author | wenzelm |
Thu, 15 Aug 2024 12:43:17 +0200 | |
changeset 80712 | 05b16602a683 |
parent 79777 | db9c6be8e236 |
permissions | -rw-r--r-- |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Tools/server_commands.scala |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
3 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
4 |
Miscellaneous Isabelle server commands. |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
6 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
8 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
9 |
|
75393 | 10 |
object Server_Commands { |
67863 | 11 |
def default_preferences: String = Options.read_prefs() |
67883 | 12 |
|
75393 | 13 |
object Help extends Server.Command("help") { |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
14 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
15 |
{ case (context, ()) => context.command_list } |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
16 |
} |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
17 |
|
75393 | 18 |
object Echo extends Server.Command("echo") { |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
19 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
20 |
{ case (_, t) => t } |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
21 |
} |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
22 |
|
75393 | 23 |
object Cancel extends Server.Command("cancel") { |
69458 | 24 |
sealed case class Args(task: UUID.T) |
67920 | 25 |
|
26 |
def unapply(json: JSON.T): Option[Args] = |
|
27 |
for { task <- JSON.uuid(json, "task") } |
|
28 |
yield Args(task) |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
29 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
30 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
31 |
{ case (context, Cancel(args)) => context.cancel_task(args.task) } |
67920 | 32 |
} |
33 |
||
75393 | 34 |
object Shutdown extends Server.Command("shutdown") { |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
35 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
36 |
{ case (context, ()) => context.server.shutdown() } |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
37 |
} |
67920 | 38 |
|
75393 | 39 |
object Session_Build extends Server.Command("session_build") { |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
40 |
sealed case class Args( |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
41 |
session: String, |
67863 | 42 |
preferences: String = default_preferences, |
67862 | 43 |
options: List[String] = Nil, |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
44 |
dirs: List[String] = Nil, |
77519 | 45 |
include_sessions: List[String] = Nil) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
46 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
47 |
def unapply(json: JSON.T): Option[Args] = |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
48 |
for { |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
49 |
session <- JSON.string(json, "session") |
67863 | 50 |
preferences <- JSON.string_default(json, "preferences", default_preferences) |
68742 | 51 |
options <- JSON.strings_default(json, "options") |
52 |
dirs <- JSON.strings_default(json, "dirs") |
|
53 |
include_sessions <- JSON.strings_default(json, "include_sessions") |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
54 |
} |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
55 |
yield { |
67862 | 56 |
Args(session, preferences = preferences, options = options, dirs = dirs, |
77519 | 57 |
include_sessions = include_sessions) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
58 |
} |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
59 |
|
75393 | 60 |
def command( |
61 |
args: Args, |
|
62 |
progress: Progress = new Progress |
|
76656 | 63 |
) : (JSON.Object.T, Build.Results, Options, Sessions.Background) = { |
77628 | 64 |
val options = |
65 |
Options.init(prefs = args.preferences, specs = args.options.map(Options.Spec.make)) |
|
71601 | 66 |
val dirs = args.dirs.map(Path.explode) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
67 |
|
76656 | 68 |
val session_background = |
69 |
Sessions.background(options, args.session, progress = progress, dirs = dirs, |
|
75920
27bf2533f4a4
clarified signature: follow Sessions.Deps.check_errors (despite Process_Result.check);
wenzelm
parents:
75674
diff
changeset
|
70 |
include_sessions = args.include_sessions).check_errors |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
71 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
72 |
val results = |
71981 | 73 |
Build.build(options, |
74 |
selection = Sessions.Selection.session(args.session), |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
75 |
progress = progress, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
76 |
build_heap = true, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
77 |
dirs = dirs, |
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77519
diff
changeset
|
78 |
infos = session_background.infos) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
79 |
|
67858 | 80 |
val sessions_order = |
76656 | 81 |
session_background.sessions_structure.imports_topological_order.zipWithIndex. |
67858 | 82 |
toMap.withDefaultValue(-1) |
83 |
||
84 |
val results_json = |
|
85 |
JSON.Object( |
|
67912 | 86 |
"ok" -> results.ok, |
67858 | 87 |
"return_code" -> results.rc, |
88 |
"sessions" -> |
|
75394 | 89 |
results.sessions.toList.sortBy(sessions_order).map { session => |
75393 | 90 |
val result = results(session) |
91 |
JSON.Object( |
|
92 |
"session" -> session, |
|
93 |
"ok" -> result.ok, |
|
94 |
"return_code" -> result.rc, |
|
95 |
"timeout" -> result.timeout, |
|
96 |
"timing" -> result.timing.json) |
|
75394 | 97 |
}) |
67858 | 98 |
|
76656 | 99 |
if (results.ok) (results_json, results, options, session_background) |
71747 | 100 |
else { |
74306 | 101 |
throw new Server.Error("Session build failed: " + Process_Result.RC.print(results.rc), |
71747 | 102 |
results_json) |
103 |
} |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
104 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
105 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
106 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
107 |
{ case (context, Session_Build(args)) => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
108 |
context.make_task(task => Session_Build.command(args, progress = task.progress)._1) } |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
109 |
} |
67869 | 110 |
|
75393 | 111 |
object Session_Start extends Server.Command("session_start") { |
67869 | 112 |
sealed case class Args( |
113 |
build: Session_Build.Args, |
|
114 |
print_mode: List[String] = Nil) |
|
115 |
||
116 |
def unapply(json: JSON.T): Option[Args] = |
|
117 |
for { |
|
118 |
build <- Session_Build.unapply(json) |
|
68742 | 119 |
print_mode <- JSON.strings_default(json, "print_mode") |
67869 | 120 |
} |
121 |
yield Args(build = build, print_mode = print_mode) |
|
122 |
||
75393 | 123 |
def command( |
124 |
args: Args, |
|
125 |
progress: Progress = new Progress, |
|
79777 | 126 |
log: Logger = new Logger |
75393 | 127 |
) : (JSON.Object.T, (UUID.T, Headless.Session)) = { |
76656 | 128 |
val (_, _, options, session_background) = |
71599 | 129 |
try { Session_Build.command(args.build, progress = progress) } |
67914
9f82f6cc3bfc
clarified error result, without JSON object from "session_build";
wenzelm
parents:
67912
diff
changeset
|
130 |
catch { case exn: Server.Error => error(exn.message) } |
67869 | 131 |
|
76656 | 132 |
val resources = Headless.Resources(options, session_background, log = log) |
69536 | 133 |
|
134 |
val session = resources.start_session(print_mode = args.print_mode, progress = progress) |
|
67869 | 135 |
|
69458 | 136 |
val id = UUID.random() |
67869 | 137 |
|
67925 | 138 |
val res = |
139 |
JSON.Object( |
|
140 |
"session_id" -> id.toString, |
|
76308 | 141 |
"tmp_dir" -> session.tmp_dir_name) |
67925 | 142 |
|
143 |
(res, id -> session) |
|
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
144 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
145 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
146 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
147 |
{ case (context, Session_Start(args)) => |
75394 | 148 |
context.make_task { task => |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
149 |
val (res, entry) = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
150 |
Session_Start.command(args, progress = task.progress, log = context.server.log) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
151 |
context.server.add_session(entry) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
152 |
res |
75394 | 153 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
154 |
} |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
155 |
} |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
156 |
|
75393 | 157 |
object Session_Stop extends Server.Command("session_stop") { |
69458 | 158 |
def unapply(json: JSON.T): Option[UUID.T] = |
67885 | 159 |
JSON.uuid(json, "session_id") |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
160 |
|
75393 | 161 |
def command(session: Headless.Session): (JSON.Object.T, Process_Result) = { |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
162 |
val result = session.stop() |
67916 | 163 |
val result_json = JSON.Object("ok" -> result.ok, "return_code" -> result.rc) |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
164 |
|
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
165 |
if (result.ok) (result_json, result) |
71747 | 166 |
else throw new Server.Error("Session shutdown failed: " + result.print_rc, result_json) |
67869 | 167 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
168 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
169 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
170 |
{ case (context, Session_Stop(id)) => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
171 |
context.make_task(_ => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
172 |
{ |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
173 |
val session = context.server.remove_session(id) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
174 |
Session_Stop.command(session)._1 |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
175 |
}) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
176 |
} |
67869 | 177 |
} |
67883 | 178 |
|
75393 | 179 |
object Use_Theories extends Server.Command("use_theories") { |
67883 | 180 |
sealed case class Args( |
69458 | 181 |
session_id: UUID.T, |
67940
b4e80f062fbf
clarified signature -- eliminated somewhat pointless positions;
wenzelm
parents:
67937
diff
changeset
|
182 |
theories: List[String], |
67897 | 183 |
master_dir: String = "", |
184 |
pretty_margin: Double = Pretty.default_margin, |
|
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
185 |
unicode_symbols: Boolean = false, |
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
186 |
export_pattern: String = "", |
69520 | 187 |
check_delay: Option[Time] = None, |
188 |
check_limit: Option[Int] = None, |
|
189 |
watchdog_timeout: Option[Time] = None, |
|
190 |
nodes_status_delay: Option[Time] = None, |
|
191 |
commit_cleanup_delay: Option[Time] = None) |
|
67883 | 192 |
|
193 |
def unapply(json: JSON.T): Option[Args] = |
|
194 |
for { |
|
67885 | 195 |
session_id <- JSON.uuid(json, "session_id") |
68742 | 196 |
theories <- JSON.strings(json, "theories") |
67883 | 197 |
master_dir <- JSON.string_default(json, "master_dir") |
67897 | 198 |
pretty_margin <- JSON.double_default(json, "pretty_margin", Pretty.default_margin) |
199 |
unicode_symbols <- JSON.bool_default(json, "unicode_symbols") |
|
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
200 |
export_pattern <- JSON.string_default(json, "export_pattern") |
69520 | 201 |
check_delay = JSON.seconds(json, "check_delay") |
202 |
check_limit = JSON.int(json, "check_limit") |
|
203 |
watchdog_timeout = JSON.seconds(json, "watchdog_timeout") |
|
204 |
nodes_status_delay = JSON.seconds(json, "nodes_status_delay") |
|
205 |
commit_cleanup_delay = JSON.seconds(json, "commit_cleanup_delay") |
|
67883 | 206 |
} |
67897 | 207 |
yield { |
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
208 |
Args(session_id, theories, master_dir = master_dir, pretty_margin = pretty_margin, |
68694
03e104be99af
added check_delay / check_limit for more robust treatment of structurally broken theory sources (or genuine non-termination);
wenzelm
parents:
68365
diff
changeset
|
209 |
unicode_symbols = unicode_symbols, export_pattern = export_pattern, |
68908 | 210 |
check_delay = check_delay, check_limit = check_limit, watchdog_timeout = watchdog_timeout, |
69520 | 211 |
nodes_status_delay = nodes_status_delay, commit_cleanup_delay = commit_cleanup_delay) |
67897 | 212 |
} |
67883 | 213 |
|
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
214 |
def command(args: Args, |
69012 | 215 |
session: Headless.Session, |
69458 | 216 |
id: UUID.T = UUID.random(), |
75393 | 217 |
progress: Progress = new Progress |
218 |
): (JSON.Object.T, Headless.Use_Theories_Result) = { |
|
67883 | 219 |
val result = |
67937 | 220 |
session.use_theories(args.theories, master_dir = args.master_dir, |
69520 | 221 |
check_delay = args.check_delay.getOrElse(session.default_check_delay), |
222 |
check_limit = args.check_limit.getOrElse(session.default_check_limit), |
|
223 |
watchdog_timeout = args.watchdog_timeout.getOrElse(session.default_watchdog_timeout), |
|
224 |
nodes_status_delay = args.nodes_status_delay.getOrElse(session.default_nodes_status_delay), |
|
225 |
commit_cleanup_delay = |
|
226 |
args.commit_cleanup_delay.getOrElse(session.default_commit_cleanup_delay), |
|
67937 | 227 |
id = id, progress = progress) |
67883 | 228 |
|
72866 | 229 |
def output_text(text: String): String = |
230 |
Symbol.output(args.unicode_symbols, text) |
|
67897 | 231 |
|
75393 | 232 |
def output_message(tree: XML.Tree, pos: Position.T): JSON.Object.T = { |
67897 | 233 |
val position = "pos" -> Position.JSON(pos) |
234 |
tree match { |
|
67901 | 235 |
case XML.Text(msg) => Server.Reply.message(output_text(msg)) + position |
67897 | 236 |
case elem: XML.Elem => |
237 |
val msg = XML.content(Pretty.formatted(List(elem), margin = args.pretty_margin)) |
|
67923
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67922
diff
changeset
|
238 |
val kind = |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67922
diff
changeset
|
239 |
Markup.messages.collectFirst({ case (a, b) if b == elem.name => |
67931
f7917c15b566
field "kind" is always present, with default "writeln";
wenzelm
parents:
67925
diff
changeset
|
240 |
if (Protocol.is_legacy(elem)) Markup.WARNING else a }) getOrElse "" |
f7917c15b566
field "kind" is always present, with default "writeln";
wenzelm
parents:
67925
diff
changeset
|
241 |
Server.Reply.message(output_text(msg), kind = kind) + position |
67897 | 242 |
} |
243 |
} |
|
244 |
||
77137
79231a210f5d
observe option "show_states" in headless server (see also 951abf9db857);
wenzelm
parents:
76852
diff
changeset
|
245 |
def show_message(tree: XML.Tree): Boolean = |
79231a210f5d
observe option "show_states" in headless server (see also 951abf9db857);
wenzelm
parents:
76852
diff
changeset
|
246 |
Protocol.is_exported(tree) || session.show_states && Protocol.is_state(tree) |
79231a210f5d
observe option "show_states" in headless server (see also 951abf9db857);
wenzelm
parents:
76852
diff
changeset
|
247 |
|
67883 | 248 |
val result_json = |
249 |
JSON.Object( |
|
250 |
"ok" -> result.ok, |
|
67900 | 251 |
"errors" -> |
252 |
(for { |
|
253 |
(name, status) <- result.nodes if !status.ok |
|
68365 | 254 |
(tree, pos) <- result.snapshot(name).messages if Protocol.is_error(tree) |
67900 | 255 |
} yield output_message(tree, pos)), |
67883 | 256 |
"nodes" -> |
68365 | 257 |
(for ((name, status) <- result.nodes) yield { |
258 |
val snapshot = result.snapshot(name) |
|
67943 | 259 |
name.json + |
260 |
("status" -> status.json) + |
|
261 |
("messages" -> |
|
67947 | 262 |
(for { |
77137
79231a210f5d
observe option "show_states" in headless server (see also 951abf9db857);
wenzelm
parents:
76852
diff
changeset
|
263 |
(tree, pos) <- snapshot.messages if show_message(tree) |
68106 | 264 |
} yield output_message(tree, pos))) + |
265 |
("exports" -> |
|
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
266 |
(if (args.export_pattern == "") Nil else { |
75658
5905c7f484b3
clarified signature: read_theory_exports is already ordered;
wenzelm
parents:
75587
diff
changeset
|
267 |
val matcher = Export.make_matcher(List(args.export_pattern)) |
75674 | 268 |
for { entry <- snapshot.exports if matcher(entry.entry_name) } |
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
269 |
yield { |
76852 | 270 |
val (base64, body) = entry.bytes.maybe_encode_base64 |
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
271 |
JSON.Object("name" -> entry.name, "base64" -> base64, "body" -> body) |
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
272 |
} |
68365 | 273 |
})) |
274 |
})) |
|
67883 | 275 |
|
276 |
(result_json, result) |
|
277 |
} |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
278 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
279 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
280 |
{ case (context, Use_Theories(args)) => |
75394 | 281 |
context.make_task { task => |
282 |
val session = context.server.the_session(args.session_id) |
|
283 |
Use_Theories.command(args, session, id = task.id, progress = task.progress)._1 |
|
284 |
} |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
285 |
} |
67883 | 286 |
} |
67941 | 287 |
|
75393 | 288 |
object Purge_Theories extends Server.Command("purge_theories") { |
67941 | 289 |
sealed case class Args( |
69458 | 290 |
session_id: UUID.T, |
67941 | 291 |
theories: List[String] = Nil, |
292 |
master_dir: String = "", |
|
293 |
all: Boolean = false) |
|
294 |
||
295 |
def unapply(json: JSON.T): Option[Args] = |
|
296 |
for { |
|
297 |
session_id <- JSON.uuid(json, "session_id") |
|
68742 | 298 |
theories <- JSON.strings_default(json, "theories") |
67941 | 299 |
master_dir <- JSON.string_default(json, "master_dir") |
300 |
all <- JSON.bool_default(json, "all") |
|
301 |
} |
|
302 |
yield { Args(session_id, theories = theories, master_dir = master_dir, all = all) } |
|
303 |
||
75393 | 304 |
def command( |
305 |
args: Args, |
|
306 |
session: Headless.Session |
|
307 |
) : (JSON.Object.T, (List[Document.Node.Name], List[Document.Node.Name])) = { |
|
67943 | 308 |
val (purged, retained) = |
67941 | 309 |
session.purge_theories( |
310 |
theories = args.theories, master_dir = args.master_dir, all = args.all) |
|
67943 | 311 |
|
312 |
val result_json = |
|
313 |
JSON.Object("purged" -> purged.map(_.json), "retained" -> retained.map(_.json)) |
|
314 |
||
315 |
(result_json, (purged, retained)) |
|
67941 | 316 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
317 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
318 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
319 |
{ case (context, Purge_Theories(args)) => |
76278 | 320 |
val session = context.server.the_session(args.session_id) |
321 |
command(args, session)._1 |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
322 |
} |
67941 | 323 |
} |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
324 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
325 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
326 |
class Server_Commands extends Server.Commands( |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
327 |
Server_Commands.Help, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
328 |
Server_Commands.Echo, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
329 |
Server_Commands.Cancel, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
330 |
Server_Commands.Shutdown, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
331 |
Server_Commands.Session_Build, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
332 |
Server_Commands.Session_Start, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
333 |
Server_Commands.Session_Stop, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
334 |
Server_Commands.Use_Theories, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
335 |
Server_Commands.Purge_Theories) |