2008-05-05 19:27:30 +00:00
|
|
|
--[[
|
2008-05-25 17:00:30 +00:00
|
|
|
LuCI - UCI libuci wrapper
|
2008-05-05 19:27:30 +00:00
|
|
|
|
|
|
|
Description:
|
|
|
|
Wrapper for the libuci Lua bindings
|
|
|
|
|
|
|
|
FileId:
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
License:
|
|
|
|
Copyright 2008 Steven Barth <steven@midlink.org>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2008-05-25 17:00:30 +00:00
|
|
|
module("luci.model.uci.libuci", package.seeall)
|
2008-05-05 19:27:30 +00:00
|
|
|
|
2008-05-06 14:28:51 +00:00
|
|
|
require("uci")
|
2008-05-25 17:00:30 +00:00
|
|
|
require("luci.util")
|
|
|
|
require("luci.sys")
|
2008-05-05 19:27:30 +00:00
|
|
|
|
|
|
|
-- Session class
|
2008-05-25 17:00:30 +00:00
|
|
|
Session = luci.util.class()
|
2008-05-05 19:27:30 +00:00
|
|
|
|
|
|
|
-- Session constructor
|
2008-05-06 14:28:51 +00:00
|
|
|
function Session.__init__(self, savedir)
|
2008-05-25 17:00:30 +00:00
|
|
|
self.savedir = savedir or luci.model.uci.savedir
|
2008-06-03 22:42:01 +00:00
|
|
|
uci.set_savedir(self.savedir)
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Session.add(self, config, section_type)
|
2008-06-03 22:42:01 +00:00
|
|
|
return uci.add(config, section_type)
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Session.changes(self, config)
|
2008-06-03 22:42:01 +00:00
|
|
|
if config then
|
|
|
|
return uci.changes(config)
|
|
|
|
else
|
|
|
|
return uci.changes()
|
|
|
|
end
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Session.commit(self, config)
|
2008-05-06 14:28:51 +00:00
|
|
|
return self:t_commit(config)
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Session.del(self, config, section, option)
|
2008-06-03 22:42:01 +00:00
|
|
|
return uci.del(config, section, option)
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Session.get(self, config, section, option)
|
2008-05-06 14:28:51 +00:00
|
|
|
return self:t_get(config, section, option)
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Session.revert(self, config)
|
2008-05-06 14:28:51 +00:00
|
|
|
return self:t_revert(config)
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
|
2008-05-06 14:28:51 +00:00
|
|
|
function Session.sections(self, config)
|
|
|
|
return self:t_sections(config)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Session.set(self, config, section, option, value)
|
|
|
|
return self:t_set(config, section, option, value) and self:t_save(config)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Session.synchronize(self)
|
|
|
|
return uci.set_savedir(self.savedir)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- UCI-Transactions
|
|
|
|
|
|
|
|
function Session.t_load(self, config)
|
|
|
|
return self:synchronize() and uci.load(config)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Session.t_save(self, config)
|
|
|
|
return uci.save(config)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Session.t_add(self, config, type)
|
2008-06-03 22:42:01 +00:00
|
|
|
return self:add(config, type)
|
2008-05-06 14:28:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Session.t_commit(self, config)
|
|
|
|
return uci.commit(config)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Session.t_del(self, config, section, option)
|
2008-06-03 22:42:01 +00:00
|
|
|
return self:del(config, section, option)
|
2008-05-06 14:28:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Session.t_get(self, config, section, option)
|
|
|
|
if option then
|
|
|
|
return uci.get(config, section, option)
|
2008-05-05 19:27:30 +00:00
|
|
|
else
|
2008-05-06 14:28:51 +00:00
|
|
|
return uci.get(config, section)
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-05-06 14:28:51 +00:00
|
|
|
function Session.t_revert(self, config)
|
|
|
|
return uci.revert(config)
|
2008-05-05 19:27:30 +00:00
|
|
|
end
|
|
|
|
|
2008-05-06 14:28:51 +00:00
|
|
|
function Session.t_sections(self, config)
|
2008-06-03 22:42:01 +00:00
|
|
|
return uci.get_all(config)
|
2008-05-06 14:28:51 +00:00
|
|
|
end
|
2008-05-05 19:27:30 +00:00
|
|
|
|
2008-05-06 14:28:51 +00:00
|
|
|
function Session.t_set(self, config, section, option, value)
|
|
|
|
if option then
|
2008-06-03 22:42:01 +00:00
|
|
|
return uci.set(config, section, option, value)
|
2008-05-06 14:28:51 +00:00
|
|
|
else
|
2008-06-03 22:42:01 +00:00
|
|
|
return uci.set(config, section, value)
|
2008-05-06 14:28:51 +00:00
|
|
|
end
|
|
|
|
end
|
2008-05-05 19:27:30 +00:00
|
|
|
|