2 Commits 28f8e5e536 ... 2dd3d704f4

Autor SHA1 Mensaje Fecha
  scossu 2dd3d704f4 Better init function. hace 1 día
  scossu 9e84300dc0 Use non-deterministic rando by default. hace 1 día
Se han modificado 7 ficheros con 71 adiciones y 21 borrados
  1. 12 3
      README.md
  2. 14 2
      config/app.lua
  3. 1 4
      src/core.lua
  4. 13 3
      src/generator.lua
  5. 6 0
      src/repo.lua
  6. 15 2
      src/submission.lua
  7. 10 7
      src/util/pkar.lua

+ 12 - 3
README.md

@@ -84,7 +84,7 @@ stage.
 
 ```
 # Note: tested on Archlinux. Other distros (especially Alpine) may need tweaks.
-eval $(luarocks path)  # for local install
+eval $(luarocks path)
 luarocks install --local debugger  # Not in dependencies file but temporarily required
 git clone --recurse-submodules https://git.knowledgetx.com/scossu/volksdata_lua.git
 cd volksdata_lua
@@ -94,7 +94,16 @@ cd ../
 git clone --recurse-submodules https://git.knowledgetx.com/scossu/pocket_archive.git
 cd pocket_archive
 luarocks build --local
-luarocks path >> ~/.bashrc  # or whatever shell init script you use at login
+# Add Luarocks paths to your login script
+luarocks path >> ~/.bashrc
+# Penlight.clonetree is not working properly. A pull request is in progress:
+# https://github.com/lunarmodules/Penlight/pull/496
+# In the meantime, clone the fork and install from the local repo:
+cd ../
+git clone https://github.com/scossu/Penlight.git
+cd Penlight
+luarocks build --local
+cd ../pocket_archive
 ```
 
 ### Run demo submission
@@ -126,7 +135,7 @@ If you don't have a configured web server yet, the provided `darkhttpd` will
 work in a pinch:
 
 ```
-cd ext/darkhttpd/
+cd ext/darkhttpd/  # Archlinux: sudo pacman -S darkhttpd
 make
 cd -
 ```

+ 14 - 2
config/app.lua

@@ -16,8 +16,20 @@ return {
     id = {
         -- Length in ASCII characters of system-generated IDs.
         len = 16,
-        -- Two seeds for the random ID generator.
-        seed = {256, 512},
+
+        --[[ Seed for the random ID generator.
+
+        Set this to an arbitrary integer in a test environment, so that
+        resource IDs will be generated with a consistent pattern for each run
+        (not when using pkar_watch, though). Note that each call to e.g.
+        `pkar deposit` will generate IDs starting from the same seed and will
+        overwrite resources from a previous deposit.
+
+        If nil, os.time() will be used, which generates always different random
+        IDs. This is necessary in a real-world application to avoid the above
+        mentioned overwriting.
+        ]]
+        seed = nil,
     },
     md = {
         -- Single-valued fields. TODO rely on content model cardinality.

+ 1 - 4
src/core.lua

@@ -115,10 +115,7 @@ setmetatable (M, mt)
 
 
 -- Initialize random ID generator.
--- TODO This must be set to completely random or use another random generator
--- so that resource IDs are not repeated for each process. For testing it's
--- convenient that resource IDs have always the same pattern.
-math.randomseed(M.config.id.seed[1], M.config.id.seed[2])
+math.randomseed(M.config.id.seed or os.time())
 
 
 return M

+ 13 - 3
src/generator.lua

@@ -703,15 +703,20 @@ M.generate_homepage = function()
 end
 
 
-M.generate_site = function()
+M.reset_site = function()
     -- Reset target folders.
     -- TODO for larger sites, a selective update should be implemented by
     -- comparing RDF resource timestamps with HTML page timestamps. Post-MVP.
     if path.isdir(pkar.config.htmlgen.out_dir) then
-        dir.rmtree(pkar.config.htmlgen.out_dir) end
+        logger:warn("Removing existing web site.")
+        dir.rmtree(pkar.config.htmlgen.out_dir)
+    end
 
     -- Recreate asset dir.
-    if path.isdir(M.asset_dir) then dir.rmtree(M.asset_dir) end
+    if path.isdir(M.asset_dir) then
+        logger:warn("Removing existing web assets.")
+        dir.rmtree(M.asset_dir)
+    end
     dir.makepath(M.asset_dir)
 
     -- Copy static assets.
@@ -719,6 +724,11 @@ M.generate_site = function()
         datafile.path("templates/assets"),
         M.asset_dir, dir.copyfile)
     )
+end
+
+
+M.generate_site = function(keep)
+    if not keep then M.reset_site() end
 
     -- Clear local search index keys.
     idx_keys = {

+ 6 - 0
src/repo.lua

@@ -8,6 +8,7 @@ local nsm = require "volksdata.namespace"
 local term = require "volksdata.term"
 local triple = require "volksdata.triple"
 local graph = require "volksdata.graph"
+local store = require "volksdata.store"
 
 local pkar = require "pocket_archive"
 local model = require "pocket_archive.model"
@@ -21,6 +22,11 @@ local NT = {}
 local M = {
     -- Default store graph to search all triples.
     gr = graph.new(pkar.store, term.DEFAULT_CTX),
+
+    reset_store = function()
+        logger:warn("Removing existing Linked Data store.")
+        return store.new(store.MDB, pkar.store_id, true)
+    end,
 }
 
 

+ 15 - 2
src/submission.lua

@@ -224,7 +224,12 @@ local function rsrc_to_graph(rsrc)
             elseif pconf.type == "resource" then
                 if not vv:match("^[a-z]*:") then
                     -- Convert local path to URIs.
-                    v[i] = assert(path_to_uri[vv]) end
+                    v[i] = path_to_uri[vv]
+                    if not v[i] then error(
+                        ("Not a valid path: %s for property: %s on res: %s")
+                        :format(vv, prop, rsrc.id))
+                    end
+                end
                 o = term.new_iriref_ns(v[i])
             elseif pconf.type == "ext_resource" then
                 o = term.new_iriref(vv)
@@ -288,7 +293,15 @@ end
 
 
 -- Submission module.
-local M = {}
+local M = {
+    reset_ores = function()
+        if path.isdir(pkar.config.fs.ores_path) then
+            logger:warn("Removing existing opaque resource store.")
+            dir.rmtree(pkar.config.fs.ores_path)
+        end
+        dir.makepath(pkar.config.fs.ores_path)
+    end,
+}
 
 
 M.deposit = function(ll_path, cleanup)

+ 10 - 7
src/util/pkar.lua

@@ -21,14 +21,17 @@ cli.locale "en_US"  -- TODO set with multilingual support.
 init = cli.command {
     "Initialize a new Pocket Archive store.",
 
-    cli.flag "wipe" {
-        "Wipe all preexisting data.",
-        type = cli.boolean,
-    },
-
     function(args)
-        if args.wipe then _ = pkar.reset_store
-        else _ = pkar.store end
+        io.write("WARNING! This will WIPE all your archive and web data!\n")
+        io.write("Enter 'yes' if you know what you are doing: ")
+        local a = io.read()
+        if a == "yes" then
+            io.write("Alright, you asked for it.\n")
+            repo.reset_store()
+            sub.reset_ores()
+            gen.reset_site()
+        else io.write("Chicken out.\n")
+        end
     end
 }