Parcourir la source

Better init function.

scossu il y a 1 jour
Parent
commit
2dd3d704f4
4 fichiers modifiés avec 44 ajouts et 12 suppressions
  1. 13 3
      src/generator.lua
  2. 6 0
      src/repo.lua
  3. 15 2
      src/submission.lua
  4. 10 7
      src/util/pkar.lua

+ 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
 }