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("base", "en")
29 i18n.load(arg[2], "en")
35 require "luci.model.uci".cursor = function(config, save)
36 return uci.cursor(config or arg[3] .. "/etc/config", save or arg[3] .. "/tmp/.uci")
41 local map = cbi.load(arg[1])[1]
44 print ("package "..map.config)
45 print ("\nconfig package")
47 if #map.title > 0 then
48 print (" option title '%s'" % util.striptags(map.title))
51 if #map.description > 0 then
52 print (" option description '%s'" % util.striptags(map.description))
55 for i, sec in pairs(map.children) do if util.instanceof(sec, cbi.AbstractSection) then
56 print ("\nconfig section")
57 print (" option name '%s'" % sec.sectiontype)
58 print (" option package '%s'" % map.config)
60 if #sec.title > 0 then
61 print (" option title '%s'" % util.striptags(sec.title))
64 if #sec.description > 0 then
65 print (" option description '%s'" % util.striptags(sec.description))
68 if not sec.addremove then
69 print (" option unique true")
70 print (" option required true")
73 if not sec.anonymous then
74 print (" option named true")
78 print (" option dynamic true")
81 for j, opt in ipairs(sec.children) do
82 if opt.option:sub(1,1) ~= "_" or util.instanceof(opt, cbi.Value) then
83 print ("\nconfig variable")
84 print (" option name '%s'" % opt.option)
85 print (" option section '%s.%s'" % {map.config, sec.sectiontype})
86 if #opt.title > 0 then
87 print (" option title '%s'" % util.striptags(opt.title))
90 if #opt.description > 0 then
91 print (" option description '%s'" % util.striptags(opt.description))
94 if not opt.rmempty and not opt.optional then
95 print (" option required true")
98 if util.instanceof(opt, cbi.Flag) then
99 print (" option datatype boolean")
100 elseif util.instanceof(opt, cbi.DynamicList) then
101 print (" option type list")
102 elseif util.instanceof(opt, cbi.ListValue) then
103 print (" option type enum")
104 util.perror("*** Warning: Please verify '%s.%s.%s' ***" %
105 {map.config, sec.sectiontype, opt.option} )
108 for i, dep in ipairs(opt.deps) do
109 if not dep.add or dep.add == "" then
111 for k, v in pairs(dep.deps) do
112 depstring = (depstring and depstring .. "," or "") .. "%s=%s" % {k, v}
114 print (" list depends '%s'" % depstring)
116 util.perror("*** Warning: Unable to decode dependency '%s' in '%s.%s.%s[%s]' ***" %
117 {util.serialize_data(dep.deps), map.config, sec.sectiontype, opt.option, dep.add})
121 if util.instanceof(opt, cbi.ListValue) then
122 for k, key in ipairs(opt.keylist) do
123 print ("\nconfig enum")
124 print (" option variable '%s.%s.%s'" % {map.config, sec.sectiontype, opt.option})
125 print (" option value '%s'" % key)
126 if opt.vallist[k] and opt.vallist[k] ~= opt.keylist[k] then
127 print (" option title '%s'" % util.striptags(opt.vallist[k]))