* luci/build: add uvl2cbi code gnerator and license foo
This commit is contained in:
parent
0ba0030745
commit
1a830a559b
2 changed files with 116 additions and 13 deletions
|
@ -1,4 +1,19 @@
|
|||
#!/usr/bin/lua
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
|
||||
Copyright 2008 Steven Barth <steven@midlink.org>
|
||||
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
|
||||
|
||||
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
|
||||
|
||||
$Id: index.lua 3548 2008-10-09 20:28:07Z Cyrus $
|
||||
]]--
|
||||
|
||||
local cbi = require "luci.cbi"
|
||||
local i18n = require "luci.i18n"
|
||||
local util = require "luci.util"
|
||||
|
@ -34,45 +49,45 @@ for i, sec in pairs(map.children) do if util.instanceof(sec, cbi.TypedSection) t
|
|||
print ("\nconfig section")
|
||||
print (" option name '%s'" % sec.sectiontype)
|
||||
print (" option package '%s'" % map.config)
|
||||
|
||||
|
||||
if #sec.title > 0 then
|
||||
print (" option title '%s'" % util.striptags(sec.title))
|
||||
end
|
||||
|
||||
|
||||
if #sec.description > 0 then
|
||||
print (" option description '%s'" % util.striptags(sec.description))
|
||||
end
|
||||
|
||||
|
||||
if not sec.addremove then
|
||||
print (" option unique true")
|
||||
print (" option required true")
|
||||
end
|
||||
|
||||
|
||||
if not sec.anonymous then
|
||||
print (" option named true")
|
||||
end
|
||||
|
||||
|
||||
if sec.dynamic then
|
||||
print (" option dynamic true")
|
||||
end
|
||||
|
||||
|
||||
for j, opt in ipairs(sec.children) do
|
||||
if opt.option:sub(1,1) ~= "_" or util.instanceof(opt, cbi.Value) then
|
||||
if opt.option:sub(1,1) ~= "_" or util.instanceof(opt, cbi.Value) then
|
||||
print ("\nconfig variable")
|
||||
print (" option name '%s'" % opt.option)
|
||||
print (" option section '%s.%s'" % {map.config, sec.sectiontype})
|
||||
if #opt.title > 0 then
|
||||
print (" option title '%s'" % util.striptags(opt.title))
|
||||
end
|
||||
|
||||
|
||||
if #opt.description > 0 then
|
||||
print (" option description '%s'" % util.striptags(opt.description))
|
||||
end
|
||||
|
||||
|
||||
if not opt.rmempty and not opt.optional then
|
||||
print (" option required true")
|
||||
end
|
||||
|
||||
|
||||
if util.instanceof(opt, cbi.Flag) then
|
||||
print (" option datatype boolean")
|
||||
elseif util.instanceof(opt, cbi.DynamicList) then
|
||||
|
@ -82,20 +97,20 @@ for i, sec in pairs(map.children) do if util.instanceof(sec, cbi.TypedSection) t
|
|||
util.perror("*** Warning: Please verify '%s.%s.%s' ***" %
|
||||
{map.config, sec.sectiontype, opt.option} )
|
||||
end
|
||||
|
||||
|
||||
for i, dep in ipairs(opt.deps) do
|
||||
if not dep.add or dep.add == "" then
|
||||
local depstring
|
||||
for k, v in pairs(dep.deps) do
|
||||
depstring = (depstring and depstring .. "," or "") .. "%s=%s" % {k, v}
|
||||
end
|
||||
end
|
||||
print (" list depends '%s'" % depstring)
|
||||
else
|
||||
util.perror("*** Warning: Unable to decode dependency '%s' in '%s.%s.%s[%s]' ***" %
|
||||
{util.serialize_data(dep.deps), map.config, sec.sectiontype, opt.option, dep.add})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if util.instanceof(opt, cbi.ListValue) then
|
||||
for k, key in ipairs(opt.keylist) do
|
||||
print ("\nconfig enum")
|
||||
|
|
88
build/uvl2cbi.lua
Normal file
88
build/uvl2cbi.lua
Normal file
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/lua
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
|
||||
Copyright 2008 Steven Barth <steven@midlink.org>
|
||||
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
|
||||
|
||||
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
|
||||
|
||||
$Id$
|
||||
]]--
|
||||
|
||||
local uvl = require "luci.uvl"
|
||||
local util = require "luci.util"
|
||||
|
||||
if not arg[1] then
|
||||
util.perror("Usage %s scheme_name" % arg[0])
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
|
||||
|
||||
local scheme, error = uvl.UVL():get_scheme(arg[1])
|
||||
|
||||
if not scheme then
|
||||
print( error:string() )
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
|
||||
print('cbimap = Map(%q, %q, %q)\n'
|
||||
% { scheme.name, scheme.title or scheme.name, scheme.description or "" } )
|
||||
|
||||
|
||||
for sn, sv in util.kspairs(scheme.sections) do
|
||||
print('%s = cbimap:section(TypedSection, %q, %q, %q)'
|
||||
% { sn, sn, sv.title or "", sv.description or "" } )
|
||||
|
||||
if not sv.named then print('%s.anonymous = true' % sn) end
|
||||
if not sv.unique then print('%s.addremove = true' % sn) end
|
||||
if sv.dynamic then print('%s.dynamic = true' % sn) end
|
||||
|
||||
if sv.depends then
|
||||
for _, dep in ipairs(sv.depends) do
|
||||
print('%s:depends(%s)' % { sn, util.serialize_data(dep) } )
|
||||
end
|
||||
end
|
||||
|
||||
print('')
|
||||
|
||||
for vn, vv in util.kspairs(scheme.variables[sn]) do
|
||||
if not vv.type or vv.type == "variable" then
|
||||
print('%s = %s:option(%s, %q, %q, %q)'
|
||||
% { vn, sn, vv.datatype == "boolean" and "Flag" or "Value",
|
||||
vn, vv.title or "", vv.description or "" } )
|
||||
elseif vv.type == "enum" then
|
||||
print('%s = %s:option(%s, %q, %q, %q)'
|
||||
% { vn, sn, vv.multival and "MultiValue" or "ListValue",
|
||||
vn, vv.title or "", vv.description or "" } )
|
||||
|
||||
for _, val in ipairs(vv.valuelist or {}) do
|
||||
print('%s:value(%q, %q)'
|
||||
% { vn, val.value, val.title or val.value } )
|
||||
end
|
||||
elseif vv.type == "list" or vv.type == "lazylist" then
|
||||
print('%s = %s:option(DynamicList, %q, %q, %q)'
|
||||
% { vn, sn, vn, vv.title or "", vv.description or "" } )
|
||||
else
|
||||
print('-- option: type(%s) ?' % { vv.type or "" } )
|
||||
end
|
||||
|
||||
if vv.default then print('%s.default = %q' % { vn, vv.default } ) end
|
||||
if vv.required then print('%s.optional = false' % vn ) end
|
||||
if not vv.required then print('%s.rmempty = true' % vn ) end
|
||||
|
||||
for _, dep in ipairs(vv.depends or {}) do
|
||||
print('%s:depends(%s)' % { vn, util.serialize_data(dep) } )
|
||||
end
|
||||
|
||||
print('')
|
||||
end
|
||||
|
||||
print('\nreturn cbimap')
|
||||
end
|
Loading…
Reference in a new issue