| author | wenzelm | 
| Thu, 24 Oct 2024 22:05:57 +0200 | |
| changeset 81253 | bbed9f218158 | 
| parent 80480 | 972f7a4cdc0e | 
| child 82948 | e2e43992f339 | 
| permissions | -rw-r--r-- | 
| 79502 | 1 | /* Title: Pure/Build/export.scala | 
| 68092 
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 | |
| 79502 | 4 | Manage per-session 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 | |
| 78541 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 12 | import scala.collection.mutable | 
| 68116 | 13 | |
| 14 | ||
| 75393 | 15 | object Export {
 | 
| 72691 | 16 | /* artefact names */ | 
| 17 | ||
| 78531 | 18 | val DOCUMENT_ID: String = "PIDE/document_id" | 
| 19 | val FILES: String = "PIDE/files" | |
| 20 | val MARKUP: String = "PIDE/markup" | |
| 21 | val MESSAGES: String = "PIDE/messages" | |
| 22 | val DOCUMENT_PREFIX: String = "document/" | |
| 23 | val DOCUMENT_LATEX: String = DOCUMENT_PREFIX + "latex" | |
| 72691 | 24 | val THEORY_PREFIX: String = "theory/" | 
| 25 | val PROOFS_PREFIX: String = "proofs/" | |
| 69634 | 26 | |
| 69756 | 27 |   def explode_name(s: String): List[String] = space_explode('/', s)
 | 
| 28 |   def implode_name(elems: Iterable[String]): String = elems.mkString("/")
 | |
