Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0725e66261 | ||
|
3824399f33 | ||
|
1f88981112 | ||
|
fcf0725534 | ||
|
3d8e4fb947 |
@ -12,24 +12,27 @@ dofile (localdir .. "/interactions/interactions.lua")
|
||||
|
||||
--modules
|
||||
--TODO make this automatic and directory-based
|
||||
dofile (localdir .. "/modules/add_child_org_consent.lua")
|
||||
dofile (localdir .. "/modules/add_child_org.lua")
|
||||
dofile (localdir .. "/modules/change_modules.lua")
|
||||
dofile (localdir .. "/modules/change_policy.lua")
|
||||
dofile (localdir .. "/modules/consent.lua")
|
||||
dofile (localdir .. "/modules/create_token.lua")
|
||||
dofile (localdir .. "/modules/defer_consent.lua")
|
||||
dofile (localdir .. "/modules/display_policies.lua")
|
||||
dofile (localdir .. "/modules/display_processes.lua")
|
||||
dofile (localdir .. "/modules/join_org_consent.lua")
|
||||
dofile (localdir .. "/modules/leave_org.lua")
|
||||
dofile (localdir .. "/modules/message_org.lua")
|
||||
dofile (localdir .. "/modules/randomizer.lua")
|
||||
dofile (localdir .. "/modules/remove_child_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_member_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_org_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_org.lua")
|
||||
dofile (localdir .. "/modules/remove_process.lua")
|
||||
dofile (localdir .. "/modules/rename_org_consent.lua")
|
||||
dofile (localdir .. "/modules/send_token.lua")
|
||||
dofile (localdir .. "/modules/tokenomics.lua")
|
||||
dofile (localdir .. "/storage/store-modules.lua")
|
||||
modpol.load_modules(localdir .. "/modules")
|
||||
|
||||
-- dofile (localdir .. "/modules/add_child_org_consent.lua")
|
||||
-- dofile (localdir .. "/modules/add_child_org.lua")
|
||||
-- dofile (localdir .. "/modules/change_modules.lua")
|
||||
-- dofile (localdir .. "/modules/change_policy.lua")
|
||||
-- dofile (localdir .. "/modules/consent.lua")
|
||||
-- dofile (localdir .. "/modules/create_token.lua")
|
||||
-- dofile (localdir .. "/modules/defer_consent.lua")
|
||||
-- dofile (localdir .. "/modules/display_policies.lua")
|
||||
-- dofile (localdir .. "/modules/display_processes.lua")
|
||||
-- dofile (localdir .. "/modules/join_org_consent.lua")
|
||||
-- dofile (localdir .. "/modules/leave_org.lua")
|
||||
-- dofile (localdir .. "/modules/message_org.lua")
|
||||
-- dofile (localdir .. "/modules/randomizer.lua")
|
||||
-- dofile (localdir .. "/modules/remove_child_consent.lua")
|
||||
-- dofile (localdir .. "/modules/remove_member_consent.lua")
|
||||
-- dofile (localdir .. "/modules/remove_org_consent.lua")
|
||||
-- dofile (localdir .. "/modules/remove_org.lua")
|
||||
-- dofile (localdir .. "/modules/remove_process.lua")
|
||||
-- dofile (localdir .. "/modules/rename_org_consent.lua")
|
||||
-- dofile (localdir .. "/modules/send_token.lua")
|
||||
-- dofile (localdir .. "/modules/tokenomics.lua")
|
||||
|
@ -55,7 +55,7 @@ dofile (topdir .. "/util/misc.lua")
|
||||
-- Select a storage method
|
||||
-- -- preferably, declare this in the init.lua that calls modpol.lua This is the default.
|
||||
-- Works with CLI:
|
||||
modpol.storage_file_path = modpol.storage_file_path or topdir .. "/storage/storage-local.lua"
|
||||
modpol.storage_file_path = modpol.storage_file_path or topdir .. "/storage/unix-storage.lua"
|
||||
-- Works with Minetest 5:
|
||||
--modpol.storage_file_path = modpol.storage_file_path or topdir .. "/storage/storage-mod_storage.lua")
|
||||
|
||||
|
3
modpol_core/modules/ignore.txt
Normal file
3
modpol_core/modules/ignore.txt
Normal file
@ -0,0 +1,3 @@
|
||||
change_modules-dropdown.lua
|
||||
join_org.lua
|
||||
template.lua
|
23
modpol_core/storage/store-modules-legacy.lua
Normal file
23
modpol_core/storage/store-modules-legacy.lua
Normal file
@ -0,0 +1,23 @@
|
||||
modpol.load_modules = function(path)
|
||||
dofile (path .. "/add_child_org_consent.lua")
|
||||
dofile (path .. "/add_child_org.lua")
|
||||
dofile (path .. "/change_modules.lua")
|
||||
dofile (path .. "/change_policy.lua")
|
||||
dofile (path .. "/consent.lua")
|
||||
dofile (path .. "/create_token.lua")
|
||||
dofile (path .. "/defer_consent.lua")
|
||||
dofile (path .. "/display_policies.lua")
|
||||
dofile (path .. "/display_processes.lua")
|
||||
dofile (path .. "/join_org_consent.lua")
|
||||
dofile (path .. "/leave_org.lua")
|
||||
dofile (path .. "/message_org.lua")
|
||||
dofile (path .. "/randomizer.lua")
|
||||
dofile (path .. "/remove_child_consent.lua")
|
||||
dofile (path .. "/remove_member_consent.lua")
|
||||
dofile (path .. "/remove_org_consent.lua")
|
||||
dofile (path .. "/remove_org.lua")
|
||||
dofile (path .. "/remove_process.lua")
|
||||
dofile (path .. "/rename_org_consent.lua")
|
||||
dofile (path .. "/send_token.lua")
|
||||
dofile (path .. "/tokenomics.lua")
|
||||
end
|
59
modpol_core/storage/store-modules.lua
Normal file
59
modpol_core/storage/store-modules.lua
Normal file
@ -0,0 +1,59 @@
|
||||
local lfs
|
||||
-- checks if lua file system is installed
|
||||
local using_lfs = pcall(function() lfs = require "lfs" end)
|
||||
|
||||
-- switches to legacy module loading if lfs is not available
|
||||
if using_lfs then
|
||||
|
||||
-- loads file names to ignore into a table
|
||||
function fetch_ignores(module_path)
|
||||
local ignore_list = {}
|
||||
-- checks if ignore.txt exists
|
||||
local f_test = io.open(module_path .. "/ignore.txt", "r")
|
||||
if not f_test then return {} end
|
||||
|
||||
-- puts each line of ignore.txt into the table
|
||||
local f = io.lines(module_path .. "/ignore.txt")
|
||||
for line in f do
|
||||
table.insert(ignore_list, line)
|
||||
end
|
||||
return ignore_list
|
||||
end
|
||||
|
||||
-- checks if a string is in a list
|
||||
function check_list(ignore_list, name)
|
||||
for i, v in ipairs(ignore_list) do
|
||||
if v == name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
modpol.load_modules = function(module_path)
|
||||
local loaded = 0
|
||||
local ignored = 0
|
||||
local ignores = fetch_ignores(module_path)
|
||||
for file in lfs.dir(module_path) do
|
||||
if file == "." or file == ".." then
|
||||
-- ignoring current and parent directory
|
||||
else
|
||||
-- only looks for .lua files
|
||||
if string.sub(file, -4, -1) == ".lua" then
|
||||
|
||||
-- doesn't load files in the ignore.txt
|
||||
if check_list(ignores, file) then
|
||||
ignored = ignored + 1
|
||||
else
|
||||
dofile(module_path .. "/" .. file)
|
||||
loaded = loaded + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
print(loaded .. " modules loaded (" .. ignored .. " ignored)")
|
||||
end
|
||||
|
||||
else
|
||||
dofile (modpol.topdir .. "/storage/store-modules-legacy.lua")
|
||||
end
|
109
modpol_core/storage/unix-storage.lua
Normal file
109
modpol_core/storage/unix-storage.lua
Normal file
@ -0,0 +1,109 @@
|
||||
-- ===================================================================
|
||||
-- /unix-storage.lua
|
||||
-- Persistent storage in /data using Serpent Serializer
|
||||
-- Unix systems only
|
||||
|
||||
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")
|
||||
|
||||
modpol.serpent = {}
|
||||
dofile (modpol.topdir .. "/util/serpent/serpent.lua")
|
||||
|
||||
-- ===================================================================
|
||||
|
||||
local write_file = function(path, data)
|
||||
local file, err
|
||||
file, err = io.open(path, "w")
|
||||
if err then print(err) os.exit(1) end
|
||||
file:write(data)
|
||||
file:close()
|
||||
end
|
||||
|
||||
local read_file = function(path)
|
||||
local file, err
|
||||
file, err = io.open(path, "r")
|
||||
if err then return nil end
|
||||
local data = file:read()
|
||||
file:close()
|
||||
return data
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
|
||||
local store_ledger = function(verbose)
|
||||
local serialized_ledger = modpol.serpent.dump(modpol.ledger)
|
||||
write_file(modpol.file_ledger, serialized_ledger)
|
||||
|
||||
local count = 0
|
||||
for _ in pairs(modpol.ledger) do count = count + 1 end
|
||||
|
||||
if verbose then modpol.ocutil.log(count .. " ledger entries stored to disk")
|
||||
end
|
||||
end
|
||||
|
||||
local store_orgs = function(verbose)
|
||||
local serialized_orgs = modpol.serpent.dump(modpol.orgs)
|
||||
write_file(modpol.file_orgs, serialized_orgs)
|
||||
|
||||
local count = 0
|
||||
for _ in pairs(modpol.orgs.array) do count = count + 1 end
|
||||
|
||||
if verbose then modpol.ocutil.log(count .. " orgs stored to disk")
|
||||
end
|
||||
end
|
||||
|
||||
modpol.store_data = function(verbose)
|
||||
store_ledger(verbose)
|
||||
store_orgs(verbose)
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
|
||||
local load_ledger = function()
|
||||
local obj = read_file(modpol.file_ledger)
|
||||
if obj ~= nil then
|
||||
local func, err = load(obj)
|
||||
if err then
|
||||
modpol.ocutil.log("Error loading ledger data")
|
||||
os.exit(1)
|
||||
end
|
||||
modpol.ledger = func()
|
||||
|
||||
local count = 0
|
||||
for _ in pairs(modpol.ledger) do count = count + 1 end
|
||||
|
||||
modpol.ocutil.log(count .. " ledger entries loaded from disk")
|
||||
else
|
||||
modpol.ocutil.log("No stored ledger data found")
|
||||
end
|
||||
end
|
||||
|
||||
local load_orgs = function()
|
||||
local obj = read_file(modpol.file_orgs)
|
||||
if obj ~= nil then
|
||||
local func, err = load(obj)
|
||||
if err then
|
||||
modpol.ocutil.log("Error loading org data")
|
||||
os.exit(1)
|
||||
end
|
||||
modpol.orgs = func()
|
||||
|
||||
local count = 0
|
||||
for _ in pairs(modpol.orgs.array) do count = count + 1 end
|
||||
|
||||
modpol.ocutil.log(count .. " orgs loaded from disk")
|
||||
else
|
||||
modpol.ocutil.log("No stored orgs found")
|
||||
end
|
||||
end
|
||||
|
||||
modpol.load_storage = function()
|
||||
load_ledger()
|
||||
load_orgs()
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user