diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-08-24 14:20:20 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-08-24 14:20:20 +0000 |
commit | 23101e71374383bdd1bae09166c2581daaa44b22 (patch) | |
tree | 60665a3c82de7ed4e6103324a2701525c608f025 /libs/uvl/luasrc/uvl.lua | |
parent | 606f7dc31317f110a98bbdb64baf00d6064bac2c (diff) |
* luci/libs: uvl: implement get_scheme() and get_dependencies()
Diffstat (limited to 'libs/uvl/luasrc/uvl.lua')
-rw-r--r-- | libs/uvl/luasrc/uvl.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/libs/uvl/luasrc/uvl.lua b/libs/uvl/luasrc/uvl.lua index 292a3ba0d8..a9359d0c35 100644 --- a/libs/uvl/luasrc/uvl.lua +++ b/libs/uvl/luasrc/uvl.lua @@ -74,11 +74,68 @@ function UVL.__init__( self, schemedir ) self.packages = { } self.beenthere = { } self.uci = luci.model.uci + self.dep = luci.uvl.dependencies self.log = luci.uvl.loghelper self.datatypes = luci.uvl.datatypes end +--- Parse given scheme and return the scheme tree. +-- @param scheme Name of the scheme to parse +-- @return Table containing the parsed scheme or nil on error +-- @return String containing the reason for errors (if any) +function UVL.get_scheme( self, scheme ) + if not self.packages[scheme] then + local ok, err = pcall( self.read_scheme, self, scheme ) + if not ok then + return nil, self.log.scheme_error( scheme, err ) + end + end + return self.packages[scheme], nil +end + +--- Return a table containing the dependencies of specified section or option. +-- @param config Name of the configuration or parsed scheme object +-- @param section Type of the section +-- @param option Name of the option (optional) +-- @return Table containing the dependencies or nil on error +-- @return String containing the reason for errors (if any) +function UVL.get_dependencies( self, config, section, option ) + config = ( type(config) == "string" and self:get_scheme(config) or config ) + + local deps = { } + local dt + + if not config.sections[section] then return deps end + + if option and config.variables[section][option] then + dt = config.variables[section][option].depends + else + dt = config.sections[section].depends + end + + if dt then + for _, d in ipairs(dt) do + local sdeps = { } + for k, v in pairs(d) do + local r = self.dep._parse_reference( k ) + if r then + sdeps[r] = v + else + return nil, string.format( + 'Ambiguous dependency reference "%s" for object ' .. + '"%s.%s%s" given', + k, config.name, section, + option and '.' .. option or '' + ) + end + end + table.insert( deps, sdeps ) + end + end + return deps +end + --- Validate given configuration, section or option. -- @param config Name of the configuration to validate -- @param section Name of the section to validate (optional) @@ -423,6 +480,7 @@ function UVL._read_scheme_parts( self, scheme, schemes ) self.packages[r[1]] = self.packages[r[1]] or { + ["name"] = r[1]; ["sections"] = { }; ["variables"] = { }; } |