projects
/
project
/
luci.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c1eb7cf
)
libs/uci: implement get_bool() to retrive uci variables as boolean value
author
Jo-Philipp Wich
<jow@openwrt.org>
Mon, 19 Jan 2009 13:39:54 +0000
(13:39 +0000)
committer
Jo-Philipp Wich
<jow@openwrt.org>
Mon, 19 Jan 2009 13:39:54 +0000
(13:39 +0000)
libs/uci/luasrc/model/uci.lua
patch
|
blob
|
history
diff --git
a/libs/uci/luasrc/model/uci.lua
b/libs/uci/luasrc/model/uci.lua
index
ecb8f47
..
5b8cf67
100644
(file)
--- a/
libs/uci/luasrc/model/uci.lua
+++ b/
libs/uci/luasrc/model/uci.lua
@@
-60,7
+60,7
@@
local Cursor = getmetatable(cursor())
function Cursor.apply(self, configlist, command)
configlist = self:_affected(configlist)
local reloadcmd = "/sbin/luci-reload " .. table.concat(configlist, " ")
function Cursor.apply(self, configlist, command)
configlist = self:_affected(configlist)
local reloadcmd = "/sbin/luci-reload " .. table.concat(configlist, " ")
-
+
return command and reloadcmd or os.execute(reloadcmd .. " >/dev/null 2>&1")
end
return command and reloadcmd or os.execute(reloadcmd .. " >/dev/null 2>&1")
end
@@
-72,7
+72,7
@@
end
-- returns a boolean whether to delete the current section (optional)
function Cursor.delete_all(self, config, stype, comparator)
local del = {}
-- returns a boolean whether to delete the current section (optional)
function Cursor.delete_all(self, config, stype, comparator)
local del = {}
-
+
if type(comparator) == "table" then
local tbl = comparator
comparator = function(section)
if type(comparator) == "table" then
local tbl = comparator
comparator = function(section)
@@
-80,11
+80,11
@@
function Cursor.delete_all(self, config, stype, comparator)
if section[k] ~= v then
return false
end
if section[k] ~= v then
return false
end
- end
+ end
return true
end
end
return true
end
end
-
+
local function helper (section)
if not comparator or comparator(section) then
local function helper (section)
if not comparator or comparator(section) then
@@
-135,6
+135,16
@@
function Cursor.tset(self, config, section, values)
return stat
end
return stat
end
+--- Get a boolean option and return it's value as true or false.
+-- @param config UCI config
+-- @param section UCI section name
+-- @param option UCI option
+-- @return Boolean
+function Cursor.get_bool(self, ...)
+ local val = self:get(...)
+ return ( val == "1" or val == "true" or val == "yes" or val == "on" )
+end
+
--- Get an option or list and return values as table.
-- @param config UCI config
-- @param section UCI section name
--- Get an option or list and return values as table.
-- @param config UCI config
-- @param section UCI section name
@@
-177,7
+187,7
@@
function Cursor._affected(self, configlist)
local function _resolve_deps(name)
local reload = {name}
local deps = {}
local function _resolve_deps(name)
local reload = {name}
local deps = {}
-
+
c:foreach("ucitrack", name,
function(section)
if section.affects then
c:foreach("ucitrack", name,
function(section)
if section.affects then
@@
-186,16
+196,16
@@
function Cursor._affected(self, configlist)
end
end
end)
end
end
end)
-
+
for i, dep in ipairs(deps) do
for j, add in ipairs(_resolve_deps(dep)) do
reload[#reload+1] = add
end
end
for i, dep in ipairs(deps) do
for j, add in ipairs(_resolve_deps(dep)) do
reload[#reload+1] = add
end
end
-
+
return reload
end
return reload
end
-
+
-- Collect initscripts
for j, config in ipairs(configlist) do
for i, e in ipairs(_resolve_deps(config)) do
-- Collect initscripts
for j, config in ipairs(configlist) do
for i, e in ipairs(_resolve_deps(config)) do
@@
-204,7
+214,7
@@
function Cursor._affected(self, configlist)
end
end
end
end
end
end
-
+
return reloadlist
end
return reloadlist
end