From a0f64cff3dfc675ed5ea641c10be72c842b693d5 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 4 Jul 2008 14:54:19 +0000 Subject: Modified lbu to use controllerfunctions, modelfunctions, and common lsp files. Moved basicstatus->status and status->listchanges. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@1276 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lbu-model.lua | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'lbu-model.lua') diff --git a/lbu-model.lua b/lbu-model.lua index 3ae6c87..0ff1b96 100644 --- a/lbu-model.lua +++ b/lbu-model.lua @@ -1,10 +1,10 @@ module (..., package.seeall) -- Load libraries +require("modelfunctions") require("fs") require("format") require("getopts") -require("daemoncontrol") require("validator") -- Set variables @@ -308,13 +308,15 @@ function getincluded () validatefilelist(included) - return included + return cfe({ type="group", value={included = included} }) end function setincluded (included) - validatefilelist(included) - if not included.errtxt then - fs.write_file(includefile, included.value) + validatefilelist(included.value.included) + if not included.value.included.errtxt then + fs.write_file(includefile, included.value.included.value) + else + included.errtxt = "Failed to set included" end return included end @@ -329,44 +331,34 @@ function getexcluded () validatefilelist(excluded) - return excluded + return cfe({ type="group", value={excluded = excluded} }) end function setexcluded (excluded) - validatefilelist(excluded) - if not excluded.errtxt then - fs.write_file(excludefile, excluded.value) + validatefilelist(excluded.value.excluded) + if not excluded.value.excluded.errtxt then + fs.write_file(excludefile, excluded.value.excluded.value) + else + excluded.errtxt = "Failed to set excluded" end return excluded end function get_filedetails() - local filename = cfe({ value=configfile, label="File name" }) - local filecontent = cfe({ type="longtext", label="Config file" }) - local filesize = cfe({ value="0", label="File size" }) - local mtime = cfe({ value="---", label="File date" }) - - if fs.is_file(configfile) then - local filedetails = fs.stat(configfile) - filecontent.value = fs.read_file(configfile) - filesize.value = filedetails.size - mtime.value = filedetails.mtime - - validatefilecontent(filecontent) - else - filename.errtxt = "File not found" - end - - return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, mtime=mtime}, label="Config file details" }) + return modelfunctions.getfiledetails(configfile) end -function set_filecontent (filecontent) +function set_filedetails(filedetails) + local filecontent = filedetails.value.filecontent filecontent.value = format.dostounix(filecontent.value) + filecontent.value = filecontent.value:gsub("\n+$", "") validatefilecontent(filecontent) if not filecontent.errtxt then fs.write_file(configfile, filecontent.value) + else + filedetails.errtxt = "Failed to set config" end - return filecontent + return filedetails end function getcommit() -- cgit v1.2.3