-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEMControllerManagerHeaderGenerator.py
54 lines (46 loc) · 1.24 KB
/
EMControllerManagerHeaderGenerator.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
#!/usr/bin/env python
#coding:utf8
import getopt
import json
import sys
import plistlib
def generate_definition(input_file, output_path, prefix):
with open(input_file, 'r') as f:
raw_string = f.read()
try:
config_dict = json.loads(raw_string)
except Exception, e:
config_dict = plistlib.readPlistFromString(raw_string)
if not isinstance(config_dict,dict):
sys.stderr.write('configuration file is not failed')
exit(-1)
with open(output_path, 'w') as o:
o.write('/* Generated by EMControllerManagerHeaderGenerator, do not edit it manually. */\n\n\n')
for controller_name in config_dict:
if prefix is None:
def_name = controller_name
else:
def_name = "%s_%s" % (prefix, controller_name)
o.write('#define %s @"%s"\n' % (def_name, controller_name))
def main():
try:
options, args = getopt.getopt(sys.argv[1:],'i:o:p:')
except Exception, e:
print str(e)
raise e
input_file = None
output_path = None
prefix = None
for o, a in options:
if o == '-i':
input_file = a
elif o == '-o':
output_path = a
elif o == '-p':
prefix = a
if input_file is None or output_path is None:
print "input error"
exit(-1)
generate_definition (input_file, output_path, prefix)
if __name__ == '__main__':
main()