author | wenzelm |
Mon, 16 Nov 2020 23:27:43 +0100 | |
changeset 72627 | 8d83acc5062e |
parent 72163 | f5722290a4d0 |
child 72847 | 9dda93a753b1 |
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 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
10 |
object Server_Commands |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
11 |
{ |
67863 | 12 |
def default_preferences: String = Options.read_prefs() |
67883 | 13 |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
14 |
object Help extends Server.Command("help") |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
15 |
{ |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
16 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
17 |
{ case (context, ()) => context.command_list } |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
18 |
} |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
19 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
20 |
object Echo extends Server.Command("echo") |
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 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
23 |
{ case (_, t) => t } |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
24 |
} |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
25 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
26 |
object Cancel extends Server.Command("cancel") |
67920 | 27 |
{ |
69458 | 28 |
sealed case class Args(task: UUID.T) |
67920 | 29 |
|
30 |
def unapply(json: JSON.T): Option[Args] = |
|
31 |
for { task <- JSON.uuid(json, "task") } |
|
32 |
yield Args(task) |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
33 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
34 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
35 |
{ case (context, Cancel(args)) => context.cancel_task(args.task) } |
67920 | 36 |
} |
37 |
||
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
38 |
object Shutdown extends Server.Command("shutdown") |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
39 |
{ |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
40 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
41 |
{ case (context, ()) => context.server.shutdown() } |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
42 |
} |
67920 | 43 |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
44 |
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
|
45 |
{ |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
46 |
sealed case class Args( |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
47 |
session: String, |
67863 | 48 |
preferences: String = default_preferences, |
67862 | 49 |
options: List[String] = Nil, |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
50 |
dirs: List[String] = Nil, |
67922
9e668ae81f97
clarified signature: prefer selective include_sessions;
wenzelm
parents:
67921
diff
changeset
|
51 |
include_sessions: List[String] = Nil, |
67853 | 52 |
verbose: Boolean = false) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
53 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
54 |
def unapply(json: JSON.T): Option[Args] = |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
55 |
for { |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
56 |
session <- JSON.string(json, "session") |
67863 | 57 |
preferences <- JSON.string_default(json, "preferences", default_preferences) |
68742 | 58 |
options <- JSON.strings_default(json, "options") |
59 |
dirs <- JSON.strings_default(json, "dirs") |
|
60 |
include_sessions <- JSON.strings_default(json, "include_sessions") |
|
67853 | 61 |
verbose <- JSON.bool_default(json, "verbose") |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
62 |
} |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
63 |
yield { |
67862 | 64 |
Args(session, preferences = preferences, options = options, dirs = dirs, |
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69536
diff
changeset
|
65 |
include_sessions = include_sessions, verbose = verbose) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
66 |
} |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
67 |
|
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71601
diff
changeset
|
68 |
def command(args: Args, progress: Progress = new Progress) |
71599 | 69 |
: (JSON.Object.T, Build.Results, Options, Sessions.Base_Info) = |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
70 |
{ |
67862 | 71 |
val options = Options.init(prefs = args.preferences, opts = args.options) |
71601 | 72 |
val dirs = args.dirs.map(Path.explode) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
73 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
74 |
val base_info = |
67919
dd90faed43b2
clarified signature: do not expose somewhat accidental internal options;
wenzelm
parents:
67916
diff
changeset
|
75 |
Sessions.base_info(options, args.session, progress = progress, dirs = dirs, |
72627 | 76 |
include_sessions = args.include_sessions).check |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
77 |
|
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
78 |
val results = |
71981 | 79 |
Build.build(options, |
80 |
selection = Sessions.Selection.session(args.session), |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
81 |
progress = progress, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
82 |
build_heap = true, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
83 |
dirs = dirs, |
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
84 |
infos = base_info.infos, |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71747
diff
changeset
|
85 |
verbose = args.verbose) |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
86 |
|
67858 | 87 |
val sessions_order = |
88 |
base_info.sessions_structure.imports_topological_order.zipWithIndex. |
|
89 |
toMap.withDefaultValue(-1) |
|
90 |
||
91 |
val results_json = |
|
92 |
JSON.Object( |
|
67912 | 93 |
"ok" -> results.ok, |
67858 | 94 |
"return_code" -> results.rc, |
95 |
"sessions" -> |
|
96 |
results.sessions.toList.sortBy(sessions_order).map(session => |
|
67912 | 97 |
{ |
98 |
val result = results(session) |
|
99 |
JSON.Object( |
|
100 |
"session" -> session, |
|
101 |
"ok" -> result.ok, |
|
102 |
"return_code" -> result.rc, |
|
103 |
"timeout" -> result.timeout, |
|
104 |
"timing" -> result.timing.json) |
|
105 |
})) |
|
67858 | 106 |
|
71599 | 107 |
if (results.ok) (results_json, results, options, base_info) |
71747 | 108 |
else { |
109 |
throw new Server.Error("Session build failed: " + Process_Result.print_rc(results.rc), |
|
110 |
results_json) |
|
111 |
} |
|
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
112 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
113 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
114 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
115 |
{ case (context, Session_Build(args)) => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
116 |
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
|
117 |
} |
67869 | 118 |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
119 |
object Session_Start extends Server.Command("session_start") |
67869 | 120 |
{ |
121 |
sealed case class Args( |
|
122 |
build: Session_Build.Args, |
|
123 |
print_mode: List[String] = Nil) |
|
124 |
||
125 |
def unapply(json: JSON.T): Option[Args] = |
|
126 |
for { |
|
127 |
build <- Session_Build.unapply(json) |
|
68742 | 128 |
print_mode <- JSON.strings_default(json, "print_mode") |
67869 | 129 |
} |
130 |
yield Args(build = build, print_mode = print_mode) |
|
131 |
||
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71601
diff
changeset
|
132 |
def command(args: Args, progress: Progress = new Progress, log: Logger = No_Logger) |
69458 | 133 |
: (JSON.Object.T, (UUID.T, Headless.Session)) = |
67869 | 134 |
{ |
71599 | 135 |
val (_, _, options, base_info) = |
136 |
try { Session_Build.command(args.build, progress = progress) } |
|
67914
9f82f6cc3bfc
clarified error result, without JSON object from "session_build";
wenzelm
parents:
67912
diff
changeset
|
137 |
catch { case exn: Server.Error => error(exn.message) } |
67869 | 138 |
|
71599 | 139 |
val resources = Headless.Resources(options, base_info, log = log) |
69536 | 140 |
|
141 |
val session = resources.start_session(print_mode = args.print_mode, progress = progress) |
|
67869 | 142 |
|
69458 | 143 |
val id = UUID.random() |
67869 | 144 |
|
67925 | 145 |
val res = |
146 |
JSON.Object( |
|
147 |
"session_id" -> id.toString, |
|
148 |
"tmp_dir" -> File.path(session.tmp_dir).implode) |
|
149 |
||
150 |
(res, id -> session) |
|
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
151 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
152 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
153 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
154 |
{ case (context, Session_Start(args)) => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
155 |
context.make_task(task => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
156 |
{ |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
157 |
val (res, entry) = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
158 |
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
|
159 |
context.server.add_session(entry) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
160 |
res |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
161 |
}) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
162 |
} |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
163 |
} |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
164 |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
165 |
object Session_Stop extends Server.Command("session_stop") |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
166 |
{ |
69458 | 167 |
def unapply(json: JSON.T): Option[UUID.T] = |
67885 | 168 |
JSON.uuid(json, "session_id") |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
169 |
|
69012 | 170 |
def command(session: Headless.Session): (JSON.Object.T, Process_Result) = |
67871
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
171 |
{ |
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
172 |
val result = session.stop() |
67916 | 173 |
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
|
174 |
|
195ff117894c
store session: per Server/Context, not Connection;
wenzelm
parents:
67869
diff
changeset
|
175 |
if (result.ok) (result_json, result) |
71747 | 176 |
else throw new Server.Error("Session shutdown failed: " + result.print_rc, result_json) |
67869 | 177 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
178 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
179 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
180 |
{ case (context, Session_Stop(id)) => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
181 |
context.make_task(_ => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
182 |
{ |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
183 |
val session = context.server.remove_session(id) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
184 |
Session_Stop.command(session)._1 |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
185 |
}) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
186 |
} |
67869 | 187 |
} |
67883 | 188 |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
189 |
object Use_Theories extends Server.Command("use_theories") |
67883 | 190 |
{ |
191 |
sealed case class Args( |
|
69458 | 192 |
session_id: UUID.T, |
67940
b4e80f062fbf
clarified signature -- eliminated somewhat pointless positions;
wenzelm
parents:
67937
diff
changeset
|
193 |
theories: List[String], |
67897 | 194 |
master_dir: String = "", |
195 |
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
|
196 |
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
|
197 |
export_pattern: String = "", |
69520 | 198 |
check_delay: Option[Time] = None, |
199 |
check_limit: Option[Int] = None, |
|
200 |
watchdog_timeout: Option[Time] = None, |
|
201 |
nodes_status_delay: Option[Time] = None, |
|
202 |
commit_cleanup_delay: Option[Time] = None) |
|
67883 | 203 |
|
204 |
def unapply(json: JSON.T): Option[Args] = |
|
205 |
for { |
|
67885 | 206 |
session_id <- JSON.uuid(json, "session_id") |
68742 | 207 |
theories <- JSON.strings(json, "theories") |
67883 | 208 |
master_dir <- JSON.string_default(json, "master_dir") |
67897 | 209 |
pretty_margin <- JSON.double_default(json, "pretty_margin", Pretty.default_margin) |
210 |
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
|
211 |
export_pattern <- JSON.string_default(json, "export_pattern") |
69520 | 212 |
check_delay = JSON.seconds(json, "check_delay") |
213 |
check_limit = JSON.int(json, "check_limit") |
|
214 |
watchdog_timeout = JSON.seconds(json, "watchdog_timeout") |
|
215 |
nodes_status_delay = JSON.seconds(json, "nodes_status_delay") |
|
216 |
commit_cleanup_delay = JSON.seconds(json, "commit_cleanup_delay") |
|
67883 | 217 |
} |
67897 | 218 |
yield { |
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
219 |
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
|
220 |
unicode_symbols = unicode_symbols, export_pattern = export_pattern, |
68908 | 221 |
check_delay = check_delay, check_limit = check_limit, watchdog_timeout = watchdog_timeout, |
69520 | 222 |
nodes_status_delay = nodes_status_delay, commit_cleanup_delay = commit_cleanup_delay) |
67897 | 223 |
} |
67883 | 224 |
|
67884
43af581d7d8e
unload_theories after consolidation -- reset node_required;
wenzelm
parents:
67883
diff
changeset
|
225 |
def command(args: Args, |
69012 | 226 |
session: Headless.Session, |
69458 | 227 |
id: UUID.T = UUID.random(), |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71601
diff
changeset
|
228 |
progress: Progress = new Progress): (JSON.Object.T, Headless.Use_Theories_Result) = |
67883 | 229 |
{ |
230 |
val result = |
|
67937 | 231 |
session.use_theories(args.theories, master_dir = args.master_dir, |
69520 | 232 |
check_delay = args.check_delay.getOrElse(session.default_check_delay), |
233 |
check_limit = args.check_limit.getOrElse(session.default_check_limit), |
|
234 |
watchdog_timeout = args.watchdog_timeout.getOrElse(session.default_watchdog_timeout), |
|
235 |
nodes_status_delay = args.nodes_status_delay.getOrElse(session.default_nodes_status_delay), |
|
236 |
commit_cleanup_delay = |
|
237 |
args.commit_cleanup_delay.getOrElse(session.default_commit_cleanup_delay), |
|
67937 | 238 |
id = id, progress = progress) |
67883 | 239 |
|
67901 | 240 |
def output_text(s: String): String = |
241 |
if (args.unicode_symbols) Symbol.decode(s) else Symbol.encode(s) |
|
67897 | 242 |
|
243 |
def output_message(tree: XML.Tree, pos: Position.T): JSON.Object.T = |
|
244 |
{ |
|
245 |
val position = "pos" -> Position.JSON(pos) |
|
246 |
tree match { |
|
67901 | 247 |
case XML.Text(msg) => Server.Reply.message(output_text(msg)) + position |
67897 | 248 |
case elem: XML.Elem => |
249 |
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
|
250 |
val kind = |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67922
diff
changeset
|
251 |
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
|
252 |
if (Protocol.is_legacy(elem)) Markup.WARNING else a }) getOrElse "" |
f7917c15b566
field "kind" is always present, with default "writeln";
wenzelm
parents:
67925
diff
changeset
|
253 |
Server.Reply.message(output_text(msg), kind = kind) + position |
67897 | 254 |
} |
255 |
} |
|
256 |
||
67883 | 257 |
val result_json = |
258 |
JSON.Object( |
|
259 |
"ok" -> result.ok, |
|
67900 | 260 |
"errors" -> |
261 |
(for { |
|
262 |
(name, status) <- result.nodes if !status.ok |
|
68365 | 263 |
(tree, pos) <- result.snapshot(name).messages if Protocol.is_error(tree) |
67900 | 264 |
} yield output_message(tree, pos)), |
67883 | 265 |
"nodes" -> |
68365 | 266 |
(for ((name, status) <- result.nodes) yield { |
267 |
val snapshot = result.snapshot(name) |
|
67943 | 268 |
name.json + |
269 |
("status" -> status.json) + |
|
270 |
("messages" -> |
|
67947 | 271 |
(for { |
68365 | 272 |
(tree, pos) <- snapshot.messages if Protocol.is_exported(tree) |
68106 | 273 |
} yield output_message(tree, pos))) + |
274 |
("exports" -> |
|
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
275 |
(if (args.export_pattern == "") Nil else { |
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
276 |
val matcher = Export.make_matcher(args.export_pattern) |
68365 | 277 |
for { entry <- snapshot.exports if matcher(entry.theory_name, entry.name) } |
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
278 |
yield { |
68167 | 279 |
val (base64, body) = entry.uncompressed().maybe_base64 |
68152
619de043389f
guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents:
68106
diff
changeset
|
280 |
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
|
281 |
} |
68365 | 282 |
})) |
283 |
})) |
|
67883 | 284 |
|
285 |
(result_json, result) |
|
286 |
} |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
287 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
288 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
289 |
{ case (context, Use_Theories(args)) => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
290 |
context.make_task(task => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
291 |
{ |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
292 |
val session = context.server.the_session(args.session_id) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
293 |
Use_Theories.command(args, session, id = task.id, progress = task.progress)._1 |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
294 |
}) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
295 |
} |
67883 | 296 |
} |
67941 | 297 |
|
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
298 |
object Purge_Theories extends Server.Command("purge_theories") |
67941 | 299 |
{ |
300 |
sealed case class Args( |
|
69458 | 301 |
session_id: UUID.T, |
67941 | 302 |
theories: List[String] = Nil, |
303 |
master_dir: String = "", |
|
304 |
all: Boolean = false) |
|
305 |
||
306 |
def unapply(json: JSON.T): Option[Args] = |
|
307 |
for { |
|
308 |
session_id <- JSON.uuid(json, "session_id") |
|
68742 | 309 |
theories <- JSON.strings_default(json, "theories") |
67941 | 310 |
master_dir <- JSON.string_default(json, "master_dir") |
311 |
all <- JSON.bool_default(json, "all") |
|
312 |
} |
|
313 |
yield { Args(session_id, theories = theories, master_dir = master_dir, all = all) } |
|
314 |
||
69012 | 315 |
def command(args: Args, session: Headless.Session) |
67943 | 316 |
: (JSON.Object.T, (List[Document.Node.Name], List[Document.Node.Name])) = |
67941 | 317 |
{ |
67943 | 318 |
val (purged, retained) = |
67941 | 319 |
session.purge_theories( |
320 |
theories = args.theories, master_dir = args.master_dir, all = args.all) |
|
67943 | 321 |
|
322 |
val result_json = |
|
323 |
JSON.Object("purged" -> purged.map(_.json), "retained" -> retained.map(_.json)) |
|
324 |
||
325 |
(result_json, (purged, retained)) |
|
67941 | 326 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
327 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
328 |
override val command_body: Server.Command_Body = |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
329 |
{ case (context, Purge_Theories(args)) => |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
330 |
val session = context.server.the_session(args.session_id) |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
331 |
command(args, session)._1 |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
332 |
} |
67941 | 333 |
} |
67848
dd83610333de
added server command "session_build": similar to JEdit_Resources.session_build;
wenzelm
parents:
diff
changeset
|
334 |
} |
72163
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
335 |
|
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
336 |
class Server_Commands extends Server.Commands( |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
337 |
Server_Commands.Help, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
338 |
Server_Commands.Echo, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
339 |
Server_Commands.Cancel, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
340 |
Server_Commands.Shutdown, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
341 |
Server_Commands.Session_Build, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
342 |
Server_Commands.Session_Start, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
343 |
Server_Commands.Session_Stop, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
344 |
Server_Commands.Use_Theories, |
f5722290a4d0
allow user-defined server commands via isabelle_scala_service;
wenzelm
parents:
71981
diff
changeset
|
345 |
Server_Commands.Purge_Theories) |