| 69634 | 29 | |
| 30 | ||
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 31 | /* SQL data model */ | 
| 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 32 | |
| 78396 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 33 |   object private_data extends SQL.Data() {
 | 
| 79844 
ac40138234ce
tuned signature: more uniform SQL.Data instances;
 wenzelm parents: 
79675diff
changeset | 34 | override lazy val tables: SQL.Tables = SQL.Tables(Base.table) | 
| 78210 | 35 | |
| 78208 | 36 |     object Base {
 | 
| 37 |       val session_name = SQL.Column.string("session_name").make_primary_key
 | |
| 38 |       val theory_name = SQL.Column.string("theory_name").make_primary_key
 | |
| 39 |       val name = SQL.Column.string("name").make_primary_key
 | |
| 40 |       val executable = SQL.Column.bool("executable")
 | |
| 41 |       val compressed = SQL.Column.bool("compressed")
 | |
| 42 |       val body = SQL.Column.bytes("body")
 | |
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 43 | |
| 78208 | 44 | val table = | 
| 45 |         SQL.Table("isabelle_exports",
 | |
| 46 | List(session_name, theory_name, name, executable, compressed, body)) | |
| 47 | } | |
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 48 | |
| 68116 | 49 | def where_equal(session_name: String, theory_name: String = "", name: String = ""): SQL.Source = | 
| 78153 | 50 | SQL.where_and( | 
| 78208 | 51 | Base.session_name.equal(session_name), | 
| 52 | if_proper(theory_name, Base.theory_name.equal(theory_name)), | |
| 53 | if_proper(name, Base.name.equal(name))) | |
| 78209 | 54 | |
| 78260 
0a7f7abbe4f0
more robust transaction_lock: avoid overlapping data spaces;
 wenzelm parents: 
78211diff
changeset | 55 | def clean_session(db: SQL.Database, session_name: String): Unit = | 
| 
0a7f7abbe4f0
more robust transaction_lock: avoid overlapping data spaces;
 wenzelm parents: 
78211diff
changeset | 56 | db.execute_statement(Base.table.delete(sql = where_equal(session_name))) | 
| 
0a7f7abbe4f0
more robust transaction_lock: avoid overlapping data spaces;
 wenzelm parents: 
78211diff
changeset | 57 | |
| 78541 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 58 |     def known_entries(db: SQL.Database, entry_names: Iterable[Entry_Name]): Set[Entry_Name] = {
 | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 59 | val it = entry_names.iterator | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 60 | if (it.isEmpty) Set.empty[Entry_Name] | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 61 |       else {
 | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 62 | val sql_preds = | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 63 | List.from( | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 64 |             for (entry_name <- it) yield {
 | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 65 | SQL.and( | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 66 | Base.session_name.equal(entry_name.session), | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 67 | Base.theory_name.equal(entry_name.theory), | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 68 | Base.name.equal(entry_name.name) | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 69 | ) | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 70 | }) | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 71 | db.execute_query_statement( | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 72 | Base.table.select(List(Base.session_name, Base.theory_name, Base.name), | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 73 | sql = SQL.where(SQL.OR(sql_preds))), | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 74 | Set.from[Entry_Name], | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 75 |           { res =>
 | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 76 | val session_name = res.string(Base.session_name) | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 77 | val theory_name = res.string(Base.theory_name) | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 78 | val name = res.string(Base.name) | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 79 | Entry_Name(session_name, theory_name, name) | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 80 | }) | 
| 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 81 | } | 
| 78209 | 82 | } | 
| 83 | ||
| 84 | def read_entry(db: SQL.Database, entry_name: Entry_Name, cache: XML.Cache): Option[Entry] = | |
| 85 | db.execute_query_statementO[Entry]( | |
| 78210 | 86 | Base.table.select(List(Base.executable, Base.compressed, Base.body), | 
| 78396 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 87 | sql = private_data.where_equal(entry_name.session, entry_name.theory, entry_name.name)), | 
| 78209 | 88 |         { res =>
 | 
| 78210 | 89 | val executable = res.bool(Base.executable) | 
| 90 | val compressed = res.bool(Base.compressed) | |
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 91 | val body = res.bytes(Base.body) | 
| 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 92 | Entry(entry_name, executable, compressed, body, cache) | 
| 78209 | 93 | } | 
| 94 | ) | |
| 95 | ||
| 78554 
54991440905e
clarified signature: proper treatment of implicit state (amending d0c9d277620e);
 wenzelm parents: 
78551diff
changeset | 96 | def write_entries(db: SQL.Database, entries: List[Entry]): Unit = | 
| 78551 
d0c9d277620e
clarified signature: more robust treatment of implicit state;
 wenzelm parents: 
78543diff
changeset | 97 | db.execute_batch_statement(Base.table.insert(), batch = | 
| 78554 
54991440905e
clarified signature: proper treatment of implicit state (amending d0c9d277620e);
 wenzelm parents: 
78551diff
changeset | 98 |         for (entry <- entries) yield { (stmt: SQL.Statement) =>
 | 
| 
54991440905e
clarified signature: proper treatment of implicit state (amending d0c9d277620e);
 wenzelm parents: 
78551diff
changeset | 99 | stmt.string(1) = entry.session_name | 
| 
54991440905e
clarified signature: proper treatment of implicit state (amending d0c9d277620e);
 wenzelm parents: 
78551diff
changeset | 100 | stmt.string(2) = entry.theory_name | 
| 
54991440905e
clarified signature: proper treatment of implicit state (amending d0c9d277620e);
 wenzelm parents: 
78551diff
changeset | 101 | stmt.string(3) = entry.name | 
| 
54991440905e
clarified signature: proper treatment of implicit state (amending d0c9d277620e);
 wenzelm parents: 
78551diff
changeset | 102 | stmt.bool(4) = entry.executable | 
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 103 | stmt.bool(5) = entry.compressed | 
| 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 104 | stmt.bytes(6) = entry.body | 
| 78541 
d95497dcd9bc
more scalable write_entries and Export.consumer via db.execute_batch_statement;
 wenzelm parents: 
78531diff
changeset | 105 | }) | 
| 78210 | 106 | |
| 107 | def read_theory_names(db: SQL.Database, session_name: String): List[String] = | |
| 108 | db.execute_query_statement( | |
| 109 | Base.table.select(List(Base.theory_name), distinct = true, | |
| 78396 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 110 | sql = private_data.where_equal(session_name) + SQL.order_by(List(Base.theory_name))), | 
| 78210 | 111 | List.from[String], res => res.string(Base.theory_name)) | 
| 112 | ||
| 113 | def read_entry_names(db: SQL.Database, session_name: String): List[Entry_Name] = | |
| 114 | db.execute_query_statement( | |
| 115 | Base.table.select(List(Base.theory_name, Base.name), | |
| 78396 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 116 | sql = private_data.where_equal(session_name)) + SQL.order_by(List(Base.theory_name, Base.name)), | 
| 78210 | 117 | List.from[Entry_Name], | 
| 118 |         { res =>
 | |
| 119 | Entry_Name( | |
| 120 | session = session_name, | |
| 121 | theory = res.string(Base.theory_name), | |
| 122 | name = res.string(Base.name)) | |
| 123 | }) | |
| 68116 | 124 | } | 
| 125 | ||
| 75674 | 126 | def compound_name(a: String, b: String): String = | 
| 127 | if (a.isEmpty) b else a + ":" + b | |
| 128 | ||
| 75672 | 129 |   sealed case class Entry_Name(session: String = "", theory: String = "", name: String = "") {
 | 
| 75674 | 130 | val compound_name: String = Export.compound_name(theory, name) | 
| 131 | ||
| 75680 | 132 |     def make_path(prune: Int = 0): Path = {
 | 
| 75675 | 133 |       val elems = theory :: space_explode('/', name)
 | 
| 134 |       if (elems.length < prune + 1) {
 | |
| 135 |         error("Cannot prune path by " + prune + " element(s): " + Path.make(elems))
 | |
| 136 | } | |
| 75680 | 137 | else Path.make(elems.drop(prune)) | 
| 75675 | 138 | } | 
| 68222 | 139 | } | 
| 140 | ||
| 68104 | 141 | def message(msg: String, theory_name: String, name: String): String = | 
| 142 | msg + " " + quote(name) + " for theory " + quote(theory_name) | |
| 143 | ||
| 76851 | 144 |   object Entry {
 | 
| 145 | def apply( | |
| 146 | entry_name: Entry_Name, | |
| 147 | executable: Boolean, | |
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 148 | compressed: Boolean, | 
| 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 149 | body: Bytes, | 
| 76851 | 150 | cache: XML.Cache | 
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 151 | ): Entry = new Entry(entry_name, executable, compressed, body, cache) | 
| 76851 | 152 | |
| 153 | def empty(theory_name: String, name: String): Entry = | |
| 154 | Entry(Entry_Name(theory = theory_name, name = name), | |
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 155 | false, false, Bytes.empty, XML.Cache.none) | 
| 72634 
5cea0993ee4f
clarified access to single database server vs. collection of database files;
 wenzelm parents: 
72375diff
changeset | 156 | |
| 76851 | 157 | def make( | 
| 158 | session_name: String, | |
| 159 | args: Protocol.Export.Args, | |
| 160 | bytes: Bytes, | |
| 161 | cache: XML.Cache | |
| 162 |     ): Entry = {
 | |
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 163 | val (compressed, body) = | 
| 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 164 | if (args.compress) bytes.maybe_compress(cache = cache.compress) | 
| 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 165 | else (false, bytes) | 
| 76851 | 166 | val entry_name = | 
| 167 | Entry_Name(session = session_name, theory = args.theory_name, name = args.name) | |
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 168 | Entry(entry_name, args.executable, compressed, body, cache) | 
| 76851 | 169 | } | 
| 170 | } | |
| 171 | ||
| 172 | final class Entry private( | |
| 173 | val entry_name: Entry_Name, | |
| 174 | val executable: Boolean, | |
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 175 | val compressed: Boolean, | 
| 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 176 | val body: Bytes, | 
| 78209 | 177 | val cache: XML.Cache | 
| 75393 | 178 |   ) {
 | 
| 75671 | 179 | def session_name: String = entry_name.session | 
| 180 | def theory_name: String = entry_name.theory | |
| 181 | def name: String = entry_name.name | |
| 69635 | 182 | override def toString: String = name | 
| 69630 | 183 | |
| 75674 | 184 | def compound_name: String = entry_name.compound_name | 
| 71141 | 185 | |
| 72691 | 186 | def name_has_prefix(s: String): Boolean = name.startsWith(s) | 
| 69634 | 187 | val name_elems: List[String] = explode_name(name) | 
| 188 | ||
| 189 | def name_extends(elems: List[String]): Boolean = | |
| 190 | name_elems.startsWith(elems) && name_elems != elems | |
| 191 | ||
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 192 | def bytes: Bytes = | 
| 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 193 | if (compressed) body.uncompress(cache = cache.compress) else body | 
| 69629 | 194 | |
| 76852 | 195 | def text: String = bytes.text | 
| 196 | ||
| 80447 
325907d85977
minor performance tuning: allow recode operation during YXML parsing;
 wenzelm parents: 
80350diff
changeset | 197 | def yxml(recode: String => String = identity): XML.Body = | 
| 80480 
972f7a4cdc0e
clarified YXML.Source: more direct support for String and Bytes, instead of CharSequence;
 wenzelm parents: 
80447diff
changeset | 198 | YXML.parse_body(bytes, recode = recode, cache = cache) | 
| 68116 | 199 | } | 
| 200 | ||
| 75393 | 201 |   def make_regex(pattern: String): Regex = {
 | 
| 68116 | 202 | @tailrec def make(result: List[String], depth: Int, chs: List[Char]): Regex = | 
| 203 |       chs match {
 | |
| 204 |         case '*' :: '*' :: rest => make("[^:]*" :: result, depth, rest)
 | |
| 205 |         case '*' :: rest => make("[^:/]*" :: result, depth, rest)
 | |
| 206 |         case '?' :: rest => make("[^:/]" :: result, depth, rest)
 | |
| 207 |         case '\\' :: c :: rest => make(("\\" + c) :: result, depth, rest)
 | |
| 208 |         case '{' :: rest => make("(" :: result, depth + 1, rest)
 | |
| 209 |         case ',' :: rest if depth > 0 => make("|" :: result, depth, rest)
 | |
| 210 |         case '}' :: rest if depth > 0 => make(")" :: result, depth - 1, rest)
 | |
| 211 |         case c :: rest if ".+()".contains(c) => make(("\\" + c) :: result, depth, rest)
 | |
| 212 | case c :: rest => make(c.toString :: result, depth, rest) | |
| 213 | case Nil => result.reverse.mkString.r | |
| 214 | } | |
| 215 | make(Nil, 0, pattern.toList) | |
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 216 | } | 
| 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 217 | |
| 75674 | 218 |   def make_matcher(pats: List[String]): Entry_Name => Boolean = {
 | 
| 75658 
5905c7f484b3
clarified signature: read_theory_exports is already ordered;
 wenzelm parents: 
75394diff
changeset | 219 | val regs = pats.map(make_regex) | 
| 76098 | 220 | (entry_name: Entry_Name) => regs.exists(_.matches(entry_name.compound_name)) | 
| 68151 | 221 | } | 
| 222 | ||
| 78260 
0a7f7abbe4f0
more robust transaction_lock: avoid overlapping data spaces;
 wenzelm parents: 
