author | wenzelm |
Fri, 11 Jan 2019 22:34:28 +0100 | |
changeset 69634 | 70f1994988d4 |
parent 69630 | aaa0b5f571e8 |
child 69635 | 95dc926fa39c |
permissions | -rw-r--r-- |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Thy/export.scala |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
3 |
|
68102 | 4 |
Manage theory exports: compressed blobs. |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
6 |
|
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
8 |
|
68116 | 9 |
|
10 |
import scala.annotation.tailrec |
|
11 |
import scala.util.matching.Regex |
|
12 |
||
13 |
||
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
14 |
object Export |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
15 |
{ |
69634 | 16 |
/* structured name */ |
17 |
||
18 |
val sep_char: Char = '/' |
|
19 |
val sep: String = sep_char.toString |
|
20 |
||
21 |
def explode_name(s: String): List[String] = space_explode(sep_char, s) |
|
22 |
def implode_name(elems: Iterable[String]): String = elems.mkString(sep) |
|
23 |
||
24 |
||
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
25 |
/* SQL data model */ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
26 |
|
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
27 |
object Data |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
28 |
{ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
29 |
val session_name = SQL.Column.string("session_name").make_primary_key |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
30 |
val theory_name = SQL.Column.string("theory_name").make_primary_key |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
31 |
val name = SQL.Column.string("name").make_primary_key |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
32 |
val compressed = SQL.Column.bool("compressed") |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
33 |
val body = SQL.Column.bytes("body") |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
34 |
|
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
35 |
val table = |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
36 |
SQL.Table("isabelle_exports", List(session_name, theory_name, name, compressed, body)) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
37 |
|
68116 | 38 |
def where_equal(session_name: String, theory_name: String = "", name: String = ""): SQL.Source = |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
39 |
"WHERE " + Data.session_name.equal(session_name) + |
68116 | 40 |
(if (theory_name == "") "" else " AND " + Data.theory_name.equal(theory_name)) + |
41 |
(if (name == "") "" else " AND " + Data.name.equal(name)) |
|
42 |
} |
|
43 |
||
44 |
def read_name(db: SQL.Database, session_name: String, theory_name: String, name: String): Boolean = |
|
45 |
{ |
|
46 |
val select = |
|
47 |
Data.table.select(List(Data.name), Data.where_equal(session_name, theory_name, name)) |
|
48 |
db.using_statement(select)(stmt => stmt.execute_query().next()) |
|
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
49 |
} |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
50 |
|
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
51 |
def read_names(db: SQL.Database, session_name: String, theory_name: String): List[String] = |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
52 |
{ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
53 |
val select = Data.table.select(List(Data.name), Data.where_equal(session_name, theory_name)) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
54 |
db.using_statement(select)(stmt => |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
55 |
stmt.execute_query().iterator(res => res.string(Data.name)).toList) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
56 |
} |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
57 |
|
68222 | 58 |
def read_theory_names(db: SQL.Database, session_name: String): List[String] = |
59 |
{ |
|
60 |
val select = |
|
61 |
Data.table.select(List(Data.theory_name), Data.where_equal(session_name), distinct = true) |
|
62 |
db.using_statement(select)(stmt => |
|
63 |
stmt.execute_query().iterator(_.string(Data.theory_name)).toList) |
|
64 |
} |
|
65 |
||
66 |
def read_theory_exports(db: SQL.Database, session_name: String): List[(String, String)] = |
|
68115 | 67 |
{ |
68116 | 68 |
val select = Data.table.select(List(Data.theory_name, Data.name), Data.where_equal(session_name)) |
69 |
db.using_statement(select)(stmt => |
|
70 |
stmt.execute_query().iterator(res => |
|
71 |
(res.string(Data.theory_name), res.string(Data.name))).toList) |
|
68115 | 72 |
} |
73 |
||
68104 | 74 |
def message(msg: String, theory_name: String, name: String): String = |
75 |
msg + " " + quote(name) + " for theory " + quote(theory_name) |
|
76 |
||
68116 | 77 |
def compound_name(a: String, b: String): String = a + ":" + b |
78 |
||
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
79 |
sealed case class Entry( |
68103
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents:
68102
diff
changeset
|
80 |
session_name: String, |
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents:
68102
diff
changeset
|
81 |
theory_name: String, |
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents:
68102
diff
changeset
|
82 |
name: String, |
68167 | 83 |
body: Future[(Boolean, Bytes)]) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
84 |
{ |
69630 | 85 |
override def toString: String = uncompressed().toString |
86 |
||
69634 | 87 |
val name_elems: List[String] = explode_name(name) |
88 |
||
89 |
def name_extends(elems: List[String]): Boolean = |
|
90 |
name_elems.startsWith(elems) && name_elems != elems |
|
91 |
||
69630 | 92 |
def text: String = uncompressed().text |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
93 |
|
69629 | 94 |
def uncompressed(cache: XZ.Cache = XZ.cache()): Bytes = |
95 |
{ |
|
96 |
val (compressed, bytes) = body.join |
|
97 |
if (compressed) bytes.uncompress(cache = cache) else bytes |
|
98 |
} |
|
99 |
||
100 |
def uncompressed_yxml(cache: XZ.Cache = XZ.cache()): XML.Body = |
|
101 |
YXML.parse_body(UTF8.decode_permissive(uncompressed(cache = cache))) |
|
102 |
||
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
103 |
def write(db: SQL.Database) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
104 |
{ |
68167 | 105 |
val (compressed, bytes) = body.join |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
106 |
db.using_statement(Data.table.insert())(stmt => |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
107 |
{ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
108 |
stmt.string(1) = session_name |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
109 |
stmt.string(2) = theory_name |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
110 |
stmt.string(3) = name |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
111 |
stmt.bool(4) = compressed |
68103
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents:
68102
diff
changeset
|
112 |
stmt.bytes(5) = bytes |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
113 |
stmt.execute() |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
114 |
}) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
115 |
} |
68116 | 116 |
} |
117 |
||
118 |
def make_regex(pattern: String): Regex = |
|
119 |
{ |
|
120 |
@tailrec def make(result: List[String], depth: Int, chs: List[Char]): Regex = |
|
121 |
chs match { |
|
122 |
case '*' :: '*' :: rest => make("[^:]*" :: result, depth, rest) |
|
123 |
case '*' :: rest => make("[^:/]*" :: result, depth, rest) |
|
124 |
case '?' :: rest => make("[^:/]" :: result, depth, rest) |
|
125 |
case '\\' :: c :: rest => make(("\\" + c) :: result, depth, rest) |
|
126 |
case '{' :: rest => make("(" :: result, depth + 1, rest) |
|
127 |
case ',' :: rest if depth > 0 => make("|" :: result, depth, rest) |
|
128 |
case '}' :: rest if depth > 0 => make(")" :: result, depth - 1, rest) |
|
129 |
case c :: rest if ".+()".contains(c) => make(("\\" + c) :: result, depth, rest) |
|
130 |
case c :: rest => make(c.toString :: result, depth, rest) |
|
131 |
case Nil => result.reverse.mkString.r |
|
132 |
} |
|
133 |
make(Nil, 0, pattern.toList) |
|
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
134 |
} |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
135 |
|
68151 | 136 |
def make_matcher(pattern: String): (String, String) => Boolean = |
137 |
{ |
|
138 |
val regex = make_regex(pattern) |
|
139 |
(theory_name: String, name: String) => |
|
140 |
regex.pattern.matcher(compound_name(theory_name, name)).matches |
|
141 |
} |
|
142 |
||
68166 | 143 |
def make_entry(session_name: String, args: Markup.Export.Args, body: Bytes, |
144 |
cache: XZ.Cache = XZ.cache()): Entry = |
|
68101 | 145 |
{ |
68167 | 146 |
Entry(session_name, args.theory_name, args.name, |
147 |
if (args.compress) Future.fork(body.maybe_compress(cache = cache)) |
|
148 |
else Future.value((false, body))) |
|
68101 | 149 |
} |
150 |
||
68202 | 151 |
def read_entry(db: SQL.Database, session_name: String, theory_name: String, name: String) |
152 |
: Option[Entry] = |
|
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
153 |
{ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
154 |
val select = |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
155 |
Data.table.select(List(Data.compressed, Data.body), |
68116 | 156 |
Data.where_equal(session_name, theory_name, name)) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
157 |
db.using_statement(select)(stmt => |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
158 |
{ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
159 |
val res = stmt.execute_query() |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
160 |
if (res.next()) { |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
161 |
val compressed = res.bool(Data.compressed) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
162 |
val body = res.bytes(Data.body) |
68202 | 163 |
Some(Entry(session_name, theory_name, name, Future.value(compressed, body))) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
164 |
} |
68202 | 165 |
else None |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
166 |
}) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
167 |
} |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
168 |
|
68831 | 169 |
def read_entry(dir: Path, session_name: String, theory_name: String, name: String): Option[Entry] = |
170 |
{ |
|
171 |
val path = dir + Path.basic(theory_name) + Path.explode(name) |
|
172 |
if (path.is_file) { |
|
173 |
val uncompressed = Bytes.read(path) |
|
174 |
Some(Entry(session_name, theory_name, name, Future.value((false, uncompressed)))) |
|
175 |
} |
|
176 |
else None |
|
177 |
} |
|
178 |
||
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
179 |
|
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
180 |
/* database consumer thread */ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
181 |
|
68289 | 182 |
def consumer(db: SQL.Database, cache: XZ.Cache = XZ.cache()): Consumer = new Consumer(db, cache) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
183 |
|
68289 | 184 |
class Consumer private[Export](db: SQL.Database, cache: XZ.Cache) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
185 |
{ |
68924 | 186 |
private val errors = Synchronized[List[String]](Nil) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
187 |
|
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
188 |
private val consumer = |
68103
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents:
68102
diff
changeset
|
189 |
Consumer_Thread.fork(name = "export")(consume = (entry: Entry) => |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
190 |
{ |
68103
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents:
68102
diff
changeset
|
191 |
entry.body.join |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
192 |
db.transaction { |
68115 | 193 |
if (read_name(db, entry.session_name, entry.theory_name, entry.name)) { |
68924 | 194 |
val msg = message("Duplicate export", entry.theory_name, entry.name) |
195 |
errors.change(msg :: _) |
|
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
196 |
} |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
197 |
else entry.write(db) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
198 |
} |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
199 |
true |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
200 |
}) |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
201 |
|
68103
c5764b8b2a87
more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents:
68102
diff
changeset
|
202 |
def apply(session_name: String, args: Markup.Export.Args, body: Bytes): Unit = |
68289 | 203 |
consumer.send(make_entry(session_name, args, body, cache = cache)) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
204 |
|
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
205 |
def shutdown(close: Boolean = false): List[String] = |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
206 |
{ |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
207 |
consumer.shutdown() |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
208 |
if (close) db.close() |
68924 | 209 |
errors.value.reverse |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
210 |
} |
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
211 |
} |
68116 | 212 |
|
213 |
||
68418 | 214 |
/* abstract provider */ |
215 |
||
216 |
object Provider |
|
217 |
{ |
|
218 |
def database(db: SQL.Database, session_name: String, theory_name: String): Provider = |
|
219 |
new Provider { |
|
220 |
def apply(export_name: String): Option[Entry] = |
|
221 |
read_entry(db, session_name, theory_name, export_name) |
|
68832 | 222 |
|
223 |
override def toString: String = db.toString |
|
68418 | 224 |
} |
225 |
||
226 |
def snapshot(snapshot: Document.Snapshot): Provider = |
|
227 |
new Provider { |
|
228 |
def apply(export_name: String): Option[Entry] = |
|
229 |
snapshot.exports_map.get(export_name) |
|
68832 | 230 |
|
231 |
override def toString: String = snapshot.toString |
|
68418 | 232 |
} |
68831 | 233 |
|
234 |
def directory(dir: Path, session_name: String, theory_name: String): Provider = |
|
235 |
new Provider { |
|
236 |
def apply(export_name: String): Option[Entry] = |
|
237 |
read_entry(dir, session_name, theory_name, export_name) |
|
68832 | 238 |
|
239 |
override def toString: String = dir.toString |
|
68831 | 240 |
} |
68418 | 241 |
} |
242 |
||
243 |
trait Provider |
|
244 |
{ |
|
245 |
def apply(export_name: String): Option[Entry] |
|
246 |
||
247 |
def uncompressed_yxml(export_name: String, cache: XZ.Cache = XZ.cache()): XML.Body = |
|
248 |
apply(export_name) match { |
|
249 |
case Some(entry) => entry.uncompressed_yxml(cache = cache) |
|
250 |
case None => Nil |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
||
68288 | 255 |
/* export to file-system */ |
256 |
||
257 |
def export_files( |
|
258 |
store: Sessions.Store, |
|
259 |
session_name: String, |
|
260 |
export_dir: Path, |
|
261 |
progress: Progress = No_Progress, |
|
262 |
export_list: Boolean = false, |
|
68291 | 263 |
export_patterns: List[String] = Nil, |
264 |
export_prefix: String = "") |
|
68288 | 265 |
{ |
266 |
using(store.open_database(session_name))(db => |
|
267 |
{ |
|
268 |
db.transaction { |
|
269 |
val export_names = read_theory_exports(db, session_name) |
|
270 |
||
271 |
// list |
|
272 |
if (export_list) { |
|
273 |
(for ((theory_name, name) <- export_names) yield compound_name(theory_name, name)). |
|
68291 | 274 |
sorted.foreach(progress.echo(_)) |
68288 | 275 |
} |
276 |
||
277 |
// export |
|
68290 | 278 |
if (export_patterns.nonEmpty) { |
279 |
val exports = |
|
280 |
(for { |
|
281 |
export_pattern <- export_patterns.iterator |
|
282 |
matcher = make_matcher(export_pattern) |
|
283 |
(theory_name, name) <- export_names if matcher(theory_name, name) |
|
284 |
} yield (theory_name, name)).toSet |
|
68288 | 285 |
for { |
68290 | 286 |
(theory_name, group) <- exports.toList.groupBy(_._1).toList.sortBy(_._1) |
287 |
name <- group.map(_._2).sorted |
|
68288 | 288 |
entry <- read_entry(db, session_name, theory_name, name) |
289 |
} { |
|
290 |
val path = export_dir + Path.basic(theory_name) + Path.explode(name) |
|
68291 | 291 |
progress.echo(export_prefix + "export " + path) |
68288 | 292 |
Isabelle_System.mkdirs(path.dir) |
68289 | 293 |
Bytes.write(path, entry.uncompressed(cache = store.xz_cache)) |
68288 | 294 |
} |
295 |
} |
|
296 |
} |
|
297 |
}) |
|
298 |
} |
|
299 |
||
300 |
||
68116 | 301 |
/* Isabelle tool wrapper */ |
302 |
||
303 |
val default_export_dir = Path.explode("export") |
|
304 |
||
305 |
val isabelle_tool = Isabelle_Tool("export", "retrieve theory exports", args => |
|
306 |
{ |
|
307 |
/* arguments */ |
|
308 |
||
309 |
var export_dir = default_export_dir |
|
310 |
var dirs: List[Path] = Nil |
|
311 |
var export_list = false |
|
312 |
var no_build = false |
|
313 |
var options = Options.init() |
|
314 |
var system_mode = false |
|
68290 | 315 |
var export_patterns: List[String] = Nil |
68116 | 316 |
|
317 |
val getopts = Getopts(""" |
|
318 |
Usage: isabelle export [OPTIONS] SESSION |
|
319 |
||
320 |
Options are: |
|
68314
2acbf8129d8b
clarified option -O: avoid conflict with build/dump option -D;
wenzelm
parents:
68305
diff
changeset
|
321 |
-O DIR output directory for exported files (default: """ + default_export_dir + """) |
68116 | 322 |
-d DIR include session directory |
323 |
-l list exports |
|
324 |
-n no build of session |
|
325 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
326 |
-s system build mode for session image |
|
327 |
-x PATTERN extract files matching pattern (e.g. "*:**" for all) |
|
328 |
||
329 |
List or export theory exports for SESSION: named blobs produced by |
|
68290 | 330 |
isabelle build. Option -l or -x is required; option -x may be repeated. |
68116 | 331 |
|
332 |
The PATTERN language resembles glob patterns in the shell, with ? and * |
|
333 |
(both excluding ":" and "/"), ** (excluding ":"), and [abc] or [^abc], |
|
334 |
and variants {pattern1,pattern2,pattern3}. |
|
335 |
""", |
|
68314
2acbf8129d8b
clarified option -O: avoid conflict with build/dump option -D;
wenzelm
parents:
68305
diff
changeset
|
336 |
"O:" -> (arg => export_dir = Path.explode(arg)), |
68116 | 337 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
338 |
"l" -> (_ => export_list = true), |
|
339 |
"n" -> (_ => no_build = true), |
|
340 |
"o:" -> (arg => options = options + arg), |
|
341 |
"s" -> (_ => system_mode = true), |
|
68290 | 342 |
"x:" -> (arg => export_patterns ::= arg)) |
68116 | 343 |
|
344 |
val more_args = getopts(args) |
|
345 |
val session_name = |
|
346 |
more_args match { |
|
68290 | 347 |
case List(session_name) if export_list || export_patterns.nonEmpty => session_name |
68116 | 348 |
case _ => getopts.usage() |
349 |
} |
|
350 |
||
68305 | 351 |
val progress = new Console_Progress() |
352 |
||
68116 | 353 |
|
354 |
/* build */ |
|
355 |
||
68305 | 356 |
if (!no_build) { |
357 |
val rc = |
|
68331 | 358 |
progress.interrupt_handler { |
359 |
Build.build_logic(options, session_name, progress = progress, |
|
360 |
dirs = dirs, system_mode = system_mode) |
|
361 |
} |
|
68305 | 362 |
if (rc != 0) sys.exit(rc) |
68116 | 363 |
} |
364 |
||
365 |
||
68288 | 366 |
/* export files */ |
68116 | 367 |
|
68209 | 368 |
val store = Sessions.store(options, system_mode) |
68288 | 369 |
export_files(store, session_name, export_dir, progress = progress, |
68290 | 370 |
export_list = export_list, export_patterns = export_patterns) |
68116 | 371 |
}) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff
changeset
|
372 |
} |