forked from nemomobile/mce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_to_c.py
executable file
·70 lines (51 loc) · 1.63 KB
/
schema_to_c.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# ----------------------------------------------------------------------------
# Copyright (C) 2012 Jolla Ltd.
# Contact: Simo Piiroinen <[email protected]>
# License: LGPLv2
# ----------------------------------------------------------------------------
# reads mce gconf schemas and writes C structure array
# compatible with builtin-gconf.c
import sys,os
from types import *
from xml.etree.ElementTree import ElementTree
typemap = {
'bool' : 'b',
'int' : 'i',
}
if __name__ == "__main__":
args = sys.argv[1:]
args.reverse()
src = []
_ = src.append
elems = []
while args:
path = args.pop()
tree = ElementTree()
root = tree.parse(path)
data = root.find("schemalist")
for elem in data.iter("schema"):
_("")
e_key = elem.find("applyto").text
e_type = elem.find("type").text
e_def = elem.find("default").text
e_arr = ''
if e_type == "list":
e_arr = 'a'
e_type = elem.find("list_type").text
e_def = e_def.replace("[","").replace("]","")
e_def = map(lambda x:x.strip(), e_def.split(","))
e_def = ",".join(e_def)
e_type = e_arr + typemap.get(e_type, '?')
elems.append((e_key, e_type, e_def))
_("")
_('static setting_t elems[] =')
_("{")
for e_key, e_type, e_def in elems:
_(' {')
_(' .key = "%s",' % e_key)
_(' .type = "%s",' % e_type)
_(' .def = "%s",' % e_def)
_(' },')
_('};')
print "\n".join(src)