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 = setmetatable
32 local tostring = tostring
34 module("luci.model.uci", function(m) setmetatable(m, {__index = uci}) end)
37 local sections_mt = {}
41 setmetatable(config, configs_mt)
44 function configs_mt.__index(self, key)
45 local node = rawget(self, key)
49 setmetatable(node, sections_mt)
50 rawset(self, key, node)
54 function configs_mt.__newindex()
55 error("invalid operation")
60 function sections_mt.__index(self, key)
61 local node = rawget(self, key)
64 node[".conf"] = self[".name"]
66 node[".type"] = uci.get(self[".name"], key)
67 setmetatable(node, options_mt)
68 rawset(self, key, node)
72 function sections_mt.__newindex(self, key, value)
74 if uci.delete(self[".name"], key) then
75 rawset(self, key, nil)
77 error("unable to delete section")
80 key = uci.add(self[".name"], tostring(value))
82 rawset(self, "", self[key])
84 error("unable to create section")
87 if not uci.set(self[".name"], key, value) then
88 error("unable to create section")
95 function options_mt.__index(self, key)
96 return uci.get(self[".conf"], self[".name"], key)
98 function options_mt.__newindex(self, key, value)
100 if not uci.delete(self[".conf"], self[".name"], key) then
101 error("unable to delete option")
104 if not uci.set(self[".conf"], self[".name"], key, tostring(value)) then
105 error("unable to write option")