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