78211diff
changeset | 223 | def clean_session(db: SQL.Database, session_name: String): Unit = | 
| 78396 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 224 |     private_data.transaction_lock(db, create = true, label = "Export.clean_session") {
 | 
| 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 225 | private_data.clean_session(db, session_name) | 
| 78356 | 226 | } | 
| 78260 
0a7f7abbe4f0
more robust transaction_lock: avoid overlapping data spaces;
 wenzelm parents: 
78211diff
changeset | 227 | |
| 78211 | 228 | def read_theory_names(db: SQL.Database, session_name: String): List[String] = | 
| 78396 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 229 |     private_data.transaction_lock(db, label = "Export.read_theory_names") {
 | 
| 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 230 | private_data.read_theory_names(db, session_name) | 
| 78356 | 231 | } | 
| 78211 | 232 | |
| 233 | def read_entry_names(db: SQL.Database, session_name: String): List[Entry_Name] = | |
| 78396 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 234 |     private_data.transaction_lock(db, label = "Export.read_entry_names") {
 | 
| 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 235 | private_data.read_entry_names(db, session_name) | 
| 78356 | 236 | } | 
| 78211 | 237 | |
| 238 | def read_entry(db: SQL.Database, entry_name: Entry_Name, cache: XML.Cache): Option[Entry] = | |
| 78396 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 239 |     private_data.transaction_lock(db, label = "Export.read_entry") {
 | 
| 
7853d9072d1b
renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
 wenzelm parents: 
78379diff
changeset | 240 | private_data.read_entry(db, entry_name, cache) | 
| 78356 | 241 | } | 
| 78211 | 242 | |
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 243 | |
| 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 244 | /* database consumer thread */ | 
| 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 245 | |
| 74255 | 246 | def consumer(db: SQL.Database, cache: XML.Cache, progress: Progress = new Progress): Consumer = | 
| 247 | new Consumer(db, cache, progress) | |
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 248 | |
| 75393 | 249 |   class Consumer private[Export](db: SQL.Database, cache: XML.Cache, progress: Progress) {
 | 
| 68924 | 250 | private val errors = Synchronized[List[String]](Nil) | 
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 251 | |
| 78564 | 252 |     private def consume(args: List[(Entry, Boolean)]): List[Exn.Result[Unit]] = {
 | 
| 253 |       private_data.transaction_lock(db, label = "Export.consumer(" + args.length + ")") {
 | |
| 254 | var known = private_data.known_entries(db, args.map(p => p._1.entry_name)) | |
| 255 | val buffer = new mutable.ListBuffer[Option[Entry]] | |
| 256 | ||
| 257 |         for ((entry, strict) <- args) {
 | |
| 258 |           if (progress.stopped || known(entry.entry_name)) {
 | |
| 259 | buffer += None | |
| 260 |             if (strict && known(entry.entry_name)) {
 | |
| 261 |               val msg = message("Duplicate export", entry.theory_name, entry.name)
 | |
| 262 | errors.change(msg :: _) | |
| 263 | } | |
| 264 | } | |
| 265 |           else {
 | |
| 266 | buffer += Some(entry) | |
| 267 | known += entry.entry_name | |
| 268 | } | |
| 269 | } | |
| 270 | ||
| 271 | val entries = buffer.toList | |
| 272 |         try {
 | |
| 273 | private_data.write_entries(db, entries.flatten) | |
| 274 | val ok = Exn.Res[Unit](()) | |
| 275 | entries.map(_ => ok) | |
| 276 | } | |
| 277 |         catch {
 | |
| 278 | case exn: Throwable => | |
| 279 | val err = Exn.Exn[Unit](exn) | |
| 280 | entries.map(_ => err) | |
| 281 | } | |
| 282 | } | |
| 283 | } | |
| 284 | ||
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 285 | private val consumer = | 
| 71145 
2f782d5f5d5a
improved performance of session exports via bulk transactions;
 wenzelm parents: 
71141diff
changeset | 286 | Consumer_Thread.fork_bulk[(Entry, Boolean)](name = "export")( | 
| 80303 
11fee9e6ba43
more robust: prefer synchronous compression (usually <= 1ms, sometimes 1..5ms);
 wenzelm parents: 
79844diff
changeset | 287 | bulk = _ => true, | 
| 78564 | 288 | consume = args => (args.grouped(20).toList.flatMap(consume), true)) | 
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 289 | |
| 77681 
1db732e6c3d2
back to compression in Isabelle/Scala (in contrast to f7174238b5e3), e.g. relevant for old_command_timings_blob, but also for prospective heaps;
 wenzelm parents: 
77599diff
changeset | 290 |     def make_entry(session_name: String, args: Protocol.Export.Args, body: Bytes): Unit = {
 | 
| 75762 
985c3a64748c
clarified signature: more uniform treatment of empty exports;
 wenzelm parents: 
75759diff
changeset | 291 |       if (!progress.stopped && !body.is_empty) {
 | 
| 76851 | 292 | consumer.send(Entry.make(session_name, args, body, cache) -> args.strict) | 
| 74257 | 293 | } | 
| 294 | } | |
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 295 | |
| 75393 | 296 |     def shutdown(close: Boolean = false): List[String] = {
 | 
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 297 | consumer.shutdown() | 
| 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 298 | if (close) db.close() | 
| 74255 | 299 |       errors.value.reverse ::: (if (progress.stopped) List("Export stopped") else Nil)
 | 
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 300 | } | 
| 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 301 | } | 
| 68116 | 302 | |
| 303 | ||
| 75786 | 304 | /* context for database access */ | 
| 75772 | 305 | |
| 78379 | 306 | def open_database_context(store: Store, server: SSH.Server = SSH.no_server): Database_Context = | 
| 307 | new Database_Context(store, store.maybe_open_database_server(server = server)) | |
| 75786 | 308 | |
| 78379 | 309 | def open_session_context0( | 
| 310 | store: Store, | |
| 311 | session: String, | |
| 312 | server: SSH.Server = SSH.no_server | |
| 313 |   ): Session_Context = {
 | |
| 314 | open_database_context(store, server = server) | |
| 315 | .open_session0(session, close_database_context = true) | |
| 316 | } | |
| 75772 | 317 | |
| 75786 | 318 | def open_session_context( | 
| 78178 | 319 | store: Store, | 
| 76656 | 320 | session_background: Sessions.Background, | 
| 78379 | 321 | document_snapshot: Option[Document.Snapshot] = None, | 
| 322 | server: SSH.Server = SSH.no_server | |
| 75786 | 323 |   ): Session_Context = {
 | 
| 78379 | 324 | open_database_context(store, server = server).open_session( | 
| 76656 | 325 | session_background, document_snapshot = document_snapshot, close_database_context = true) | 
| 75786 | 326 | } | 
| 75771 | 327 | |
| 75786 | 328 | class Database_Context private[Export]( | 
| 78178 | 329 | val store: Store, | 
| 75786 | 330 | val database_server: Option[SQL.Database] | 
| 331 |   ) extends AutoCloseable {
 | |
| 332 | database_context => | |
| 75782 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 333 | |
| 75786 | 334 |     override def toString: String = {
 | 
| 335 | val s = | |
| 336 |         database_server match {
 | |
| 337 | case Some(db) => db.toString | |
| 338 |           case None => "input_dirs = " + store.input_dirs.map(_.absolute).mkString(", ")
 | |
| 339 | } | |
| 340 |       "Database_Context(" + s + ")"
 | |
| 341 | } | |
| 342 | ||
| 343 | def cache: Term.Cache = store.cache | |
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 344 | |
| 75786 | 345 | def close(): Unit = database_server.foreach(_.close()) | 
| 346 | ||
| 75970 | 347 | def open_database(session: String, output: Boolean = false): Session_Database = | 
| 75786 | 348 |       database_server match {
 | 
| 75787 | 349 | case Some(db) => new Session_Database(session, db) | 
| 350 | case None => | |
| 75970 | 351 |           new Session_Database(session, store.open_database(session, output = output)) {
 | 
| 75787 | 352 | override def close(): Unit = db.close() | 
| 353 | } | |
| 75786 | 354 | } | 
| 355 | ||
| 356 | def open_session0(session: String, close_database_context: Boolean = false): Session_Context = | |
| 76656 | 357 | open_session(Sessions.background0(session), close_database_context = close_database_context) | 
| 75779 
5470c67bd772
clarified signature: prefer Export.Session_Context;
 wenzelm parents: 
75778diff
changeset | 358 | |
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 359 | def open_session( | 
| 76656 | 360 | session_background: Sessions.Background, | 
| 75772 | 361 | document_snapshot: Option[Document.Snapshot] = None, | 
| 75786 | 362 | close_database_context: Boolean = false | 
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 363 |     ): Session_Context = {
 | 
| 76656 | 364 | val session_name = session_background.check_errors.session_name | 
| 365 | val session_hierarchy = session_background.sessions_structure.build_hierarchy(session_name) | |
| 75773 
11b2bf6f90d8
clarified signature: less redundant -- Sessions.Base_Info already specifies the main session;
 wenzelm parents: 
75772diff
changeset | 366 | val session_databases = | 
| 75786 | 367 |         database_server match {
 | 
| 75771 | 368 | case Some(db) => session_hierarchy.map(name => new Session_Database(name, db)) | 
| 369 | case None => | |
| 75775 
70a65ee4a738
clarified signature: more robust treatment of server;
 wenzelm parents: 
75774diff
changeset | 370 | val attempts = | 
| 78367 | 371 | for (name <- session_hierarchy) | 
| 372 | yield name -> store.try_open_database(name, server_mode = false) | |
| 75771 | 373 |             attempts.collectFirst({ case (name, None) => name }) match {
 | 
| 374 | case Some(bad) => | |
| 78592 | 375 | for (case (_, Some(db)) <- attempts) db.close() | 
| 75791 | 376 | store.error_database(bad) | 
| 75764 
07e097f60b85
clarified signature: more robust close operation;
 wenzelm parents: 
75762diff
changeset | 377 | case None => | 
| 78592 | 378 |                 for (case (name, Some(db)) <- attempts) yield {
 | 
| 75764 
07e097f60b85
clarified signature: more robust close operation;
 wenzelm parents: 
75762diff
changeset | 379 |                   new Session_Database(name, db) { override def close(): Unit = this.db.close() }
 | 
| 
07e097f60b85
clarified signature: more robust close operation;
 wenzelm parents: 
75762diff
changeset | 380 | } | 
| 
07e097f60b85
clarified signature: more robust close operation;
 wenzelm parents: 
75762diff
changeset | 381 | } | 
| 75771 | 382 | } | 
| 76656 | 383 | new Session_Context( | 
| 384 |           database_context, session_background, session_databases, document_snapshot) {
 | |
| 75772 | 385 |         override def close(): Unit = {
 | 
| 386 | session_databases.foreach(_.close()) | |
| 75786 | 387 | if (close_database_context) database_context.close() | 
| 75772 | 388 | } | 
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 389 | } | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 390 | } | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 391 | } | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 392 | |
| 75789 | 393 | class Session_Database private[Export](val session: String, val db: SQL.Database) | 
| 394 |   extends AutoCloseable {
 | |
| 395 | def close(): Unit = () | |
| 396 | ||
| 78211 | 397 | lazy private [Export] val theory_names: List[String] = read_theory_names(db, session) | 
| 398 | lazy private [Export] val entry_names: List[Entry_Name] = read_entry_names(db, session) | |
| 75789 | 399 | } | 
| 400 | ||
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 401 | class Session_Context private[Export]( | 
| 75786 | 402 | val database_context: Database_Context, | 
| 76656 | 403 | session_background: Sessions.Background, | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 404 | db_hierarchy: List[Session_Database], | 
| 77005 | 405 | val document_snapshot: Option[Document.Snapshot] | 
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 406 |   ) extends AutoCloseable {
 | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 407 | session_context => | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 408 | |
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 409 | def close(): Unit = () | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 410 | |
| 75786 | 411 | def cache: Term.Cache = database_context.cache | 
| 75778 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 412 | |
| 76656 | 413 | def sessions_structure: Sessions.Structure = session_background.sessions_structure | 
| 75778 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 414 | |
| 76656 | 415 | def session_base: Sessions.Base = session_background.base | 
| 75778 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 416 | |
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 417 | def session_name: String = | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 418 | if (document_snapshot.isDefined) Sessions.DRAFT | 
| 75773 
11b2bf6f90d8
clarified signature: less redundant -- Sessions.Base_Info already specifies the main session;
 wenzelm parents: 
75772diff
changeset | 419 | else session_base.session_name | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 420 | |
| 75780 
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
 wenzelm parents: 
75779diff
changeset | 421 | def session_database(session: String = session_name): Option[Session_Database] = | 
| 
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
 wenzelm parents: 
75779diff
changeset | 422 | db_hierarchy.find(_.session == session) | 
| 
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
 wenzelm parents: 
75779diff
changeset | 423 | |
| 
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
 wenzelm parents: 
75779diff
changeset | 424 | def session_db(session: String = session_name): Option[SQL.Database] = | 
| 
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
 wenzelm parents: 
75779diff
changeset | 425 | session_database(session = session).map(_.db) | 
| 
f49c4f160b84
clarified signature: find session_database within Session_Context.db_hierarchy;
 wenzelm parents: 
75779diff
changeset | 426 | |
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 427 | def session_stack: List[String] = | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 428 | ((if (document_snapshot.isDefined) List(session_name) else Nil) ::: | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 429 | db_hierarchy.map(_.session)).reverse | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 430 | |
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 431 | private def select[A]( | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 432 | session: String, | 
| 75860 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 433 | select: Session_Database => List[A], | 
| 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 434 | project: Entry_Name => A, | 
| 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 435 | sort_key: A => String | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 436 |     ): List[A] = {
 | 
| 75860 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 437 | def result(name: String): List[A] = | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 438 |         if (name == Sessions.DRAFT) {
 | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 439 |           (for {
 | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 440 | snapshot <- document_snapshot.iterator | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 441 | entry_name <- snapshot.all_exports.keysIterator | 
| 75860 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 442 | } yield project(entry_name)).toSet.toList.sortBy(sort_key) | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 443 | } | 
| 75860 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 444 | else session_database(name).map(select).getOrElse(Nil) | 
| 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 445 | |
| 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 446 | if (session.nonEmpty) result(session) else session_stack.flatMap(result) | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 447 | } | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 448 | |
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 449 | def entry_names(session: String = session_name): List[Entry_Name] = | 
| 75860 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 450 | select(session, _.entry_names, identity, _.compound_name) | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 451 | |
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 452 | def theory_names(session: String = session_name): List[String] = | 
| 75860 
2b2c09f4e7b5
proper export theory_names: theory/parents are not necessarily present (amending 4d27b520622a);
 wenzelm parents: 
75825diff
changeset | 453 | select(session, _.theory_names, _.theory, identity) | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 454 | |
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 455 | def get(theory: String, name: String): Option[Entry] = | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 456 |     {
 | 
| 75784 | 457 | def snapshot_entry: Option[Entry] = | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 458 |         for {
 | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 459 | snapshot <- document_snapshot | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 460 | entry_name = Entry_Name(session = Sessions.DRAFT, theory = theory, name = name) | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 461 | entry <- snapshot.all_exports.get(entry_name) | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 462 | } yield entry | 
| 75784 | 463 | def db_entry: Option[Entry] = | 
| 78209 | 464 |         db_hierarchy.view.map { database =>
 | 
| 465 | val entry_name = Export.Entry_Name(session = database.session, theory = theory, name = name) | |
| 78211 | 466 | read_entry(database.db, entry_name, cache) | 
| 78209 | 467 |         }.collectFirst({ case Some(entry) => entry })
 | 
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 468 | |
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 469 | snapshot_entry orElse db_entry | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 470 | } | 
| 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 471 | |
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 472 | def apply(theory: String, name: String, permissive: Boolean = false): Entry = | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 473 |       get(theory, name) match {
 | 
| 76851 | 474 | case None if permissive => Entry.empty(theory, name) | 
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 475 |         case None => error("Missing export entry " + quote(compound_name(theory, name)))
 | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 476 | case Some(entry) => entry | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 477 | } | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 478 | |
| 75790 
0ab8a9177e41
clarified signature: more uniform treatment of cache for Export.read_session vs. Export.read_theory;
 wenzelm parents: 
75789diff
changeset | 479 | def theory(theory: String, other_cache: Option[Term.Cache] = None): Theory_Context = | 
| 
0ab8a9177e41
clarified signature: more uniform treatment of cache for Export.read_session vs. Export.read_theory;
 wenzelm parents: 
75789diff
changeset | 480 | new Theory_Context(session_context, theory, other_cache) | 
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 481 | |
| 78178 | 482 |     def get_source_file(name: String): Option[Store.Source_File] = {
 | 
| 76909 | 483 | val store = database_context.store | 
| 484 |       (for {
 | |
| 485 | database <- db_hierarchy.iterator | |
| 486 | file <- store.read_sources(database.db, database.session, name = name).iterator | |
| 487 | } yield file).nextOption() | |
| 488 | } | |
| 489 | ||
| 78178 | 490 | def source_file(name: String): Store.Source_File = | 
| 76910 | 491 |       get_source_file(name).getOrElse(error("Missing session source file " + quote(name)))
 | 
| 492 | ||
| 77023 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 493 |     def theory_source(theory: String, unicode_symbols: Boolean = false): String = {
 | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 494 | def snapshot_source: Option[String] = | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 495 |         for {
 | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 496 | snapshot <- document_snapshot | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 497 | text <- snapshot.version.nodes.iterator.collectFirst( | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 498 |             { case (name, node) if name.theory == theory => node.source })
 | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 499 | if text.nonEmpty | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 500 | } yield Symbol.output(unicode_symbols, text) | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 501 | |
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 502 |       def db_source: Option[String] = {
 | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 503 | val theory_context = session_context.theory(theory) | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 504 |         for {
 | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 505 | name <- theory_context.files0(permissive = true).headOption | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 506 | file <- get_source_file(name) | 
| 77168 
547d140f0780
more uniform use of Symbol.output, even in situations where its Symbol.encode is usually redundant;
 wenzelm parents: 
77026diff
changeset | 507 | } yield Symbol.output(unicode_symbols, file.bytes.text) | 
| 77023 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 508 | } | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 509 | |
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 510 | snapshot_source orElse db_source getOrElse "" | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 511 | } | 
| 
474a07221c27
more robust theory_source -- in contrast to node_source from fffb978dd683: theory name is more reliable than Document.Node.Name, explicit unicode_symbols;
 wenzelm parents: 
77005diff
changeset | 512 | |
| 75825 | 513 |     def classpath(): List[File.Content] = {
 | 
| 75782 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 514 |       (for {
 | 
| 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 515 | session <- session_stack.iterator | 
| 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 516 | info <- sessions_structure.get(session).iterator | 
| 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 517 | if info.export_classpath.nonEmpty | 
| 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 518 | matcher = make_matcher(info.export_classpath) | 
| 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 519 | entry_name <- entry_names(session = session).iterator | 
| 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 520 | if matcher(entry_name) | 
| 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 521 | entry <- get(entry_name.theory, entry_name.name).iterator | 
| 76852 | 522 | } yield File.content(entry.entry_name.make_path(), entry.bytes)).toList | 
| 75918 | 523 | } | 
| 75782 
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
 wenzelm parents: 
75780diff
changeset | 524 | |
| 75918 | 525 | override def toString: String = | 
| 75770 
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
 wenzelm parents: 
75769diff
changeset | 526 |       "Export.Session_Context(" + commas_quote(session_stack) + ")"
 | 
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 527 | } | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 528 | |
| 75774 
efc25bf4b795
discontinued Export.Provider in favour of Export.Context and its derivatives;
 wenzelm parents: 
