10d956738a14b3c61001b68c25edbcda5e686731
[project/luci.git] / build / cbi2uvl.lua
1 #!/usr/bin/lua
2 --[[
3 LuCI - Lua Configuration Interface
4
5 Copyright 2008 Steven Barth <steven@midlink.org>
6 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7
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
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14 $Id: index.lua 3548 2008-10-09 20:28:07Z Cyrus $
15 ]]--
16
17 local cbi = require "luci.cbi"
18 local i18n = require "luci.i18n"
19 local util = require "luci.util"
20
21 if not arg[1] then
22 util.perror("Usage %s path/to/cbi/model.lua [i18nfilename]" % arg[0])
23 os.exit(1)
24 end
25
26 i18n.load("default", "en")
27 i18n.load("admin-core", "en")
28 i18n.load("wifi", "en")
29
30 if arg[2] then
31 i18n.load(arg[2], "en")
32 end
33
34 local map = cbi.load(arg[1])[1]
35 assert(map)
36
37 print ("package "..map.config)
38 print ("\nconfig package")
39
40 if #map.title > 0 then
41 print (" option title '%s'" % util.striptags(map.title))
42 end
43
44 if #map.description > 0 then
45 print (" option description '%s'" % util.striptags(map.description))
46 end
47
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)
52
53 if #sec.title > 0 then
54 print (" option title '%s'" % util.striptags(sec.title))
55 end
56
57 if #sec.description > 0 then
58 print (" option description '%s'" % util.striptags(sec.description))
59 end
60
61 if not sec.addremove then
62 print (" option unique true")
63 print (" option required true")
64 end
65
66 if not sec.anonymous then
67 print (" option named true")
68 end
69
70 if sec.dynamic then
71 print (" option dynamic true")
72 end
73
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))
81 end
82
83 if #opt.description > 0 then
84 print (" option description '%s'" % util.striptags(opt.description))
85 end
86
87 if not opt.rmempty and not opt.optional then
88 print (" option required true")
89 end
90
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} )
99 end
100
101 for i, dep in ipairs(opt.deps) do
102 if not dep.add or dep.add == "" then
103 local depstring
104 for k, v in pairs(dep.deps) do
105 depstring = (depstring and depstring .. "," or "") .. "%s=%s" % {k, v}
106 end
107 print (" list depends '%s'" % depstring)
108 else
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})
111 end
112 end
113
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]))
121 end
122 end
123 end
124 end
125 end
126 end end