summaryrefslogtreecommitdiffstats
path: root/app/cfgfile-model.lua
diff options
context:
space:
mode:
authorAlexander Poslavsky <alexander.poslavsky@gmail.com>2007-11-01 13:09:27 +0000
committerAlexander Poslavsky <alexander.poslavsky@gmail.com>2007-11-01 13:09:27 +0000
commit8de481d12806a87d77795291e4a560c935134d19 (patch)
treeeca419db72459f80e00837e0bbb842f416386355 /app/cfgfile-model.lua
parent55a89d64a17314bcf4b8c0eabf5b05deb9fd69ae (diff)
downloadacf-core-8de481d12806a87d77795291e4a560c935134d19.tar.bz2
acf-core-8de481d12806a87d77795291e4a560c935134d19.tar.xz
test for general etc editing
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@241 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'app/cfgfile-model.lua')
-rw-r--r--app/cfgfile-model.lua85
1 files changed, 85 insertions, 0 deletions
diff --git a/app/cfgfile-model.lua b/app/cfgfile-model.lua
new file mode 100644
index 0000000..788ebc2
--- /dev/null
+++ b/app/cfgfile-model.lua
@@ -0,0 +1,85 @@
+module (..., package.seeall)
+
+require "fs"
+
+
+--TODO this should be somehow figureoutable from acf info
+local cfgdir = "/usr/share/acf/app/cfgfile"
+
+--TODO, in fs actually, find should use coroutines instead of reading
+--all in table
+
+local files = nil
+
+--TODO might on demand load only part of config that is needed for this app
+--but then TODO need to make persistent item ids
+local function loadCfg()
+ if files ~= nil then return end
+ files = {}
+ for fname in fs.find(".*%.cfg", cfgdir) do
+ print ("LOADING FILE ", fname)
+ f = io.open(fname, 'r')
+ if f then
+ s = f:read("*a")
+ f:close()
+ if s then
+ c = loadstring("return ({\n" .. s .. "\n})")
+ if c then
+ for i,v in ipairs(c()) do
+ files[#files + 1] = v
+ end
+ end
+ end
+ end
+ end
+end
+
+function list(self, app)
+ loadCfg()
+ ret = {}
+ for k,v in pairs(files) do
+ if v.app == app then
+ ret[#ret+1] = {
+ id=k,
+ app=v.app,
+ section=v.section,
+ name=v.name,
+ descr=v.descr,
+ }
+ end
+ end
+ return ret
+end
+
+function get(self, id)
+ loadCfg()
+ local item = files[id]
+ if not item then return false end
+ local f = io.open(item.filename, "r")
+ local n = ""
+ if f then
+ n = f:read("*a")
+ f:close()
+ end
+ return true, {
+ id=cfe{ value=tostring(id) },
+ content=cfe{ value=n, type="longtext" },
+ name=cfe{ value=item.name }
+ }
+end
+
+
+function set(self, id, data)
+ loadCfg()
+ local item = files[id]
+ if not item then return false, date end
+ local f = io.open(item.filename, "w")
+ if f then
+ f:write(data.content.value)
+ f:close()
+ end
+ -- TODO update processing
+ return get(self, id)
+end
+
+