equal
deleted
inserted
replaced
61 |
61 |
62 sealed case class Entry( |
62 sealed case class Entry( |
63 session_name: String, |
63 session_name: String, |
64 theory_name: String, |
64 theory_name: String, |
65 name: String, |
65 name: String, |
66 compressed: Boolean, |
66 body: Future[(Boolean, Bytes)]) |
67 body: Future[Bytes]) |
|
68 { |
67 { |
69 override def toString: String = compound_name(theory_name, name) |
68 override def toString: String = compound_name(theory_name, name) |
70 |
69 |
71 def write(db: SQL.Database) |
70 def write(db: SQL.Database) |
72 { |
71 { |
73 val bytes = body.join |
72 val (compressed, bytes) = body.join |
74 db.using_statement(Data.table.insert())(stmt => |
73 db.using_statement(Data.table.insert())(stmt => |
75 { |
74 { |
76 stmt.string(1) = session_name |
75 stmt.string(1) = session_name |
77 stmt.string(2) = theory_name |
76 stmt.string(2) = theory_name |
78 stmt.string(3) = name |
77 stmt.string(3) = name |
80 stmt.bytes(5) = bytes |
79 stmt.bytes(5) = bytes |
81 stmt.execute() |
80 stmt.execute() |
82 }) |
81 }) |
83 } |
82 } |
84 |
83 |
85 def body_uncompressed(cache: XZ.Cache = XZ.cache()): Bytes = |
84 def uncompressed(cache: XZ.Cache = XZ.cache()): Bytes = |
86 if (compressed) body.join.uncompress(cache = cache) else body.join |
85 { |
|
86 val (compressed, bytes) = body.join |
|
87 if (compressed) bytes.uncompress(cache = cache) else bytes |
|
88 } |
87 } |
89 } |
88 |
90 |
89 def make_regex(pattern: String): Regex = |
91 def make_regex(pattern: String): Regex = |
90 { |
92 { |
91 @tailrec def make(result: List[String], depth: Int, chs: List[Char]): Regex = |
93 @tailrec def make(result: List[String], depth: Int, chs: List[Char]): Regex = |
112 } |
114 } |
113 |
115 |
114 def make_entry(session_name: String, args: Markup.Export.Args, body: Bytes, |
116 def make_entry(session_name: String, args: Markup.Export.Args, body: Bytes, |
115 cache: XZ.Cache = XZ.cache()): Entry = |
117 cache: XZ.Cache = XZ.cache()): Entry = |
116 { |
118 { |
117 Entry(session_name, args.theory_name, args.name, args.compress, |
119 Entry(session_name, args.theory_name, args.name, |
118 if (args.compress) Future.fork(body.compress(cache = cache)) else Future.value(body)) |
120 if (args.compress) Future.fork(body.maybe_compress(cache = cache)) |
|
121 else Future.value((false, body))) |
119 } |
122 } |
120 |
123 |
121 def read_entry(db: SQL.Database, session_name: String, theory_name: String, name: String): Entry = |
124 def read_entry(db: SQL.Database, session_name: String, theory_name: String, name: String): Entry = |
122 { |
125 { |
123 val select = |
126 val select = |
127 { |
130 { |
128 val res = stmt.execute_query() |
131 val res = stmt.execute_query() |
129 if (res.next()) { |
132 if (res.next()) { |
130 val compressed = res.bool(Data.compressed) |
133 val compressed = res.bool(Data.compressed) |
131 val body = res.bytes(Data.body) |
134 val body = res.bytes(Data.body) |
132 Entry(session_name, theory_name, name, compressed, Future.value(body)) |
135 Entry(session_name, theory_name, name, Future.value(compressed, body)) |
133 } |
136 } |
134 else error(message("Bad export", theory_name, name)) |
137 else error(message("Bad export", theory_name, name)) |
135 }) |
138 }) |
136 } |
139 } |
137 |
140 |
273 val entry = read_entry(db, session_name, theory_name, name) |
276 val entry = read_entry(db, session_name, theory_name, name) |
274 val path = export_dir + Path.basic(theory_name) + Path.explode(name) |
277 val path = export_dir + Path.basic(theory_name) + Path.explode(name) |
275 |
278 |
276 progress.echo("exporting " + path) |
279 progress.echo("exporting " + path) |
277 Isabelle_System.mkdirs(path.dir) |
280 Isabelle_System.mkdirs(path.dir) |
278 Bytes.write(path, entry.body_uncompressed(cache = xz_cache)) |
281 Bytes.write(path, entry.uncompressed(cache = xz_cache)) |
279 } |
282 } |
280 } |
283 } |
281 } |
284 } |
282 }) |
285 }) |
283 }) |
286 }) |