diff options
| author | Ralph Amissah <ralph.amissah@gmail.com> | 2026-09-21 11:42:42 -0400 |
|---|---|---|
| committer | Ralph Amissah <ralph.amissah@gmail.com> | 2026-09-22 14:54:32 -0400 |
| commit | 3f87aa600b5080135557d846ee1ba7daef9d3155 (patch) | |
| tree | fed92ba22b9baa0b8f3acfbb1eda46f5f5fa5d67 /src/sisudoc/spine.d | |
| parent | ocda db: one <doc>.ocda.db holding every language (diff) | |
ocda.db: read a document language of a database
A database now holds every language of its document, so reading one
means naming a language. Three small pieces:
- spineDbLanguages says what languages a file holds. Its own template
rather than part of the reader (asking a file what it holds does not
instantiate the object setter and the markup regexes with it).
- abstractionLoad and spineDocFromArtefact take a language and pass it
to dbReadFile, which resolves it to a doc_id, takes that language
document where there is one, and lists the languages and stops where
there is a choice.
- spineArtefactLanguages turns an artefact into the documents to build:
one for a .ssp, and for a database the languages it holds filtered by
--lang. The artefact loop then has a language loop inside it, so a
single .ocda.db argument builds every language, as the pod it came
from would.
--db-round-trip takes --lang for the same reason, and ocda-db looses
--parallel (would cause a race).
(assisted by Claude-Code)
Diffstat (limited to 'src/sisudoc/spine.d')
| -rw-r--r-- | src/sisudoc/spine.d | 102 |
1 files changed, 72 insertions, 30 deletions
diff --git a/src/sisudoc/spine.d b/src/sisudoc/spine.d index 9424e02..ab4eaa3 100644 --- a/src/sisudoc/spine.d +++ b/src/sisudoc/spine.d @@ -431,7 +431,26 @@ string program_name = "spine"; import sisudoc.ocda.abstraction.db_in; mixin spineAbstractionDbRead; mixin sspObjectRecord; - auto _doc = dbReadFile(settings["db-round-trip"]); + /+ ↓ a database now holds every language of its document, so a language has to + be named. --lang says which; with none named dbReadFile if there is only + one, takes the only document there is, and where there is a choice + reports the languages and stops rather than picking one. A .ssp emitted + for a language nobody asked for would match nothing, and this is what the + round trip test compares byte for byte. + +/ + string _rt_lang = ""; + { + auto _langs = settings["lang"].split(","); + if (_langs.length > 0 && _langs[0] != "all") { + _rt_lang = _langs[0]; + } + } + auto _doc = dbReadFile(settings["db-round-trip"], _rt_lang); + if (_doc.format.length == 0 && _doc.section_order.length == 0) { + import core.stdc.stdlib : exit; + stdout.flush; + exit(1); + } string[] _out; if (_doc.format.length > 0) { _out ~= _doc.format; } if (_doc.source.length > 0) { _out ~= "% Source: " ~ _doc.source; } @@ -880,8 +899,15 @@ string program_name = "spine"; } else if ( /+ ↓ these cannot run in parallel however asked: --curate aggregates across documents, and the shared sqlite db has the one writer + . + --ocda-db joins them because one database now holds every + language of a document, written a language at a time. Several + languages at once against one file, one of them clearing it and + each opening its own transaction, is a race, and the losing + language would be missing from the artefact. +/ sqlite_shared_db_action + || ocda_db || source_or_pod ) { _is = false; @@ -1690,38 +1716,54 @@ string program_name = "spine"; _artefact_args.join(", ")); } foreach (_artefact; _artefact_args) { - auto doc = spineDocFromArtefact!()( - _artefact, program_info, _opt_action, _env, _make_and_meta_struct, - ); - if (!doc.loaded) { - stderr.writeln("ERROR: could not load ", _artefact, - (doc.note.length > 0) ? ": " ~ doc.note : ""); + /+ ↓ a .ocda.db holds every language of its document, so one artefact can + be several documents to build. A .ssp is one, and comes back as a + single unnamed language. + +/ + string[] _artefact_langs + = spineArtefactLanguages!()(_artefact, _opt_action.languages_set); + if (_artefact_langs.length == 0) { + stderr.writeln("WARNING: ", _artefact.baseName, + " holds no document in the language(s) asked for: ", + _opt_action.languages_set.join(" ")); continue; } - if (_opt_action.vox_gt_1) { - writeln("-- ~ document from ", doc.source_name, - " ~ ------------------------------------"); - writeln(" ", _artefact); - } - if (doc.matters.opt.action.curate) { - auto _hvst = spineMetaDocCurate!()(doc.matters, hvst); - if (_hvst.title.length > 0 && _hvst.author_surname_fn.length > 0) { - hvst.curates ~= _hvst; + foreach (_artefact_lang; _artefact_langs) { + auto doc = spineDocFromArtefact!()( + _artefact, program_info, _opt_action, _env, _make_and_meta_struct, + _artefact_lang, + ); + if (!doc.loaded) { + stderr.writeln("ERROR: could not load ", _artefact, + (_artefact_lang.length > 0) ? " [" ~ _artefact_lang ~ "]" : "", + (doc.note.length > 0) ? ": " ~ doc.note : ""); + continue; } - } - if (!(doc.matters.opt.action.skip_output)) { - doc.outputHub!(); - } - if (_opt_action.vox_gt_1) { - writeln("processed artefact: ", _artefact.baseName, - " [", doc.matters.src.language, "]"); - } - /+ ↓ the images a database carried, written out for this run only +/ - if (doc.images_tmp.length > 0) { - try { - if (doc.images_tmp.exists) { doc.images_tmp.rmdirRecurse; } - } catch (Exception ex) { - stderr.writeln("WARNING: could not remove ", doc.images_tmp, ": ", ex.msg); + if (_opt_action.vox_gt_1) { + writeln("-- ~ document from ", doc.source_name, + " ~ ------------------------------------"); + writeln(" ", _artefact); + } + if (doc.matters.opt.action.curate) { + auto _hvst = spineMetaDocCurate!()(doc.matters, hvst); + if (_hvst.title.length > 0 && _hvst.author_surname_fn.length > 0) { + hvst.curates ~= _hvst; + } + } + if (!(doc.matters.opt.action.skip_output)) { + doc.outputHub!(); + } + if (_opt_action.vox_gt_1) { + writeln("processed artefact: ", _artefact.baseName, + " [", doc.matters.src.language, "]"); + } + /+ ↓ the images a database carried, written out for this run only +/ + if (doc.images_tmp.length > 0) { + try { + if (doc.images_tmp.exists) { doc.images_tmp.rmdirRecurse; } + } catch (Exception ex) { + stderr.writeln("WARNING: could not remove ", doc.images_tmp, ": ", ex.msg); + } } } } |
