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")
37 require "luci.model.uci".cursor = function(config, save)
38 return uci.cursor(config or arg[3] .. "/etc/config", save or arg[3] .. "/tmp/.uci")
43 local map = cbi.load(arg[1])[1]
46 print ("package "..map.config)
47 print ("\nconfig package")
49 if #map.title > 0 then
50 print (" option title '%s'" % util.striptags(map.title))
53 if #map.description > 0 then
54 print (" option description '%s'" % util.striptags(map.description))
57 for i, sec in pairs(map.children) do if util.instanceof(sec, cbi.AbstractSection) then
58 print ("\nconfig section")
59 print (" option name '%s'" % sec.sectiontype)
60 print (" option package '%s'" % map.config)
62 if #sec.title > 0 then
63 print (" option title '%s'" % util.striptags(sec.title))
66 if #sec.description > 0 then
67 print (" option description '%s'" % util.striptags(sec.description))
70 if not sec.addremove then
71 print (" option unique true")
72 print (" option required true")
75 if not sec.anonymous then
76 print (" option named true")
80 print (" option dynamic true")
83 for j, opt in ipairs(sec.children) do
84 if opt.option:sub(1,1) ~= "_" or util.instanceof(opt, cbi.Value) then
85 print ("\nconfig variable")
86 print (" option name '%s'" % opt.option)
87 print (" option section '%s.%s'" % {map.config, sec.sectiontype})
88 if #opt.title > 0 then
89 print (" option title '%s'" % util.striptags(opt.title))
92 if #opt.description > 0 then
93 print (" option description '%s'" % util.striptags(opt.description))
96 if not opt.rmempty and not opt.optional then
97 print (" option required true")
100 if util.instanceof(opt, cbi.Flag) then
101 print (" option datatype boolean")
102 elseif util.instanceof(opt, cbi.DynamicList) then
103 print (" option type list")
104 elseif util.instanceof(opt, cbi.ListValue) then
105 print (" option type enum")
106 util.perror("*** Warning: Please verify '%s.%s.%s' ***" %
107 {map.config, sec.sectiontype, opt.option} )
110 for i, dep in ipairs(opt.deps) do
111 if not dep.add or dep.add == "" then
113 for k, v in pairs(dep.deps) do
114 depstring = (depstring and depstring .. "," or "") .. "%s=%s" % {k, v}
116 print (" list depends '%s'" % depstring)
118 util.perror("*** Warning: Unable to decode dependency '%s' in '%s.%s.%s[%s]' ***" %
119 {util.serialize_data(dep.deps), map.config, sec.sectiontype, opt.option, dep.add})
123 if util.instanceof(opt, cbi.ListValue) then
124 for k, key in ipairs(opt.keylist) do
125 print ("\nconfig enum")
126 print (" option variable '%s.%s.%s'" % {map.config, sec.sectiontype, opt.option})
127 print (" option value '%s'" % key)
128 if opt.vallist[k] and opt.vallist[k] ~= opt.keylist[k] then
129 print (" option title '%s'" % util.striptags(opt.vallist[k]))