modules/freifunk: Set uhttpd.main.rfc1918_filter=0 via uci-defaults/freifunk to allow...
[project/luci.git] / build / uvl2cbi.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$
15 ]]--
16
17 local uvl  = require "luci.uvl"
18 local util = require "luci.util"
19
20 if not arg[1] then
21         util.perror("Usage %s scheme_name" % arg[0])
22         os.exit(1)
23 end
24
25
26
27 local scheme, error = uvl.UVL():get_scheme(arg[1])
28
29 if not scheme then
30         print( error:string() )
31         os.exit(1)
32 end
33
34
35 print('cbimap = Map(%q, %q, %q)\n'
36         % { scheme.name, scheme.title or scheme.name, scheme.description or "" } )
37
38
39 for sn, sv in util.kspairs(scheme.sections) do
40         print('%s = cbimap:section(TypedSection, %q, %q, %q)'
41                 % { sn, sn, sv.title or "", sv.description or "" } )
42
43         if not sv.named   then print('%s.anonymous = true' % sn) end
44         if not sv.unique  then print('%s.addremove = true' % sn) end
45         if     sv.dynamic then print('%s.dynamic = true'   % sn) end
46
47         if sv.depends then
48                 for _, dep in ipairs(sv.depends) do
49                         print('%s:depends(%s)' % { sn, util.serialize_data(dep) } )
50                 end
51         end
52
53         print('')
54
55         for vn, vv in util.kspairs(scheme.variables[sn]) do
56                 if not vv.type or vv.type == "variable" then
57                         print('%s = %s:option(%s, %q, %q, %q)'
58                                 % { vn, sn, vv.datatype == "boolean" and "Flag" or "Value",
59                                         vn, vv.title or "", vv.description or "" } )
60                 elseif vv.type == "enum" then
61                         print('%s = %s:option(%s, %q, %q, %q)'
62                                 % { vn, sn, vv.multival and "MultiValue" or "ListValue",
63                                         vn, vv.title or "", vv.description or "" } )
64
65                         for _, val in ipairs(vv.valuelist or {}) do
66                                 print('%s:value(%q, %q)'
67                                         % { vn, val.value, val.title or val.value } )
68                         end
69                 elseif vv.type == "list" or vv.type == "lazylist" then
70                         print('%s = %s:option(DynamicList, %q, %q, %q)'
71                                 % { vn, sn, vn, vv.title or "", vv.description or "" } )
72                 else
73                         print('-- option: type(%s) ?' % { vv.type or "" } )
74                 end
75
76                 if     vv.default  then print('%s.default = %q'     % { vn, vv.default } ) end
77                 if     vv.required then print('%s.optional = false' % vn ) end
78                 if not vv.required then print('%s.rmempty = true'   % vn ) end
79
80                 for _, dep in ipairs(vv.depends or {}) do
81                         print('%s:depends(%s)' % { vn, util.serialize_data(dep) } )
82                 end
83
84                 print('')
85         end
86
87         print('\nreturn cbimap')
88 end