3 LuCI - Lua Configuration Interface
5 Copyright 2008 Steven Barth <steven@midlink.org>
6 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 $Id: index.lua 3548 2008-10-09 20:28:07Z Cyrus $
17 local cbi = require "luci.cbi"
18 local i18n = require "luci.i18n"
19 local util = require "luci.util"
22 util.perror("Usage %s path/to/cbi/model.lua [i18nfilename]" % arg[0])
26 i18n.load("default", "en")
27 i18n.load("admin-core", "en")
28 i18n.load("wifi", "en")
31 i18n.load(arg[2], "en")
34 local map = cbi.load(arg[1])[1]
37 print ("package "..map.config)
38 print ("\nconfig package")
40 if #map.title > 0 then
41 print (" option title '%s'" % util.striptags(map.title))
44 if #map.description > 0 then
45 print (" option description '%s'" % util.striptags(map.description))
48 for i, sec in pairs(map.children) do if util.instanceof(sec, cbi.TypedSection) then
49 print ("\nconfig section")
50 print (" option name '%s'" % sec.sectiontype)
51 print (" option package '%s'" % map.config)
53 if #sec.title > 0 then
54 print (" option title '%s'" % util.striptags(sec.title))
57 if #sec.description > 0 then
58 print (" option description '%s'" % util.striptags(sec.description))
61 if not sec.addremove then
62 print (" option unique true")
63 print (" option required true")
66 if not sec.anonymous then
67 print (" option named true")
71 print (" option dynamic true")
74 for j, opt in ipairs(sec.children) do
75 if opt.option:sub(1,1) ~= "_" or util.instanceof(opt, cbi.Value) then
76 print ("\nconfig variable")
77 print (" option name '%s'" % opt.option)
78 print (" option section '%s.%s'" % {map.config, sec.sectiontype})
79 if #opt.title > 0 then
80 print (" option title '%s'" % util.striptags(opt.title))
83 if #opt.description > 0 then
84 print (" option description '%s'" % util.striptags(opt.description))
87 if not opt.rmempty and not opt.optional then
88 print (" option required true")
91 if util.instanceof(opt, cbi.Flag) then
92 print (" option datatype boolean")
93 elseif util.instanceof(opt, cbi.DynamicList) then
94 print (" option type list")
95 elseif util.instanceof(opt, cbi.ListValue) then
96 print (" option type enum")
97 util.perror("*** Warning: Please verify '%s.%s.%s' ***" %
98 {map.config, sec.sectiontype, opt.option} )
101 for i, dep in ipairs(opt.deps) do
102 if not dep.add or dep.add == "" then
104 for k, v in pairs(dep.deps) do
105 depstring = (depstring and depstring .. "," or "") .. "%s=%s" % {k, v}
107 print (" list depends '%s'" % depstring)
109 util.perror("*** Warning: Unable to decode dependency '%s' in '%s.%s.%s[%s]' ***" %
110 {util.serialize_data(dep.deps), map.config, sec.sectiontype, opt.option, dep.add})
114 if util.instanceof(opt, cbi.ListValue) then
115 for k, key in ipairs(opt.keylist) do
116 print ("\nconfig enum")
117 print (" option variable '%s.%s.%s'" % {map.config, sec.sectiontype, opt.option})
118 print (" option value '%s'" % key)
119 if opt.vallist[k] and opt.vallist[k] ~= opt.keylist[k] then
120 print (" option title '%s'" % util.striptags(opt.vallist[k]))