75773diff
changeset | 529 | class Theory_Context private[Export]( | 
| 
efc25bf4b795
discontinued Export.Provider in favour of Export.Context and its derivatives;
 wenzelm parents: 
75773diff
changeset | 530 | val session_context: Session_Context, | 
| 75790 
0ab8a9177e41
clarified signature: more uniform treatment of cache for Export.read_session vs. Export.read_theory;
 wenzelm parents: 
75789diff
changeset | 531 | val theory: String, | 
| 
0ab8a9177e41
clarified signature: more uniform treatment of cache for Export.read_session vs. Export.read_theory;
 wenzelm parents: 
75789diff
changeset | 532 | other_cache: Option[Term.Cache] | 
| 75774 
efc25bf4b795
discontinued Export.Provider in favour of Export.Context and its derivatives;
 wenzelm parents: 
75773diff
changeset | 533 |   ) {
 | 
| 75790 
0ab8a9177e41
clarified signature: more uniform treatment of cache for Export.read_session vs. Export.read_theory;
 wenzelm parents: 
75789diff
changeset | 534 | def cache: Term.Cache = other_cache getOrElse session_context.cache | 
| 75778 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 535 | |
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 536 | def get(name: String): Option[Entry] = session_context.get(theory, name) | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 537 | def apply(name: String, permissive: Boolean = false): Entry = | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 538 | session_context.apply(theory, name, permissive = permissive) | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 539 | |
| 80447 
325907d85977
minor performance tuning: allow recode operation during YXML parsing;
 wenzelm parents: 
80350diff
changeset | 540 | def yxml(name: String, recode: String => String = identity): XML.Body = | 
| 75774 
efc25bf4b795
discontinued Export.Provider in favour of Export.Context and its derivatives;
 wenzelm parents: 
75773diff
changeset | 541 |       get(name) match {
 | 
| 80447 
325907d85977
minor performance tuning: allow recode operation during YXML parsing;
 wenzelm parents: 
80350diff
changeset | 542 | case Some(entry) => entry.yxml(recode = recode) | 
| 75774 
efc25bf4b795
discontinued Export.Provider in favour of Export.Context and its derivatives;
 wenzelm parents: 
75773diff
changeset | 543 | case None => Nil | 
| 
efc25bf4b795
discontinued Export.Provider in favour of Export.Context and its derivatives;
 wenzelm parents: 
75773diff
changeset | 544 | } | 
| 
efc25bf4b795
discontinued Export.Provider in favour of Export.Context and its derivatives;
 wenzelm parents: 
75773diff
changeset | 545 | |
| 75778 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 546 | def document_id(): Option[Long] = | 
| 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 547 |       apply(DOCUMENT_ID, permissive = true).text match {
 | 
| 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 548 | case Value.Long(id) => Some(id) | 
| 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 549 | case _ => None | 
| 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 550 | } | 
| 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 551 | |
| 75901 | 552 | def files0(permissive: Boolean = false): List[String] = | 
| 553 | split_lines(apply(FILES, permissive = permissive).text) | |
| 554 | ||
| 555 | def files(permissive: Boolean = false): Option[(String, List[String])] = | |
| 556 |       files0(permissive = permissive) match {
 | |
| 75778 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 557 | case Nil => None | 
| 75901 | 558 | case a :: bs => Some((a, bs)) | 
| 75778 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 559 | } | 
| 
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
 wenzelm parents: 
75775diff
changeset | 560 | |
| 75759 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 561 |     override def toString: String = "Export.Theory_Context(" + quote(theory) + ")"
 | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 562 | } | 
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 563 | |
| 
0cdccd0d1699
clarified context for retrieval: more explicit types, with optional close() operation;
 wenzelm parents: 
