Change file structures so that the interior modpol folder IS the portable modpol.

Added documentation of how to pre-define the modpath and the storage file.
This commit is contained in:
MisterE123
2021-02-11 16:39:51 -05:00
parent 37463fc8cc
commit dc12ec50a9
13 changed files with 41 additions and 6 deletions

View File

@@ -0,0 +1,117 @@
-- ===================================================================
-- /storage-local.lua
-- Persistent storage in /data using Serpent Serializer
-- Unix systems only
-- ===================================================================
-- Set directories and filenames
modpol.datadir = modpol.topdir .. "/data"
modpol.file_ledger = modpol.datadir .. "/ledger.dat"
modpol.file_orgs = modpol.datadir .. "/orgs.dat"
os.execute ("mkdir -p " .. modpol.datadir)
modpol.ocutil.setlogdir (modpol.datadir)
modpol.ocutil.setlogname ("modpol.log")
-- ===================================================================
-- Set up the Serpent Serializer functions.
modpol.serpent = {}
dofile (modpol.topdir .. "/util/serpent/serpent.lua")
-- ===================================================================
-- This function stores "ledger" data to disk.
local store_ledger = function()
local ok = modpol.ocutil.file_write (modpol.file_ledger,
modpol.serpent.dump (modpol.ledger))
if ok ~= true then
modpol.ocutil.fatal_error ("store_data: ledger")
end
local nn = modpol.ocutil.table_length (modpol.ledger)
local str = "entries"
if nn == 1 then str = "entry" end
modpol.ocutil.log (nn .. " global ledger entries stored to disk")
end
-- ===================================================================
-- This function stores "orgs" data to disk.
local store_orgs = function()
local ok = modpol.ocutil.file_write (modpol.file_orgs,
modpol.serpent.dump (modpol.orgs))
if ok ~= true then
modpol.ocutil.fatal_error ("store_data: orgs")
end
local nn = modpol.ocutil.table_length (modpol.orgs)
local str = "entries"
if nn == 1 then str = "entry" end
modpol.ocutil.log (nn .. " orgs stored to disk")
end
-- ===================================================================
-- This function stores data to disk.
modpol.store_data = function()
store_ledger()
store_orgs()
end
-- ===================================================================
-- This function loads "ledger" data from disk.
local load_ledger = function()
local obj = modpol.ocutil.file_read (modpol.file_ledger )
if obj ~= nil then
local func, err = load (obj)
if err then
modpol.ocutil.fatal_error ("load_data: ledger" )
end
modpol.ledger = func()
local nn = modpol.ocutil.table_length (modpol.ledger)
local str = "entries"
if nn == 1 then str = "entry" end
modpol.ocutil.log (nn .. " global ledger entries loaded from disk")
else
modpol.ocutil.log ("No stored global ledger data found")
end
end
-- ===================================================================
-- This function loads "orgs" data from disk.
local load_orgs = function()
local obj = modpol.ocutil.file_read (modpol.file_orgs )
if obj ~= nil then
local func, err = load (obj)
if err then
modpol.ocutil.fatal_error ("load_data: orgs" )
end
modpol.orgs = func()
local nn = modpol.ocutil.table_length (modpol.orgs)
local str = "entries"
if nn == 1 then str = "entry" end
modpol.ocutil.log (nn .. " orgs loaded from disk")
else
modpol.ocutil.log ("No stored orgs data found")
end
end
-- ===================================================================
-- This function loads stored data from disk.
modpol.load_storage = function()
load_ledger()
load_orgs()
end
-- ===================================================================
-- End of file.