build: remove some obsolete support scripts
[project/luci.git] / libs / uvl / luasrc / uvl / dependencies.lua
index 3aa3c73..33f2fad 100644 (file)
@@ -14,38 +14,35 @@ $Id$
 
 ]]--
 
-module( "luci.uvl.dependencies", package.seeall )
+local uvl = require "luci.uvl"
+local ERR = require "luci.uvl.errors".error
+local util = require "luci.util"
+local table = require "table"
+
+local type, unpack = type, unpack
+local ipairs, pairs = ipairs, pairs
+
+module "luci.uvl.dependencies"
+
 
-local ERR = luci.uvl.errors
 
 function _parse_reference( r, c, s, o )
        local ref  = { }
        local vars = {
-               config  = ( c or '$config'  ),
-               section = ( s or '$section' ),
-               option  = ( o or '$option'  )
+               config  = c,
+               section = s,
+               option  = o
        }
 
-       for i, v in ipairs(luci.util.split(r,".")) do
-               table.insert(ref, (v:gsub( "%$(.+)", function(n) return vars[n] end )))
+       for v in r:gmatch("[^.]+") do
+               ref[#ref+1] = (v:gsub( "%$(.+)", vars ))
        end
-
-       if c or s then
-               if #ref == 1 and c and s then
-                       ref = { c, s, ref[1] }
-               elseif #ref == 2 and c then
-                       ref = { c, unpack(ref) }
-               elseif #ref ~= 3 then
-                       ref = nil
-               end
-       else
-               if #ref == 1 then
-                       ref = { '$config', '$section', ref[1] }
-               elseif #ref == 2 then
-                       ref = { '$config', unpack(ref) }
-               elseif #ref ~= 3 then
-                       ref = nil
-               end
+       
+       if #ref < 2 then
+               table.insert(ref, 1, s or '$section')
+       end
+       if #ref < 3 then
+               table.insert(ref, 1, c or '$config')
        end
 
        return ref
@@ -54,7 +51,7 @@ end
 function _serialize_dependency( dep, v )
        local str
 
-       for k, v in luci.util.spairs( dep,
+       for k, v in util.spairs( dep,
                function(a,b)
                        a = ( type(dep[a]) ~= "boolean" and "_" or "" ) .. a
                        b = ( type(dep[b]) ~= "boolean" and "_" or "" ) .. b
@@ -70,12 +67,12 @@ end
 
 function check( self, object, nodeps )
 
-       local derr = ERR.DEPENDENCY(object)
+       local derr = ERR('DEPENDENCY', object)
 
        if not self.depseen[object:cid()] then
                self.depseen[object:cid()] = true
        else
-               return false, derr:child(ERR.DEP_RECURSIVE(object))
+               return false, derr:child(ERR('DEP_RECURSIVE', object))
        end
 
        if object:scheme('depends') then
@@ -89,10 +86,10 @@ function check( self, object, nodeps )
                                local ref = _parse_reference( k, unpack(object.cref) )
 
                                if not ref then
-                                       return false, derr:child(ERR.SME_BADDEP(object,k))
+                                       return false, derr:child(ERR('SME_BADDEP',object,k))
                                end
 
-                               local option = luci.uvl.option( self, object.c, unpack(ref) )
+                               local option = uvl.option( self, object.c, unpack(ref) )
 
                                valid, err = self:_validate_option( option, true )
                                if valid then
@@ -105,8 +102,8 @@ function check( self, object, nodeps )
                                                local depstr = _serialize_dependency( dep, v )
                                                derr:child(
                                                        type(v) == "boolean"
-                                                               and ERR.DEP_NOVALUE(option, depstr)
-                                                               or  ERR.DEP_NOTEQUAL(option, {depstr, v})
+                                                               and ERR('DEP_NOVALUE', option, depstr)
+                                                               or  ERR('DEP_NOTEQUAL', option, {depstr, v})
                                                )
 
                                                break
@@ -115,7 +112,7 @@ function check( self, object, nodeps )
                                        subcondition = false
 
                                        local depstr = _serialize_dependency( dep, v )
-                                       derr:child(ERR.DEP_NOTVALID(option, depstr):child(err))
+                                       derr:child(ERR('DEP_NOTVALID', option, depstr):child(err))
 
                                        break
                                end
@@ -142,7 +139,7 @@ function check( self, object, nodeps )
                local ok    = true
                local valid = false
                local enum  = object:enum()
-               local eerr  = ERR.DEP_BADENUM(enum)
+               local eerr  = ERR('DEP_BADENUM', enum)
 
                for _, dep in ipairs(enum:scheme('enum_depends')[object:value()]) do
                        local subcondition = true
@@ -151,7 +148,7 @@ function check( self, object, nodeps )
                                local ref = _parse_reference( k, unpack(object.cref) )
 
                                if not ref then
-                                       return false, derr:child(eerr:child(ERR.SME_BADDEP(enum,k)))
+                                       return false, derr:child(eerr:child(ERR('SME_BADDEP',enum,k)))
                                end
 
                                local option = luci.uvl.option( self, object.c, unpack(ref) )
@@ -167,8 +164,8 @@ function check( self, object, nodeps )
                                                local depstr = _serialize_dependency( dep, v )
                                                eerr:child(
                                                        type(v) == "boolean"
-                                                               and ERR.DEP_NOVALUE(option, depstr)
-                                                               or  ERR.DEP_NOTEQUAL(option, {depstr, v})
+                                                               and ERR('DEP_NOVALUE', option, depstr)
+                                                               or  ERR('DEP_NOTEQUAL', option, {depstr, v})
                                                )
 
                                                break
@@ -177,7 +174,7 @@ function check( self, object, nodeps )
                                        subcondition = false
 
                                        local depstr = _serialize_dependency( dep, v )
-                                       eerr:child(ERR.DEP_NOTVALID(option, depstr):child(err))
+                                       eerr:child(ERR('DEP_NOTVALID', option, depstr):child(err))
 
                                        break
                                end