75757diff
changeset | 564 | |
| 68288 | 565 | /* export to file-system */ | 
| 566 | ||
| 567 | def export_files( | |
| 78178 | 568 | store: Store, | 
| 68288 | 569 | session_name: String, | 
| 570 | export_dir: Path, | |
| 71726 
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
 wenzelm parents: 
71624diff
changeset | 571 | progress: Progress = new Progress, | 
| 69671 | 572 | export_prune: Int = 0, | 
| 68288 | 573 | export_list: Boolean = false, | 
| 75393 | 574 | export_patterns: List[String] = Nil | 
| 575 |   ): Unit = {
 | |
| 75394 | 576 |     using(store.open_database(session_name)) { db =>
 | 
| 78211 | 577 | val entry_names = read_entry_names(db, session_name) | 
| 68288 | 578 | |
| 75739 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 579 | // list | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 580 |       if (export_list) {
 | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 581 | for (entry_name <- entry_names) progress.echo(entry_name.compound_name) | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 582 | } | 
| 68288 | 583 | |
| 75739 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 584 | // export | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 585 |       if (export_patterns.nonEmpty) {
 | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 586 | val matcher = make_matcher(export_patterns) | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 587 |         for {
 | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 588 | entry_name <- entry_names if matcher(entry_name) | 
| 78211 | 589 | entry <- read_entry(db, entry_name, store.cache) | 
| 75739 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 590 |         } {
 | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 591 | val path = export_dir + entry_name.make_path(prune = export_prune) | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 592 |           progress.echo("export " + path + (if (entry.executable) " (executable)" else ""))
 | 
| 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 593 | Isabelle_System.make_directory(path.dir) | 
| 76852 | 594 | val bytes = entry.bytes | 
| 75739 
5b37466c1463
removed somewhat pointless transaction: db is meant to be finished (or updated monotonically);
 wenzelm parents: 
75736diff
changeset | 595 | if (!path.is_file || Bytes.read(path) != bytes) Bytes.write(path, bytes) | 
| 78298 
3b0f8f1010f2
clarified signature, with subtle change of semantics (amending 8b5a2e4b16d4);
 wenzelm parents: 
78260diff
changeset | 596 | File.set_executable(path, reset = !entry.executable) | 
| 68288 | 597 | } | 
| 598 | } | |
| 75394 | 599 | } | 
| 68288 | 600 | } | 
| 601 | ||
| 602 | ||
| 68116 | 603 | /* Isabelle tool wrapper */ | 
| 604 | ||
| 71601 | 605 |   val default_export_dir: Path = Path.explode("export")
 | 
