summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-12-31 09:07:05 +0000
committerTed Trask <ttrask01@yahoo.com>2009-12-31 09:07:05 +0000
commitbe4063286a0b8f46754c082178517b3c684c3dff (patch)
tree32966a8ba376048fa34b718cd6663138aea87249
parentbd1d77b3b8278dfab279fe31ff88eab953bdd4c0 (diff)
downloadacf-core-be4063286a0b8f46754c082178517b3c684c3dff.tar.bz2
acf-core-be4063286a0b8f46754c082178517b3c684c3dff.tar.xz
Allow appdir and libdir to be comma-separated lists of directories.
-rw-r--r--acf.conf2
-rw-r--r--app/acf_cli-controller.lua6
-rw-r--r--app/acf_www-controller.lua50
-rw-r--r--lib/menubuilder.lua100
-rw-r--r--lib/roles.lua23
-rw-r--r--www/cgi-bin/mvc.lua28
6 files changed, 121 insertions, 88 deletions
diff --git a/acf.conf b/acf.conf
index 64c8e40..e8cb0ac 100644
--- a/acf.conf
+++ b/acf.conf
@@ -1,6 +1,8 @@
# Configuration file for Alpine Configuration Framework
# Directories where the application resides
+# appdir and libdir may be comma-separated lists
+# do not place same name lib or prefix/controller files in multiple directories
appdir=/usr/share/acf/app/
libdir=/usr/share/acf/lib/
wwwdir=/usr/share/acf/www/
diff --git a/app/acf_cli-controller.lua b/app/acf_cli-controller.lua
index ef82c70..3d4a3e9 100644
--- a/app/acf_cli-controller.lua
+++ b/app/acf_cli-controller.lua
@@ -5,13 +5,15 @@ require("posix")
mvc = {}
mvc.on_load = function (self, parent)
-- Make sure we have some kind of sane defaults for libdir
- self.conf.libdir = self.conf.libdir or ( posix.dirname(self.conf.appdir) .. "/lib/" )
+ self.conf.libdir = self.conf.libdir or ( string.match(self.conf.appdir, "[^,]+/") .. "/lib/" )
self.conf.script = ""
self.conf.default_prefix = "/acf-util/"
self.conf.default_controller = "welcome"
-- this sets the package path for us and our children
- package.path= self.conf.libdir .. "?.lua;" .. package.path
+ for p in string.gmatch(self.conf.libdir, "[^,]+") do
+ package.path= p .. "?.lua;" .. package.path
+ end
self.session = {}
local x=require("session")
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index 1977491..017b574 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -27,7 +27,7 @@ local function build_menus(self)
self.sessiondata.permissions = permissions
--Build the menu
- local cats = m.get_menuitems(self.conf.appdir)
+ local cats = m.get_menuitems(self)
-- now, loop through menu and remove actions without permission
-- go in reverse so we can remove entries while looping
for x = #cats,1,-1 do
@@ -80,6 +80,15 @@ end
-- ctlr-action-view, then ctlr-view, then action-view, then view
-- cannot be local function because of recursion
find_template = function ( appdir, prefix, controller, action, viewtype )
+ if string.find(appdir, ",") then
+ local template
+ for p in string.gmatch(appdir, "[^,]+") do
+ template = find_template(p, prefix, controller, action, viewtype)
+ if template then break end
+ end
+ return template
+ end
+
local targets = {
appdir .. prefix .. "template-" .. controller .. "-" ..
action .. "-" .. viewtype .. ".lsp",
@@ -108,17 +117,19 @@ end
-- look for a view
-- ctlr-action-view, then ctlr-view
local find_view = function ( appdir, prefix, controller, action, viewtype )
- local names = { appdir .. prefix .. controller .. "-" ..
- action .. "-" .. viewtype .. ".lsp",
- appdir .. prefix .. controller .. "-" ..
- viewtype .. ".lsp" }
- local file
- -- search for view
- for i,filename in ipairs (names) do
- file = io.open(filename)
- if file then
- file:close()
- return filename
+ for p in string.gmatch(appdir, "[^,]+") do
+ local names = { p .. prefix .. controller .. "-" ..
+ action .. "-" .. viewtype .. ".lsp",
+ p .. prefix .. controller .. "-" ..
+ viewtype .. ".lsp" }
+ local file
+ -- search for view
+ for i,filename in ipairs (names) do
+ file = io.open(filename)
+ if file then
+ file:close()
+ return filename
+ end
end
end
return nil
@@ -126,8 +137,11 @@ end
local has_view = function(self)
require("fs")
- local file = posix.stat(self.conf.appdir .. self.conf.prefix .. self.conf.controller .. "-" .. self.conf.action .. "-" .. (self.conf.viewtype or "html") .. ".lsp", "type")
- return file == "regular" or file == "link"
+ for p in string.gmatch(self.conf.appdir, "[^,]+") do
+ local file = posix.stat(p .. self.conf.prefix .. self.conf.controller .. "-" .. self.conf.action .. "-" .. (self.conf.viewtype or "html") .. ".lsp", "type")
+ if file == "regular" or file == "link" then return true end
+ end
+ return false
end
-- This function is made available within the view to allow loading of components
@@ -226,8 +240,8 @@ mvc.on_load = function (self, parent)
--logevent("acf_www-controller mvc.on_load")
-- Make sure we have some kind of sane defaults for libdir, wwwdir, and sessiondir
- self.conf.libdir = self.conf.libdir or ( posix.dirname(self.conf.appdir) .. "/lib/" )
- self.conf.wwwdir = self.conf.wwwdir or ( posix.dirname(self.conf.appdir) .. "/www/" )
+ self.conf.libdir = self.conf.libdir or ( string.match(self.conf.appdir, "[^,]+/") .. "/lib/" )
+ self.conf.wwwdir = self.conf.wwwdir or ( string.match(self.conf.appdir, "[^,]+/") .. "/www/" )
self.conf.sessiondir = self.conf.sessiondir or "/tmp/"
self.conf.script = ENV.SCRIPT_NAME
self.conf.default_prefix = "/acf-util/"
@@ -238,7 +252,9 @@ mvc.on_load = function (self, parent)
parent_exception_handler = parent.exception_handler
-- this sets the package path for us and our children
- package.path= self.conf.libdir .. "?.lua;" .. package.path
+ for p in string.gmatch(self.conf.libdir, "[^,]+") do
+ package.path= p .. "?.lua;" .. package.path
+ end
sessionlib=require ("session")
diff --git a/lib/menubuilder.lua b/lib/menubuilder.lua
index 51ed76d..2606fb7 100644
--- a/lib/menubuilder.lua
+++ b/lib/menubuilder.lua
@@ -59,61 +59,63 @@ local prio_compare = function(x,y)
end
-- returns a table of all the menu items found, sorted by priority
-get_menuitems = function (startdir)
+get_menuitems = function (self)
local cats = {}
local reversecats = {}
- startdir = (string.gsub(startdir, "/$", "")) --remove trailing /
- for k,filename in pairs(get_candidates(startdir)) do
- local controller = string.gsub(posix.basename(filename), ".menu$", "")
- local prefix = (string.gsub(posix.dirname(filename), startdir, "")).."/"
+ for p in string.gmatch(self.conf.appdir, "[^,]+") do
+ p = (string.gsub(p, "/$", "")) --remove trailing /
+ for k,filename in pairs(get_candidates(p)) do
+ local controller = string.gsub(posix.basename(filename), ".menu$", "")
+ local prefix = (string.gsub(posix.dirname(filename), p, "")).."/"
- -- open the menu file, and parse the contents
- local handle = io.open(filename)
- for x in handle:lines() do
- local result = parse_menu_line(x)
- if result then
- for i = 1,1 do -- loop so break works
- -- Add the category
- if nil == reversecats[result.cat] then
- table.insert ( cats,
- { name=result.cat,
- groups = {},
- reversegroups = {} } )
- reversecats[result.cat] = #cats
- end
- local cat = cats[reversecats[result.cat]]
- cat.priority = cat.priority or result.cat_prio
- -- Add the group
- if nil == result.group then break end
- if nil == cat.groups[cat.reversegroups[result.group]] then
- table.insert ( cat.groups,
- { name = result.group,
- controllers = {},
- reversetabs = {},
- tabs = {} } )
- cat.reversegroups[result.group] = #cat.groups
- end
- cat.groups[cat.reversegroups[result.group]].controllers[prefix..controller] = true
- local group = cat.groups[cat.reversegroups[result.group]]
- group.priority = group.priority or result.group_prio
- -- Add the tab
- if nil == result.tab or nil == result.action then break end
- local tab = { name = result.tab,
- controller = controller,
- prefix = prefix,
- action = result.action }
- table.insert(group.tabs, tab)
- if group.reversetabs[tab.name] then
- -- Flag for two tabs of same name
- group.flag = tab.name
- table.insert(group.reversetabs[tab.name], #group.tabs)
- else
- group.reversetabs[tab.name] = {#group.tabs}
- end
+ -- open the menu file, and parse the contents
+ local handle = io.open(filename)
+ for x in handle:lines() do
+ local result = parse_menu_line(x)
+ if result then
+ for i = 1,1 do -- loop so break works
+ -- Add the category
+ if nil == reversecats[result.cat] then
+ table.insert ( cats,
+ { name=result.cat,
+ groups = {},
+ reversegroups = {} } )
+ reversecats[result.cat] = #cats
+ end
+ local cat = cats[reversecats[result.cat]]
+ cat.priority = cat.priority or result.cat_prio
+ -- Add the group
+ if nil == result.group then break end
+ if nil == cat.groups[cat.reversegroups[result.group]] then
+ table.insert ( cat.groups,
+ { name = result.group,
+ controllers = {},
+ reversetabs = {},
+ tabs = {} } )
+ cat.reversegroups[result.group] = #cat.groups
+ end
+ cat.groups[cat.reversegroups[result.group]].controllers[prefix..controller] = true
+ local group = cat.groups[cat.reversegroups[result.group]]
+ group.priority = group.priority or result.group_prio
+ -- Add the tab
+ if nil == result.tab or nil == result.action then break end
+ local tab = { name = result.tab,
+ controller = controller,
+ prefix = prefix,
+ action = result.action }
+ table.insert(group.tabs, tab)
+ if group.reversetabs[tab.name] then
+ -- Flag for two tabs of same name
+ group.flag = tab.name
+ table.insert(group.reversetabs[tab.name], #group.tabs)
+ else
+ group.reversetabs[tab.name] = {#group.tabs}
+ end
+ end
end
end
+ handle:close()
end
- handle:close()
end
-- Now that we have the entire menu, sort by priority
diff --git a/lib/roles.lua b/lib/roles.lua
index bfd45cf..a07d290 100644
--- a/lib/roles.lua
+++ b/lib/roles.lua
@@ -10,16 +10,25 @@ guest_role = "GUEST"
-- returns a table of the *.roles files
-- startdir should be the app dir
-local get_roles_candidates = function (startdir)
- return fs.find_files_as_array(".*%.roles", startdir, true) or {}
+local get_roles_candidates = function(self)
+ local list = {}
+ for p in string.gmatch(self.conf.appdir, "[^,]+") do
+ local l = fs.find_files_as_array(".*%.roles", p, true) or {}
+ for i,f in ipairs(l) do
+ list[#list+1] = f
+ end
+ end
+ return list
end
-- Return a list of *controller.lua files
list_controllers = function(self)
local list = {}
- for file in fs.find(".*controller%.lua", self.conf.appdir, true) do
- if not string.find(file, "acf_") then
- list[#list + 1] = file
+ for p in string.gmatch(self.conf.appdir, "[^,]+") do
+ for file in fs.find(".*controller%.lua", p, true) do
+ if not string.find(file, "acf_") then
+ list[#list + 1] = file
+ end
end
end
@@ -85,7 +94,7 @@ list_default_roles = function(self)
local reverseroles = {}
-- find all of the default roles files and parse them
- local rolesfiles = get_roles_candidates(self.conf.appdir)
+ local rolesfiles = get_roles_candidates(self)
for x,file in ipairs(rolesfiles) do
f = fs.read_file_as_array(file) or {}
@@ -152,7 +161,7 @@ local determine_perms = function(self,roles)
end
-- find all of the default roles files and parse them
- local rolesfiles = get_roles_candidates(self.conf.appdir)
+ local rolesfiles = get_roles_candidates(self)
for x,file in ipairs(rolesfiles) do
local prefix = string.match(file, "(/[^/]+/)[^/]+$") or "/"
diff --git a/www/cgi-bin/mvc.lua b/www/cgi-bin/mvc.lua
index efaca5f..f176fe9 100644
--- a/www/cgi-bin/mvc.lua
+++ b/www/cgi-bin/mvc.lua
@@ -208,19 +208,21 @@ end
-- otherwise, returns nil, but no error
soft_require = function (self, name )
local filename, file
- filename = self.conf.appdir .. name .. ".lua"
- file = io.open(filename)
- if file then
- file:close()
- local PATH=package.path
- -- FIXME - this should really try to open the lua file,
- -- and if it doesnt exist silently fail.
- -- This version allows things from /usr/local/lua/5.1 to
- -- be loaded
- package.path = self.conf.appdir .. posix.dirname(name) .. "/?.lua;" .. package.path
- local t = require(posix.basename(name))
- package.path = PATH
- return t
+ for p in string.gmatch(self.conf.appdir, "[^,]+") do
+ filename = p .. name .. ".lua"
+ file = io.open(filename)
+ if file then
+ file:close()
+ local PATH=package.path
+ -- FIXME - this should really try to open the lua file,
+ -- and if it doesnt exist silently fail.
+ -- This version allows things from /usr/local/lua/5.1 to
+ -- be loaded
+ package.path = p .. posix.dirname(name) .. "/?.lua;" .. package.path
+ local t = require(posix.basename(name))
+ package.path = PATH
+ return t
+ end
end
return nil
end