From 1448b0049d94eb830c2e6ac17a6f1038f76de076 Mon Sep 17 00:00:00 2001 From: Alexander Poslavsky Date: Fri, 2 Nov 2007 13:08:51 +0000 Subject: lbu acf module work-in-progress git-svn-id: svn://svn.alpinelinux.org/acf/lbu/trunk@259 ab2d0c66-481e-0410-8bed-d214d4d58bed --- Makefile | 53 ++++++++++++++++++++++++++++ config.mk | 11 ++++++ lbu-commit-html.lsp | 52 ++++++++++++++++++++++++++++ lbu-controller.lua | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lbu-html.lsp | 41 ++++++++++++++++++++++ lbu-model.lua | 35 +++++++++++++++++++ lbu-read-html.lsp | 27 +++++++++++++++ lbu.cfg | 11 ++++++ lbu.menu | 2 ++ 9 files changed, 331 insertions(+) create mode 100644 Makefile create mode 100644 config.mk create mode 100644 lbu-commit-html.lsp create mode 100644 lbu-controller.lua create mode 100644 lbu-html.lsp create mode 100644 lbu-model.lua create mode 100644 lbu-read-html.lsp create mode 100644 lbu.cfg create mode 100644 lbu.menu diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f702d16 --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +APP_NAME=lbu +PACKAGE=acf-$(APP_NAME) +VERSION=0.1 + +APP_DIST=\ + lbu-commit-html.lsp \ + lbu-controller.lua \ + lbu-html.lsp \ + lbu-model.lsp \ + lbu-read-html.lsp \ + lbu.menu + +APP_CFG=\ + lbu.cfg + +EXTRA_DIST=Makefile config.mk + +DISTFILES=$(APP_DIST) $(EXTRA_DIST) + +TAR=tar + +P=$(PACKAGE)-$(VERSION) +tarball=$(P).tar.bz2 +install_dir=$(DESTDIR)/$(appdir)/$(APP_NAME) + +all: +clean: + rm -rf $(tarball) $(P) + +dist: $(tarball) + +install: + mkdir -p "$(install_dir)" + cp -a $(APP_DIST) "$(install_dir)" + mkdir -p "$(cfgdir)" + cp -a $(APP_CFG) "$(cfgdir)" + +$(tarball): $(DISTFILES) + rm -rf $(P) + mkdir -p $(P) + cp $(DISTFILES) $(P) + $(TAR) -jcf $@ $(P) + rm -rf $(P) + +# target that creates a tar package, unpacks is and install from package +dist-install: $(tarball) + $(TAR) -jxf $(tarball) + $(MAKE) -C $(P) install DESTDIR=$(DESTDIR) + rm -rf $(P) + +include config.mk + +.PHONY: all clean dist install dist-install diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..f67accc --- /dev/null +++ b/config.mk @@ -0,0 +1,11 @@ +prefix=/usr +datadir=${prefix}/share +sysconfdir=${prefix}/etc +localstatedir=${prefix}/var +acfdir=${datadir}/acf +wwwdir=${acfdir}/www +cgibindir=${acfdir}/cgi-bin +appdir=${acfdir}/app +cfgdir=${appdir}/cfgfile +acflibdir=${acfdir}/lib +sessionsdir=${localstatedir}/lib/acf/sessions diff --git a/lbu-commit-html.lsp b/lbu-commit-html.lsp new file mode 100644 index 0000000..c5e1ff2 --- /dev/null +++ b/lbu-commit-html.lsp @@ -0,0 +1,52 @@ +

