From da0f051e1aced4fa1fd5cd13c0548279bf04b2a0 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 12 Apr 2017 15:23:23 -0400 Subject: 0.13.9 sisupod & epub3, zipped output --- src/sdp/source_sisupod.d | 201 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 152 insertions(+), 49 deletions(-) (limited to 'src/sdp/source_sisupod.d') diff --git a/src/sdp/source_sisupod.d b/src/sdp/source_sisupod.d index e6702bf..cf15348 100644 --- a/src/sdp/source_sisupod.d +++ b/src/sdp/source_sisupod.d @@ -3,103 +3,206 @@ template SiSUpod() { std.algorithm, std.array, std.container, + std.digest.sha, std.exception, std.file, std.getopt, std.json, - std.process, - std.stdio, + std.outbuffer, std.path, + std.process, std.range, std.regex, + std.stdio, std.string, std.traits, std.typecons, std.uni, std.utf, + std.zip, std.conv : to; import + create_zip_file, defaults, output_rgx, output_xhtmls; void SiSUpod(T)(T doc_matters) { - debug(asserts){ + debug(asserts) { // static assert(is(typeof(doc_matters) == tuple)); } mixin SiSUoutputRgxInit; mixin SiSUpaths; - auto pth_sisupod = SiSUpodPaths(); + auto pth_sisupod = SiSUpodPathsZipped(); + auto pth_sisupod_filesystem = SiSUpodPathsFilesystemArchive(); mixin SiSUlanguageCodes; auto lang = Lang(); auto rgx = Rgx(); assert (doc_matters.source_filename.match(rgx.src_fn)); try { /+ create directory structure +/ - if (!exists(pth_sisupod.doc(doc_matters.source_filename))) { - pth_sisupod.doc(doc_matters.source_filename).mkdirRecurse; + if (!exists(pth_sisupod_filesystem.doc(doc_matters.source_filename))) { + pth_sisupod_filesystem.doc(doc_matters.source_filename).mkdirRecurse; } - if (!exists(pth_sisupod.conf(doc_matters.source_filename))) { - pth_sisupod.conf(doc_matters.source_filename).mkdirRecurse; + if (!exists(pth_sisupod_filesystem.conf(doc_matters.source_filename))) { + pth_sisupod_filesystem.conf(doc_matters.source_filename).mkdirRecurse; } - if (!exists(pth_sisupod.css(doc_matters.source_filename))) { - pth_sisupod.css(doc_matters.source_filename).mkdirRecurse; + if (!exists(pth_sisupod_filesystem.css(doc_matters.source_filename))) { + pth_sisupod_filesystem.css(doc_matters.source_filename).mkdirRecurse; } - if (!exists(pth_sisupod.image(doc_matters.source_filename))) { - pth_sisupod.image(doc_matters.source_filename).mkdirRecurse; + if (!exists(pth_sisupod_filesystem.image(doc_matters.source_filename))) { + pth_sisupod_filesystem.image(doc_matters.source_filename).mkdirRecurse; } - if (!exists(pth_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language))) { - pth_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language).mkdirRecurse; + if (!exists(pth_sisupod_filesystem.doc_lng(doc_matters.source_filename, doc_matters.language))) { + pth_sisupod_filesystem.doc_lng(doc_matters.source_filename, doc_matters.language).mkdirRecurse; } debug(sisupod) { writeln(__LINE__, ": ", - // doc_matters.environment["pwd"], "/", - doc_matters.source_filename, " -> ", - // doc_matters.environment["pwd"], "/", - pth_sisupod.fn_doc( - doc_matters.source_filename, - doc_matters.language - )); - } - if (exists(doc_matters.source_filename)) { - copy( + doc_matters.source_filename, " -> ", + pth_sisupod_filesystem.fn_doc( doc_matters.source_filename, - pth_sisupod.fn_doc( - doc_matters.source_filename, - doc_matters.language + doc_matters.language )); } - if (doc_matters.file_insert_list.length > 0) { - foreach (insert_file; doc_matters.file_insert_list) { - debug(sisupod) { + auto zip = new ZipArchive(); + auto fn_sisupod = pth_sisupod.sisupod_filename(doc_matters.source_filename); + { /+ bundle images +/ + foreach (image; doc_matters.image_list) { + debug(sisupodimages) { writeln( + "_sisu/image/", image, " -> ", + pth_sisupod.image(doc_matters.source_filename), "/", image + ); + } + auto fn_src = "_sisu/image/"~ image; + auto fn_out = pth_sisupod.image(doc_matters.source_filename).to!string ~ "/" ~ image; + auto fn_out_filesystem = pth_sisupod_filesystem.image(doc_matters.source_filename).to!string ~ "/" ~ image; + if (exists(fn_src)) { + fn_src.copy(fn_out_filesystem); + { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn_out; + auto zip_data = new OutBuffer(); + zip_data.write(cast(char[]) ((fn_src).read)); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); + } + } + } + } + { /+ bundle sisu_document_make +/ + auto fn_src = "_sisu/sisu_document_make"; // check (_sisu/sisu_document_make) + auto fn_out = pth_sisupod.conf(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; + auto fn_out_filesystem = pth_sisupod_filesystem.conf(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; + if (exists(fn_src)) { + fn_src.copy(fn_out_filesystem); + { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn_out; + auto zip_data = new OutBuffer(); + zip_data.write((fn_src).readText); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); + } + } + } + { /+ bundle primary file +/ + auto fn_src = doc_matters.source_filename; + auto fn_out = pth_sisupod.fn_doc(doc_matters.source_filename, doc_matters.language).to!string; + auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc(doc_matters.source_filename, doc_matters.language).to!string; + if (exists(fn_src)) { + fn_src.copy(fn_out_filesystem); + { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = fn_out; + auto zip_data = new OutBuffer(); + zip_data.write((fn_src).readText); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); + } + } + } + { /+ bundle insert files +/ + if (doc_matters.file_insert_list.length > 0) { + foreach (insert_file; doc_matters.file_insert_list) { + debug(sisupod) { + writeln( insert_file, " -> ", pth_sisupod.fn_doc_insert( doc_matters.source_filename, insert_file, doc_matters.language - )); - } - if (exists(insert_file)) { - insert_file.copy( - pth_sisupod.fn_doc_insert( - doc_matters.source_filename, - insert_file, - doc_matters.language - )); + )); + } + auto fn_src = insert_file; + auto fn_out = pth_sisupod.fn_doc_insert( + doc_matters.source_filename, + insert_file, + doc_matters.language + ).to!string; + auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc_insert( + doc_matters.source_filename, + insert_file, + doc_matters.language + ).to!string; + if (exists(fn_src)) { + fn_src.copy(fn_out_filesystem); + { + auto zip_arc_member_file = new ArchiveMember(); + zip_arc_member_file.name = insert_file; + auto zip_data = new OutBuffer(); + zip_data.write((fn_src).readText); + zip_arc_member_file.expandedData = zip_data.toBytes(); + zip.addMember(zip_arc_member_file); + createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); + } + } } } } - foreach (image; doc_matters.image_list) { - debug(sisupod) { - writeln( - "_sisu/image/", image, " -> ", - pth_sisupod.image(doc_matters.source_filename), "/", image - ); + if (exists(fn_sisupod)) { + try { + auto data = (cast(byte[]) (fn_sisupod).read); + writefln("%-(%02x%) %s", data.sha256Of, fn_sisupod); + debug(sisupod) { + try { + auto zipped = new ZipArchive((fn_sisupod).read); + foreach (filename, member; zipped.directory) { + auto data = zipped.expand(member); + writeln("> ", filename, " length ", data.length); // filename == member.name + // Use data + } + } + catch (ZipException ex) { + // Handle errors + } + if (doc_matters.source_filename == "en/the_wealth_of_networks.yochai_benkler.sst") { + assert( + ((data).sha256Of).toHexString + == "DDE0013C13C6A4F06D4BE72087E2CDEF47697CA38A6A2D65BA7207DB6B144271", + "\nsisupod: sha256 value for " + ~ doc_matters.source_filename + ~ " has changed, is now: " + ~ ((data).sha256Of).toHexString + ); + } + if (doc_matters.source_filename == "en/sisu_markup_stress_test.sst") { + assert( + ((data).sha256Of).toHexString + == "112C0AEDD2518A1803D91A7CF5785274A3116C0779A631782D0C0813B212C68A", + "\nsisupod: sha256 value for " + ~ doc_matters.source_filename + ~ " has changed, is now: " + ~ ((data).sha256Of).toHexString + ); + } + } } - if (exists("_sisu/image/"~ image)) { - ("_sisu/image/"~ image).copy( - (pth_sisupod.image(doc_matters.source_filename) ~ "/" ~ image) - ); + catch (ErrnoException ex) + { + // Handle errors } } -- cgit v1.2.3