From b1092115af620b794a1ccc851374974d33e3cf6e Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 21 Oct 2013 00:26:40 +0000 Subject: 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. --- rrdtool-controller.lua | 36 +++++++++++++++++++----------------- rrdtool-model.lua | 38 ++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/rrdtool-controller.lua b/rrdtool-controller.lua index ae4a2a2..6070dcc 100644 --- a/rrdtool-controller.lua +++ b/rrdtool-controller.lua @@ -1,52 +1,52 @@ -module(..., package.seeall) +local mymodule = {} -default_action = "status" +mymodule.default_action = "status" -function status(self) +function mymodule.status(self) return self.model.getstatus() end -function expert(self) +function mymodule.expert(self) return self.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Saved") end -function listrrd(self) +function mymodule.listrrd(self) local configfiles = self.model.getrrdlist() return cfe({ type="list", value=configfiles.value, label="View/Edit RoundRobinDatabase (rrd) files" }) end -function createrrd(self) +function mymodule.createrrd(self) return self.handle_form(self, self.model.createnewrrd, function(self, value) - return self.model.savenewrrd(self, value, sessiondata.userinfo.userid) + return self.model.savenewrrd(self, value, self.sessiondata.userinfo.userid) end, self.clientdata, "Save", "Create new RRD", "File saved") end -function delete(self) - return self:redirect_to_referrer(self.model.remove_file(self, self.clientdata.filename, sessiondata.userinfo.userid)) +function mymodule.delete(self) + return self:redirect_to_referrer(self.model.remove_file(self, self.clientdata.filename, self.sessiondata.userinfo.userid)) end -function rrdinfo(self) - return self:redirect_to_referrer(self.model.rrd_info(self, self.clientdata.filename, sessiondata.userinfo.userid)) +function mymodule.rrdinfo(self) + return self:redirect_to_referrer(self.model.rrd_info(self, self.clientdata.filename, self.sessiondata.userinfo.userid)) end -function listgraphs(self) +function mymodule.listgraphs(self) return self.model.list_graphs() end -function viewgraph(self) +function mymodule.viewgraph(self) return self.model.view_graph(self, self.clientdata.group, self.clientdata.id) end -function listgraphcfg(self) +function mymodule.listgraphcfg(self) local configfiles = self.model.getgraphlist() return cfe({ type="list", value=configfiles.value, label="View/Edit graph files" }) end -function editgraphcfg(self) +function mymodule.editgraphcfg(self) config = self.handle_form(self, function() return self.model.getgraphfile(self.clientdata.filename) end, function(self, value) - return self.model.set_filedetails(self, value, sessiondata.userinfo.userid) + return self.model.set_filedetails(self, value, self.sessiondata.userinfo.userid) end, self.clientdata, "Save", "Edit Config File", "Config File Saved") if self.clientdata.linenumber and validator.is_integer(self.clientdata.linenumber) then @@ -55,4 +55,6 @@ function editgraphcfg(self) return config end -newgraphcfg = editgraphcfg +mymodule.newgraphcfg = mymodule.editgraphcfg + +return mymodule diff --git a/rrdtool-model.lua b/rrdtool-model.lua index 7b3895a..8f97738 100644 --- a/rrdtool-model.lua +++ b/rrdtool-model.lua @@ -1,4 +1,4 @@ -module(..., package.seeall) +local mymodule = {} -- Load libraries modelfunctions = require("modelfunctions") @@ -65,23 +65,23 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function getstatus() +function mymodule.getstatus() return modelfunctions.getstatus(nil, packagename, header .. " status") end -function getconfigfile() +function mymodule.getconfigfile() return modelfunctions.getfiledetails(configfile) end -function setconfigfile(self, filedetails) +function mymodule.setconfigfile(self, filedetails) return modelfunctions.setfiledetails(self, filedetails, {configfile}) end -function getrrdlist() +function mymodule.getrrdlist() return list_files(databases,".*rrd") end -function createnewrrd() +function mymodule.createnewrrd() local newdb = {} newdb.filename = cfe({label="Name",value="mydb.rrd",descr="The name of the RRD you want to create. RRD files should end with the extension .rrd. However, RRDtool will accept any filename."}) newdb.start = cfe({label="Start",value="",descr="Specifies the time in seconds since 1970-01-01 UTC when the first value should be added to the RRD. RRDtool will not accept any data timed before or at the time specified.\ @@ -95,7 +95,7 @@ DS:ds-name:COMPUTE:rpn-expression",type="longtext"}) return {value=newdb} end -function remove_file(self, path, userid) +function mymodule.remove_file(self, path, userid) local success = "Failed to delete file" local errtxt if not (fs.is_file(path)) then @@ -109,7 +109,7 @@ function remove_file(self, path, userid) return cfe({ value=success, label="Delete config file result", errtxt=errtxt }) end -function rrd_info(self, path, userid) +function mymodule.rrd_info(self, path, userid) local success, errtxt if (validfilename(path)) then success, errtxt = modelfunctions.run_executable({"rrdtool", "info", path}, true) @@ -119,7 +119,7 @@ function rrd_info(self, path, userid) return cfe({ value=success, label="rrdtool info ".. tostring(path) , errtxt=errtxt }) end -function savenewrrd(self, configfile, userid) +function mymodule.savenewrrd(self, configfile, userid) path=tostring(databases).."/"..configfile.value.filename.value configfile.errtxt = "Failed to create file" local path = configfile.value.filename.value @@ -170,7 +170,7 @@ If you specify path, it should be " .. tostring(databases) .."/" if not fs.is_dir(tostring(db_scripts)) then fs.create_directory(tostring(db_scripts)) end - filedetails = modelfunctions.setfiledetails(self, filedetails, getgraphlist) + filedetails = modelfunctions.setfiledetails(self, filedetails, mymodule.getgraphlist) filedetails = nil local f = io.popen( cmd .. " 2>&1") @@ -182,7 +182,7 @@ If you specify path, it should be " .. tostring(databases) .."/" return configfile end -function list_graphs() +function mymodule.list_graphs() local graphs = {} local files = fs.find_files_as_array(".*graph", graphpath) @@ -217,13 +217,13 @@ function list_graphs() return graphs end -function view_graph(self, graph_grp, graph_id) +function mymodule.view_graph(self, graph_grp, graph_id) local general_settings = { filenameextention=".png", graph_width="800", } - local graphs = list_graphs() + local graphs = mymodule.list_graphs() local settings = graphs[tostring(graph_grp)][tonumber(self.clientdata.id)] local filename = "/".. string.lower(tostring(graph_grp)).."_"..tostring(graph_id) .. (settings.filenameextention or ".png") @@ -248,11 +248,11 @@ function view_graph(self, graph_grp, graph_id) return settings end -function getgraphlist() +function mymodule.getgraphlist() return list_files(graphpath,".*graph") end -function getgraphfile(path) +function mymodule.getgraphfile(path) if (path) and not (validfilename(path)) then path = nil end @@ -278,7 +278,7 @@ AREA:eth0tx#99000099: return output end -function set_filedetails (self, filedetails, userid) +function mymodule.set_filedetails (self, filedetails, userid) if filedetails.value.filename.value and (#filedetails.value.filename.value > 0) and not (string.match(filedetails.value.filename.value, ".*/$")) then if not (string.match(filedetails.value.filename.value, "^" .. graphpath)) then filedetails.value.filename.value = graphpath .. "/" .. string.gsub(filedetails.value.filename.value,"^.*/", "") @@ -287,7 +287,7 @@ function set_filedetails (self, filedetails, userid) filedetails.value.filename.value = filedetails.value.filename.value .. ".graph" end - filedetails = modelfunctions.setfiledetails(self, filedetails, getgraphlist) + filedetails = modelfunctions.setfiledetails(self, filedetails, mymodule.getgraphlist) else filedetails.errtxt = "Failed to set file" filedetails.value.filename.errtxt = "You need to specify a valid filename!" @@ -297,6 +297,8 @@ function set_filedetails (self, filedetails, userid) return filedetails end -function setgraphfile(self, filedetails, file) +function mymodule.setgraphfile(self, filedetails, file) return modelfunctions.setfiledetails(self, filedetails, {file}) end + +return mymodule -- cgit v1.2.3