diff --git a/lbu-controller.lua b/lbu-controller.lua new file mode 100644 index 0000000..51a0538 --- /dev/null +++ b/lbu-controller.lua @@ -0,0 +1,99 @@ +module(..., package.seeall) + +local list_redir = function(self) + self.conf.action = "read" + self.conf.type = "redir" + error(self.conf) +end + +local cfgfile + +mvc={} +mvc.on_load = function(self, parent) + cfgfile = self:new("cfgfile") + if (self.worker[self.conf.action] == nil) or (self.conf.action == "init") then + self.worker[self.conf.action] = list_redir(self) + end +end + +-- Public methods +-- /hostname/get + +local function getNotes(self) + ret = {} + for k,v in pairs(cfgfile.model:list(nil)) do + if v.status then + ret[#ret + 1] = { + content = "There are some configuration changes. Please do not forget to save." + } + break + end + end + return ret +end + +read = function(self) + return { + list=cfgfile.model:list(function(x) return x.app == "lbu" end), + script=ENV["SCRIPT_NAME"], + prefix=self.conf.prefix, + controller=self.conf.controller, + action="update", + note=getNotes(self), + } +end + +update = function(self) + local id = tonumber(self.clientdata.id) or -1 + local result + local data + + result, data = cfgfile.model:get(id) + if not result then return list_redir(self) end + + if self.clientdata.cmd then + for k,v in pairs (data) do + if self.clientdata[k] then + data[k].value = self.clientdata[k] + end + end + result, data = cfgfile.model:set(id, data) + if result then return list_redir(self) end + end + + data.cmd = cfe { type="action", value="save", label="action" } + return cfe{ type="form", + option={ script=ENV["SCRIPT_NAME"], + prefix=self.conf.prefix, + controller = self.conf.controller, + action = "update", + extra = ""}, + value = data} +end + +function commit(self) + local ret = { + script=ENV["SCRIPT_NAME"], + prefix=self.conf.prefix, + controller = self.conf.controller, + action="commit", + data={}, + title="LBU", + text={}, + } + if self.clientdata.commit then + local result, report = self.model:commit() + local label = result and "Report" or "Error" + ret.text[#ret.text + 1] = { label=label, content=report } + else + for i,v in ipairs(self.model:list(nil)) do + ret.data[#ret.data + 1] = { + status = v.status, + name = v.name, + } + end + end + ret.note=getNotes(self) + return ret +end + diff --git a/lbu-html.lsp b/lbu-html.lsp new file mode 100644 index 0000000..efb1c38 --- /dev/null +++ b/lbu-html.lsp @@ -0,0 +1,41 @@ +

Edit

+ diff --git a/lbu-model.lua b/lbu-model.lua new file mode 100644 index 0000000..276ef85 --- /dev/null +++ b/lbu-model.lua @@ -0,0 +1,35 @@ +module (..., package.seeall) + +require "fs" + +local function getLbuStatus() + local ret = {} + local f = io.popen("/sbin/lbu status -v", "r") + if not f then return ret end + for line in f:lines() do + local status, name = string.match(line, "^(%S+)%s+(.+)$") + if status and name then + ret[string.gsub('/' .. name, "/+", "/")] = status + end + end + f:close() + return ret +end + +function list(self) + local ret = {} + local lbuStatus = getLbuStatus() + for k,v in pairs(lbuStatus) do + ret[#ret + 1] = { name=k, status=v } + end + return ret +end + +function commit(self) + local f = io.popen("/sbin/lbu commit", 'r') + if not f then return false, "cannot run lbu" end + local ret = f:read("*a") + f:close() + return true, ret +end + diff --git a/lbu-read-html.lsp b/lbu-read-html.lsp new file mode 100644 index 0000000..0ea1ec8 --- /dev/null +++ b/lbu-read-html.lsp @@ -0,0 +1,27 @@ + + +

Edit

+ +

+ + + +

diff --git a/lbu.cfg b/lbu.cfg new file mode 100644 index 0000000..fc22ed6 --- /dev/null +++ b/lbu.cfg @@ -0,0 +1,11 @@ +-- /* vim: set filetype=lua : */ +{ app="lbu", section="general", + name="include", filename="/etc/lbu/include", + descr="Include list" }, +{ app="lbu", section="general", + name="exclude", filename="/etc/lbu/exclude", + descr="Exclude list" }, +{ app="lbu", section="general", + name="packages", filename="/etc/lbu/packages.list", + descr="Remembered list of installed packages" }, + diff --git a/lbu.menu b/lbu.menu new file mode 100644 index 0000000..01bd02b --- /dev/null +++ b/lbu.menu @@ -0,0 +1,2 @@ +System LBU Define read + -- cgit v1.2.3