Browse Source

Fix nasty bug with store init.

scossu 1 day ago
parent
commit
1bc47b621a
6 changed files with 37 additions and 35 deletions
  1. 10 10
      README.md
  2. 4 3
      config/app.lua
  3. 3 2
      scratch.lua
  4. 8 3
      src/core.lua
  5. 3 3
      src/html_generator.lua
  6. 9 14
      src/submission.lua

+ 10 - 10
README.md

@@ -42,10 +42,10 @@ contribute to many decentralized projects that are highly efficient, small,
 representing periferal cultures, and most importantly, that are at much higher
 representing periferal cultures, and most importantly, that are at much higher
 risk of loss than large institutions'"?
 risk of loss than large institutions'"?
 
 
-Both: this software has been conceived with the experience of large-scale
-repositories as the background to decide what works and what doesn't, what is
-necessary and what is superfluous, and what catalogers and archivists need to
-do their job.
+The answer was: both. This software has been conceived with the experience of
+large-scale repositories as the background to decide what works and what
+doesn't, what is necessary and what is superfluous, and what catalogers and
+archivists need to do their job.
 
 
 It is not inconceivable that if many Pocket Archives were to sprout all over
 It is not inconceivable that if many Pocket Archives were to sprout all over
 the place one day, they could be periodically harvested, linked together, and
 the place one day, they could be periodically harvested, linked together, and
@@ -100,18 +100,18 @@ they can be found later.
 
 
 A submission is directed by a *laundry list*, which is a spreadsheet listing
 A submission is directed by a *laundry list*, which is a spreadsheet listing
 all the resources (both opaque and descriptive) to be created, and the metadata
 all the resources (both opaque and descriptive) to be created, and the metadata
-assigned to them. The laundry list, formatted as a CSV (comma-separated value)
+assigned to them. The laundry list, formatted as a CSV (comma-separated values)
 file, can be edited by several free and open source applications, such as
 file, can be edited by several free and open source applications, such as
-LibreOffice. For repetitive, high-volume submissions, templates can be set to
-facilitate filling in metadata fields. An [example submission
-](test/sample_submission/postcard-bag/data/), which includes a laundry list, is
-available.
+LibreOffice or Google Sheets. For repetitive, high-volume submissions,
+templates can be set to facilitate filling in metadata fields. An [example
+submission ](test/sample_submission/postcard-bag/data/), which includes a
+laundry list, is available.
 
 
 Using spreadsheets is for most users much faster and intuitive than clicking
 Using spreadsheets is for most users much faster and intuitive than clicking
 around an alien user interface filled with icons and terms that one has never
 around an alien user interface filled with icons and terms that one has never
 seen before.
 seen before.
 
 
-Detailed instructions on how to write a laundry list are under the 
+Detailed instructions on how to write a laundry list are under the
 [submission documentation](doc/submission.md).
 [submission documentation](doc/submission.md).
 
 
 ### Metadata & content model
 ### Metadata & content model

+ 4 - 3
config/app.lua

