make use of the new features in the binding for uci v0.4.0 - fixes remaining dependen...
[project/luci.git] / libs / core / luasrc / model / uci / libuci.lua
1 --[[
2 LuCI - UCI libuci wrapper
3
4 Description:
5 Wrapper for the libuci Lua bindings
6
7 FileId:
8 $Id$
9
10 License:
11 Copyright 2008 Steven Barth <steven@midlink.org>
12
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
16
17 http://www.apache.org/licenses/LICENSE-2.0
18
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.
24
25 ]]--
26
27 module("luci.model.uci.libuci", package.seeall)
28
29 require("uci")
30 require("luci.util")
31 require("luci.sys")
32
33 -- Session class
34 Session = luci.util.class()
35
36 -- Session constructor
37 function Session.__init__(self, savedir)
38 self.savedir = savedir or luci.model.uci.savedir
39 uci.set_savedir(self.savedir)
40 end
41
42 function Session.add(self, config, section_type)
43 return uci.add(config, section_type)
44 end
45
46 function Session.changes(self, config)
47 if config then
48 return uci.changes(config)
49 else
50 return uci.changes()
51 end
52 end
53
54 function Session.commit(self, config)
55 return self:t_commit(config)
56 end
57
58 function Session.del(self, config, section, option)
59 return uci.del(config, section, option)
60 end
61
62 function Session.get(self, config, section, option)
63 return self:t_get(config, section, option)
64 end
65
66 function Session.revert(self, config)
67 return self:t_revert(config)
68 end
69
70 function Session.sections(self, config)
71 return self:t_sections(config)
72 end
73
74 function Session.set(self, config, section, option, value)
75 return self:t_set(config, section, option, value) and self:t_save(config)
76 end
77
78 function Session.synchronize(self)
79 return uci.set_savedir(self.savedir)
80 end
81
82
83 -- UCI-Transactions
84
85 function Session.t_load(self, config)
86 return self:synchronize() and uci.load(config)
87 end
88
89 function Session.t_save(self, config)
90 return uci.save(config)
91 end
92
93 function Session.t_add(self, config, type)
94 return self:add(config, type)
95 end
96
97 function Session.t_commit(self, config)
98 return uci.commit(config)
99 end
100
101 function Session.t_del(self, config, section, option)
102 return self:del(config, section, option)
103 end
104
105 function Session.t_get(self, config, section, option)
106 if option then
107 return uci.get(config, section, option)
108 else
109 return uci.get(config, section)
110 end
111 end
112
113 function Session.t_revert(self, config)
114 return uci.revert(config)
115 end
116
117 function Session.t_sections(self, config)
118 return uci.get_all(config)
119 end
120
121 function Session.t_set(self, config, section, option, value)
122 if option then
123 return uci.set(config, section, option, value)
124 else
125 return uci.set(config, section, value)
126 end
127 end
128