trunk: prepare LuCI to handle .lua.gz files

This commit is contained in:
Jo-Philipp Wich 2009-04-04 22:54:16 +00:00
parent f3deef9ec5
commit 9835296ba2
5 changed files with 41 additions and 18 deletions

View file

@ -59,12 +59,15 @@ function load(cbimap, ...)
local upldir = "/lib/uci/upload/" local upldir = "/lib/uci/upload/"
local cbidir = luci.util.libpath() .. "/model/cbi/" local cbidir = luci.util.libpath() .. "/model/cbi/"
assert(luci.fs.stat(cbimap) or luci.fs.stat(cbidir..cbimap..".lua"), assert(luci.fs.stat(cbimap) or
"Model not found!") luci.fs.stat(cbidir..cbimap..".lua") or
luci.fs.stat(cbidir..cbimap..".lua.gz"),
"Model not found!")
local func, err = loadfile(cbimap) local func, err = loadfile(cbimap)
if not func then if not func then
func, err = loadfile(cbidir..cbimap..".lua") func, err = loadfile(cbidir..cbimap..".lua") or
loadfile(cbidir..cbimap..".lua.gz")
end end
assert(func, err) assert(func, err)

View file

@ -355,7 +355,7 @@ end
--- Generate the dispatching index using the best possible strategy. --- Generate the dispatching index using the best possible strategy.
function createindex() function createindex()
local path = luci.util.libpath() .. "/controller/" local path = luci.util.libpath() .. "/controller/"
local suff = ".lua" local suff = { ".lua", ".lua.gz" }
if luci.util.copcall(require, "luci.fastindex") then if luci.util.copcall(require, "luci.fastindex") then
createindex_fastindex(path, suff) createindex_fastindex(path, suff)
@ -366,14 +366,16 @@ end
--- Generate the dispatching index using the fastindex C-indexer. --- Generate the dispatching index using the fastindex C-indexer.
-- @param path Controller base directory -- @param path Controller base directory
-- @param suffix Controller file suffix -- @param suffixes Controller file suffixes
function createindex_fastindex(path, suffix) function createindex_fastindex(path, suffixes)
index = {} index = {}
if not fi then if not fi then
fi = luci.fastindex.new("index") fi = luci.fastindex.new("index")
fi.add(path .. "*" .. suffix) for _, suffix in ipairs(suffixes) do
fi.add(path .. "*/*" .. suffix) fi.add(path .. "*" .. suffix)
fi.add(path .. "*/*" .. suffix)
end
end end
fi.scan() fi.scan()
@ -384,12 +386,16 @@ end
--- Generate the dispatching index using the native file-cache based strategy. --- Generate the dispatching index using the native file-cache based strategy.
-- @param path Controller base directory -- @param path Controller base directory
-- @param suffix Controller file suffix -- @param suffixes Controller file suffixes
function createindex_plain(path, suffix) function createindex_plain(path, suffixes)
local controllers = util.combine( local controllers = { }
luci.fs.glob(path .. "*" .. suffix) or {}, for _, suffix in ipairs(suffixes) do
luci.fs.glob(path .. "*/*" .. suffix) or {} util.combine(
) controllers,
luci.fs.glob(path .. "*" .. suffix) or {},
luci.fs.glob(path .. "*/*" .. suffix) or {}
)
end
if indexcache then if indexcache then
local cachedate = fs.mtime(indexcache) local cachedate = fs.mtime(indexcache)
@ -416,7 +422,11 @@ function createindex_plain(path, suffix)
index = {} index = {}
for i,c in ipairs(controllers) do for i,c in ipairs(controllers) do
local module = "luci.controller." .. c:sub(#path+1, #c-#suffix):gsub("/", ".") local module = "luci.controller." .. c:sub(#path+1, #c):gsub("/", ".")
for _, suffix in ipairs(suffixes) do
module = module:gsub(suffix.."$", "")
end
local mod = require(module) local mod = require(module)
local idx = mod.index local idx = mod.index

View file

@ -47,7 +47,9 @@ end
function load(file, lang, force) function load(file, lang, force)
lang = lang and lang:gsub("_", "-") or "" lang = lang and lang:gsub("_", "-") or ""
if force or not loaded[lang] or not loaded[lang][file] then if force or not loaded[lang] or not loaded[lang][file] then
local f = loadfile(i18ndir .. file .. "." .. lang .. ".lua") local f = loadfile(i18ndir .. file .. "." .. lang .. ".lua") or
loadfile(i18ndir .. file .. "." .. lang .. ".lua.gz")
if f then if f then
table[lang] = table[lang] or {} table[lang] = table[lang] or {}
setfenv(f, table[lang]) setfenv(f, table[lang])

View file

@ -29,7 +29,11 @@ l:value("auto")
local i18ndir = luci.i18n.i18ndir .. "default." local i18ndir = luci.i18n.i18ndir .. "default."
for k, v in pairs(luci.config.languages) do for k, v in pairs(luci.config.languages) do
if k:sub(1, 1) ~= "." and luci.fs.access(i18ndir .. k:gsub("_", "-") .. ".lua") then local file = i18ndir .. k:gsub("_", "-")
if k:sub(1, 1) ~= "." and (
luci.fs.access(file .. ".lua") or
luci.fs.access(file .. ".lua.gz")
) then
l:value(k, v) l:value(k, v)
end end
end end

View file

@ -29,7 +29,11 @@ l:value("auto")
local i18ndir = luci.i18n.i18ndir .. "default." local i18ndir = luci.i18n.i18ndir .. "default."
for k, v in pairs(luci.config.languages) do for k, v in pairs(luci.config.languages) do
if k:sub(1, 1) ~= "." and luci.fs.access(i18ndir .. k:gsub("_", "-") .. ".lua") then local file = i18ndir .. k:gsub("_", "-")
if k:sub(1, 1) ~= "." and (
luci.fs.access(file .. ".lua") or
luci.fs.access(file .. ".lua.gz")
) then
l:value(k, v) l:value(k, v)
end end
end end