@@ -33,9 +33,9 @@ return {
     },
     },
     fs = {
     fs = {
         -- Base path to write opaque resources.
         -- Base path to write opaque resources.
-        ores_path = plpath.join(ROOT, "data/ores"),
+        ores_path = os.getenv("PKAR_ORES") or plpath.join(ROOT, "data/ores"),
         -- Base path of LSUP store for descriptive resources (RDF).
         -- Base path of LSUP store for descriptive resources (RDF).
-        dres_path = plpath.join(ROOT, "data/dres"),
+        dres_path = os.getenv("PKAR_DRES") or plpath.join(ROOT, "data/dres"),
 
 
         -- How many bytes to read when handling files. Adjust to memory
         -- How many bytes to read when handling files. Adjust to memory
         -- availability.
         -- availability.
@@ -44,10 +44,11 @@ return {
 
 
     -- Namespace prefixes to populate the Pocket Archive NS map.
     -- Namespace prefixes to populate the Pocket Archive NS map.
     namespace = {
     namespace = {
+        b2 = "urn:blake2:",
         dc = "http://purl.org/dc/terms/",
         dc = "http://purl.org/dc/terms/",
         foaf = "http://xmlns.com/foaf/0.1/",
         foaf = "http://xmlns.com/foaf/0.1/",
-        pas = "http://id.pkar.knowledgetx.com/schema#",
         par = "urn:pkar:resource/",
         par = "urn:pkar:resource/",
+        pas = "http://id.pkar.knowledgetx.com/schema#",
         premis = "http://id.loc.gov/vocabulary/preservation/",
         premis = "http://id.loc.gov/vocabulary/preservation/",
         rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
         rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
         rdfs = "http://www.w3.org/2000/01/rdf-schema#",
         rdfs = "http://www.w3.org/2000/01/rdf-schema#",

+ 3 - 2
scratch.lua

@@ -1,4 +1,5 @@
 local pp = require "pl.pretty"
 local pp = require "pl.pretty"
+local dir = require "pl.dir"
 
 
 local graph = require "volksdata.graph"
 local graph = require "volksdata.graph"
 local store = require "volksdata.store"
 local store = require "volksdata.store"
@@ -10,7 +11,7 @@ local hgen = require "pocket_archive.html_generator"
 
 
 
 
 ---[[
 ---[[
-local st = store.new(store.MDB, pkar.store_id, true)  -- delete prev archive
+pkar.init(true)
 
 
 sip = sub.generate_sip(
 sip = sub.generate_sip(
     "test/sample_submission/postcard-bag/data/pkar_submission.csv")
     "test/sample_submission/postcard-bag/data/pkar_submission.csv")
@@ -18,4 +19,4 @@ sip = sub.generate_sip(
 sub.deposit(sip)
 sub.deposit(sip)
 --]]
 --]]
 
 
-html = hgen.generate_site()
+--html = hgen.generate_site()

+ 8 - 3
src/core.lua

@@ -9,9 +9,9 @@ local nsm = require "volksdata.namespace"
 local fpath = debug.getinfo(1, "S").source:sub(2)
 local fpath = debug.getinfo(1, "S").source:sub(2)
 local root_path = path.dirname(path.dirname(fpath))
 local root_path = path.dirname(path.dirname(fpath))
 local config_path = os.getenv("PKAR_CONFIG_DIR") or
 local config_path = os.getenv("PKAR_CONFIG_DIR") or
-        plpath.join(root_path .. "/config")
+        path.join(root_path .. "/config")
 
 
-local config = dofile(plpath.join(config_path, "app.lua"))
+local config = dofile(path.join(config_path, "app.lua"))
 local store_id = "file://" .. (os.getenv("PKAR_BASE") or config.fs.dres_path)
 local store_id = "file://" .. (os.getenv("PKAR_BASE") or config.fs.dres_path)
 
 
 for pfx, ns in pairs(config.namespace) do nsm.add(pfx, ns) end
 for pfx, ns in pairs(config.namespace) do nsm.add(pfx, ns) end
@@ -24,7 +24,6 @@ local M = {
 
 
     default_title = "Pocket Archive",
     default_title = "Pocket Archive",
     store_id = store_id,
     store_id = store_id,
-    store = store.new(store.MDB, store_id),
 
 
     --Logger config.
     --Logger config.
     logger = require "sllog":init{
     logger = require "sllog":init{
@@ -95,6 +94,12 @@ M.gen_pairtree = function (pfx, id_str, ext, no_create)
 end
 end
 
 
 
 
+-- Initialize the store. `clear` wipes all data. YOU HAVE BEEN WARNED!
+M.init = function(clear)
+    M.store = store.new(store.MDB, store_id, clear)
+end
+
+
 --[[
 --[[
     Escape strings for use in gsub patterns.
     Escape strings for use in gsub patterns.
 --]]
 --]]

+ 3 - 3
src/html_generator.lua

@@ -353,11 +353,11 @@ end
 
 
 
 
 M.generate_site = function()
 M.generate_site = function()
-    dir.rmtree(M.res_dir)
+    if plpath.isdir(M.res_dir) then dir.rmtree(M.res_dir) end
     dir.makepath(M.res_dir)
     dir.makepath(M.res_dir)
-    dir.rmtree(M.asset_dir)
+    if plpath.isdir(M.asset_dir) then dir.rmtree(M.asset_dir) end
     dir.makepath(M.asset_dir)
     dir.makepath(M.asset_dir)
-    dir.rmtree(M.media_dir)
+    if plpath.isdir(M.media_dir) then dir.rmtree(M.media_dir) end
     dir.makepath(plpath.join(M.media_dir, "tn"))
     dir.makepath(plpath.join(M.media_dir, "tn"))
 
 
     assert(M.generate_resources())
     assert(M.generate_resources())

+ 9 - 14
src/submission.lua

@@ -206,8 +206,9 @@ M.rsrc_to_graph = function(rsrc)
     logger:info("Updating resource md: ", pp.write(rsrc))
     logger:info("Updating resource md: ", pp.write(rsrc))
 
 
     local s = term.new_iriref_ns(rsrc.id)
     local s = term.new_iriref_ns(rsrc.id)
-    triples = {}
+    local gr = graph.new(nil)
 
 
+    it = gr:add_init()
     for k, v in pairs(rsrc) do
     for k, v in pairs(rsrc) do
         -- id is the subject, it won't be an attribute.
         -- id is the subject, it won't be an attribute.
         if k == "id" then goto skip end
         if k == "id" then goto skip end
@@ -232,24 +233,14 @@ M.rsrc_to_graph = function(rsrc)
             elseif datatype == "ext_resource" then
             elseif datatype == "ext_resource" then
                 o = term.new_iriref(vv)
                 o = term.new_iriref(vv)
             else o = term.new_lit(vv, rdf_type) end
             else o = term.new_lit(vv, rdf_type) end
-            table.insert(triples, triple.new(s, p, o))
+            it:add_iter(triple.new(s, p, o))
         end
         end
         ::skip::
         ::skip::
     end
     end
     for i, m in ipairs(rmod.lineage) do
     for i, m in ipairs(rmod.lineage) do
-        table.insert(
-            triples, triple.new(s, pkar.RDF_TYPE, term.new_iriref_ns(m)))
+        it:add_iter(triple.new(s, pkar.RDF_TYPE, term.new_iriref_ns(m)))
     end
     end
-
-    local gr = graph.new(nil)
-    -- This is a full replacement.
-    --require "debugger"()
-    logger:info("Removing triples.")
-    gr:remove(s)
-    logger:info("Adding triples.")
-    -- TODO implement volksdata_lua fn to add a single triple and add triples
-    -- in the previous loop.
-    gr:add(triples)
+    it:add_done()
 
 
     return gr, s
     return gr, s
 end
 end
@@ -269,6 +260,10 @@ M.store_updates = function(tmp_gr, s)
 
 
     local stored_gr = graph.new(pkar.store, term.DEFAULT_CTX)
     local stored_gr = graph.new(pkar.store, term.DEFAULT_CTX)
 
 
+    logger:debug("Removing stored triples.")
+    stored_gr:remove(s)
+
+    logger:info("Storing triples.")
     return tmp_gr:copy(stored_gr)
     return tmp_gr:copy(stored_gr)
 end
 end