| 68116 | 606 | |
| 75394 | 607 | val isabelle_tool = | 
| 608 |     Isabelle_Tool("export", "retrieve theory exports", Scala_Project.here,
 | |
| 609 |       { args =>
 | |
| 610 | /* arguments */ | |
| 68116 | 611 | |
| 75394 | 612 | var export_dir = default_export_dir | 
| 613 | var dirs: List[Path] = Nil | |
| 614 | var export_list = false | |
| 615 | var no_build = false | |
| 616 | var options = Options.init() | |
| 617 | var export_prune = 0 | |
| 618 | var export_patterns: List[String] = Nil | |
| 68116 | 619 | |
| 75394 | 620 |         val getopts = Getopts("""
 | 
| 68116 | 621 | Usage: isabelle export [OPTIONS] SESSION | 
| 622 | ||
| 623 | Options are: | |
| 68314 
2acbf8129d8b
clarified option -O: avoid conflict with build/dump option -D;
 wenzelm parents: 
68305diff
changeset | 624 | -O DIR output directory for exported files (default: """ + default_export_dir + """) | 
| 68116 | 625 | -d DIR include session directory | 
| 626 | -l list exports | |
| 627 | -n no build of session | |
| 628 | -o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) | |
| 69671 | 629 | -p NUM prune path of exported files by NUM elements | 
| 68116 | 630 | -x PATTERN extract files matching pattern (e.g. "*:**" for all) | 
| 631 | ||
| 632 | List or export theory exports for SESSION: named blobs produced by | |
| 68290 | 633 | isabelle build. Option -l or -x is required; option -x may be repeated. | 
| 68116 | 634 | |
| 635 | The PATTERN language resembles glob patterns in the shell, with ? and * | |
| 636 | (both excluding ":" and "/"), ** (excluding ":"), and [abc] or [^abc], | |
| 637 |   and variants {pattern1,pattern2,pattern3}.
 | |
| 638 | """, | |
| 75394 | 639 | "O:" -> (arg => export_dir = Path.explode(arg)), | 
| 640 | "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), | |
| 641 | "l" -> (_ => export_list = true), | |
| 642 | "n" -> (_ => no_build = true), | |
| 643 | "o:" -> (arg => options = options + arg), | |
| 644 | "p:" -> (arg => export_prune = Value.Int.parse(arg)), | |
| 645 | "x:" -> (arg => export_patterns ::= arg)) | |
| 68116 | 646 | |
| 75394 | 647 | val more_args = getopts(args) | 
| 648 | val session_name = | |
| 649 |           more_args match {
 | |
| 650 | case List(session_name) if export_list || export_patterns.nonEmpty => session_name | |
| 651 | case _ => getopts.usage() | |
| 652 | } | |
| 68116 | 653 | |
| 75394 | 654 | val progress = new Console_Progress() | 
| 68305 | 655 | |
| 68116 | 656 | |
| 75394 | 657 | /* build */ | 
| 68116 | 658 | |
| 75394 | 659 |         if (!no_build) {
 | 
| 660 | val rc = | |
| 661 |             progress.interrupt_handler {
 | |
| 662 | Build.build_logic(options, session_name, progress = progress, dirs = dirs) | |
| 663 | } | |
| 664 | if (rc != Process_Result.RC.ok) sys.exit(rc) | |
| 68331 | 665 | } | 
| 68116 | 666 | |
| 667 | ||
| 75394 | 668 | /* export files */ | 
| 68116 | 669 | |
| 79675 | 670 | export_files(Store(options), session_name, export_dir, progress = progress, | 
| 671 | export_prune = export_prune, export_list = export_list, export_patterns = export_patterns) | |
| 75394 | 672 | }) | 
| 68092 
888d35a19866
store exports in session database, with asynchronous / parallel compression;
 wenzelm parents: diff
changeset | 673 | } |