mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-19 21:58:04 +00:00
ucitrigger: add options to force enable/disable specific triggers
SVN-Revision: 16718
This commit is contained in:
parent
7ffee1f66f
commit
069dbf6fd4
10
package/uci/trigger/apply_config
Normal file → Executable file
10
package/uci/trigger/apply_config
Normal file → Executable file
@ -9,6 +9,8 @@ function usage()
|
|||||||
print(" -t: show matching UCI triggers")
|
print(" -t: show matching UCI triggers")
|
||||||
print(" -s: show information about tasks to be executed")
|
print(" -s: show information about tasks to be executed")
|
||||||
print(" -r: reset all triggers")
|
print(" -r: reset all triggers")
|
||||||
|
print(" -C <trigger> [<section>]: force clear a trigger")
|
||||||
|
print(" -S <trigger> [<section>]: force set a trigger")
|
||||||
print("")
|
print("")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,6 +41,14 @@ elseif arg[1] == "-a" then
|
|||||||
uci.trigger.run()
|
uci.trigger.run()
|
||||||
elseif arg[1] == "-r" then
|
elseif arg[1] == "-r" then
|
||||||
uci.trigger.reset_state()
|
uci.trigger.reset_state()
|
||||||
|
elseif arg[1] == "-S" then
|
||||||
|
local trigger = arg[2]
|
||||||
|
local section = arg[3]
|
||||||
|
uci.trigger.set_active(trigger, section)
|
||||||
|
elseif arg[1] == "-C" then
|
||||||
|
local trigger = arg[2]
|
||||||
|
local section = arg[3]
|
||||||
|
uci.trigger.clear_active(trigger, section)
|
||||||
else
|
else
|
||||||
usage()
|
usage()
|
||||||
end
|
end
|
||||||
|
@ -253,6 +253,17 @@ function add(ts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function save_trigger(name)
|
||||||
|
if triggers.active[name] then
|
||||||
|
local slist = get_names(triggers.active[name])
|
||||||
|
if #slist > 0 then
|
||||||
|
tctx:set("uci_trigger", name, "sections", slist)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
tctx:delete("uci_trigger", name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function set(data, cursor)
|
function set(data, cursor)
|
||||||
assert(data ~= nil)
|
assert(data ~= nil)
|
||||||
if cursor == nil then
|
if cursor == nil then
|
||||||
@ -296,10 +307,7 @@ function set(data, cursor)
|
|||||||
if section[".name"] then
|
if section[".name"] then
|
||||||
active[section[".name"]] = true
|
active[section[".name"]] = true
|
||||||
end
|
end
|
||||||
local slist = get_names(triggers.active[t.id])
|
save_trigger(t.id)
|
||||||
if #slist > 0 then
|
|
||||||
tctx:set("uci_trigger", t.id, "sections", slist)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
tctx:save("uci_trigger")
|
tctx:save("uci_trigger")
|
||||||
end
|
end
|
||||||
@ -335,6 +343,46 @@ function get_active()
|
|||||||
return slist
|
return slist
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function set_active(trigger, sections)
|
||||||
|
if triggers == nil then
|
||||||
|
load_state()
|
||||||
|
end
|
||||||
|
if not triggers.list[trigger] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if triggers.active[trigger] == nil then
|
||||||
|
tctx:set("uci_trigger", trigger, "trigger")
|
||||||
|
triggers.active[trigger] = {}
|
||||||
|
end
|
||||||
|
local active = triggers.active[trigger]
|
||||||
|
if triggers.list[trigger].section_only or sections ~= nil then
|
||||||
|
for i, t in ipairs(sections) do
|
||||||
|
triggers.active[trigger][t] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
save_trigger(trigger)
|
||||||
|
tctx:save("uci_trigger")
|
||||||
|
end
|
||||||
|
|
||||||
|
function clear_active(trigger, sections)
|
||||||
|
if triggers == nil then
|
||||||
|
load_state()
|
||||||
|
end
|
||||||
|
if triggers.list[trigger] == nil or triggers.active[trigger] == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local active = triggers.active[trigger]
|
||||||
|
if not triggers.list[trigger].section_only or sections == nil then
|
||||||
|
triggers.active[trigger] = nil
|
||||||
|
else
|
||||||
|
for i, t in ipairs(sections) do
|
||||||
|
triggers.active[trigger][t] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
save_trigger(trigger)
|
||||||
|
tctx:save("uci_trigger")
|
||||||
|
end
|
||||||
|
|
||||||
function run(ts)
|
function run(ts)
|
||||||
if ts == nil then
|
if ts == nil then
|
||||||
ts = get_active()
|
ts = get_active()
|
||||||
|
Loading…
Reference in New Issue
Block a user