summaryrefslogtreecommitdiffstats
path: root/lbu-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-10-18 19:45:13 +0000
committerTed Trask <ttrask01@yahoo.com>2013-10-18 19:45:13 +0000
commitbbfda88e89f236aafbcf39640aebd5a5c14c64aa (patch)
tree3e5ae38f62463bf92a5764c899bbfc462d2e428f /lbu-model.lua
parent65d76efca6fdc54b449ea396d70faae4d990b05a (diff)
downloadacf-alpine-conf-bbfda88e89f236aafbcf39640aebd5a5c14c64aa.tar.bz2
acf-alpine-conf-bbfda88e89f236aafbcf39640aebd5a5c14c64aa.tar.xz
Remove all calls to 'module' in preparation for move to Lua 5.2
Use mymodule parameter for module definition. This was also helpful in revealing places where the code relied on the global environment.
Diffstat (limited to 'lbu-model.lua')
-rw-r--r--lbu-model.lua44
1 files changed, 23 insertions, 21 deletions
diff --git a/lbu-model.lua b/lbu-model.lua
index 7c58b01..6116a9d 100644
--- a/lbu-model.lua
+++ b/lbu-model.lua
@@ -1,4 +1,4 @@
-module (..., package.seeall)
+local mymodule = {}
-- Load libraries
posix = require("posix")
@@ -141,7 +141,7 @@ local function validatefilecontent (filedetails)
local success = true
local clientdata = clientdata or self.clientdata or {}
clientdata.configcontents = filedetails.value.filecontent.value
- local config = getconfig(nil, clientdata)
+ local config = mymodule.getconfig(nil, clientdata)
local errors = {}
for name,value in pairs(config.value) do
if value.errtxt then
@@ -159,7 +159,7 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
-function getstatus ()
+function mymodule.getstatus ()
local status = {}
status["version"] = cfe({
value=get_version(),
@@ -168,12 +168,12 @@ function getstatus ()
status["committed"] = cfe({
type="boolean",
- value=(#list().value==0),
+ value=(#mymodule.list().value==0),
descr=descrtxt,
label="Program status",
})
- local config = getconfig()
+ local config = mymodule.getconfig()
status["LBU_MEDIA"] = config.value.LBU_MEDIA
if (config.value.ENCRYPTION.value) then
status["DEFAULT_CIPHER"] = config.value.DEFAULT_CIPHER
@@ -182,7 +182,7 @@ function getstatus ()
return cfe({ type="group", value=status, label="LBU Status" })
end
-function list()
+function mymodule.list()
local ret = {}
local lbuStatus = getLbuStatus()
for k,v in pairs(lbuStatus) do
@@ -192,7 +192,7 @@ function list()
return cfe({ type="structure", value=ret, label="List of changes" })
end
-function getconfig (self, clientdata)
+function mymodule.getconfig (self, clientdata)
local clientdata = clientdata or {}
local config = {}
local configopts = {}
@@ -237,7 +237,7 @@ function getconfig (self, clientdata)
return retval
end
-function setconfig (self, config)
+function mymodule.setconfig (self, config)
validateconfig(config)
if not config.errtxt then
@@ -261,7 +261,7 @@ function setconfig (self, config)
return config
end
-function getincluded ()
+function mymodule.getincluded ()
local included = cfe({
label="Included item(s)",
type="longtext",
@@ -276,7 +276,7 @@ function getincluded ()
return cfe({ type="group", value={included = included} })
end
-function setincluded (self, included)
+function mymodule.setincluded (self, included)
local files = validatefilelist(included.value.included)
if not included.value.included.errtxt then
local current = format.string_to_table(modelfunctions.run_executable({"lbu", "include", "-l"}), "\n")
@@ -294,7 +294,7 @@ function setincluded (self, included)
return included
end
-function getexcluded ()
+function mymodule.getexcluded ()
local excluded = cfe({
label="Excluded item(s)",
type="longtext",
@@ -309,7 +309,7 @@ function getexcluded ()
return cfe({ type="group", value={excluded = excluded} })
end
-function setexcluded (self, excluded)
+function mymodule.setexcluded (self, excluded)
local files = validatefilelist(excluded.value.excluded)
if not excluded.value.excluded.errtxt then
local current = format.string_to_table(modelfunctions.run_executable({"lbu", "exclude", "-l"}), "\n")
@@ -327,21 +327,21 @@ function setexcluded (self, excluded)
return excluded
end
-function get_filedetails()
+function mymodule.get_filedetails()
return modelfunctions.getfiledetails(configfile)
end
-function set_filedetails(self, filedetails)
+function mymodule.set_filedetails(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, {configfile}, validatefilecontent)
end
-function getcommit()
+function mymodule.getcommit()
local simulate = cfe({ type="boolean", value=false, label="Simulate a commit" })
local delete = cfe({ type="boolean", value=false, label="Remove existing overlays on commit" })
return cfe({ type="group", value={simulate=simulate, delete=delete}, label="Commit changes" })
end
-function commit(self, input)
+function mymodule.commit(self, input)
if input.value.simulate.value and input.value.delete.value then
input.errtxt = "Cannot delete overlays when simulating"
else
@@ -354,7 +354,7 @@ function commit(self, input)
return input
end
-function getbackupfiles()
+function mymodule.getbackupfiles()
local files = {}
local content = modelfunctions.run_executable({"lbu", "lb"})
if not string.match(content, "usage: lbu") then
@@ -365,15 +365,15 @@ function getbackupfiles()
return cfe({ type="list", value=files, label="Backup archive list"})
end
-function get_selectbackup(self, clientdata)
+function mymodule.get_selectbackup(self, clientdata)
local result = {}
result.backup = cfe({ type="select", value=clientdata.backup or "", label="Backup" })
- local files = getbackupfiles()
+ local files = mymodule.getbackupfiles()
result.backup.option = files.value
return cfe({ type="group", value=result, label="Revert to Backup" })
end
-function selectbackupfile(self, backuprequest)
+function mymodule.selectbackupfile(self, backuprequest)
local success = modelfunctions.validate_select(backuprequest.value.backup)
if success then
backuprequest.descr, backuprequest.errtxt = modelfunctions.run_executable({"lbu", "revert", backuprequest.value.backup.value})
@@ -386,7 +386,7 @@ function selectbackupfile(self, backuprequest)
return backuprequest
end
-function getpackage()
+function mymodule.getpackage()
-- create a temporary directory to store the file
session = require("session")
local tmp = "/tmp/"..session.random_hash(10)
@@ -409,3 +409,5 @@ function getpackage()
return package
end
+
+return mymodule