11 Copyright 2008 Steven Barth <steven@midlink.org>
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
26 local uci = require("uci")
27 local util = require("luci.util")
28 local setmetatable, rawget, rawset = setmetatable, rawget, rawset
29 local error, pairs, ipairs, tostring = error, pairs, ipairs, tostring
32 module("luci.model.uci", function(m) setmetatable(m, {__index = uci}) end)
34 savedir_default = "/tmp/.uci"
35 confdir_default = "/etc/config"
37 savedir_state = "/var/state"
39 function delete_all(config, type, comparator)
41 local function helper (section)
42 if not comparator or comparator(section) then
43 table.insert(del, section[".name"])
47 foreach(config, type, helper)
49 for i, j in ipairs(del) do
54 function section(config, type, name, values)
57 stat = set(config, name, type)
59 name = add(config, type)
63 if stat and values then
64 stat = tset(config, name, values)
70 function get_statevalue(...)
71 set_savedir(savedir_state)
72 local result = get(...)
73 set_savedir(savedir_default)
77 function tset(config, section, values)
79 for k, v in pairs(values) do
80 if k:sub(1, 1) ~= "." then
81 stat = stat and set(config, section, k, v)