tools/configcollector.py

changeset 1308
dcc8c02530c2
parent 1157
1d6d244bdabd
child 1323
05b3e173c900
equal deleted inserted replaced
1307:adb9d32a1426 1308:dcc8c02530c2
57 float(value) 57 float(value)
58 return 'double' 58 return 'double'
59 except: 59 except:
60 pass 60 pass
61 61
62 if endswith(value, 'f'): 62 if value.endswith('f'):
63 try: 63 try:
64 float(value[:-1]) 64 float(value[:-1])
65 return 'float' 65 return 'float'
66 except: 66 except:
67 pass 67 pass
74 self.qtTypes = set() 74 self.qtTypes = set()
75 self.args = args 75 self.args = args
76 76
77 def collect(self, filename): 77 def collect(self, filename):
78 with open(filename) as file: 78 with open(filename) as file:
79 for line in file: 79 for linenumber, line in enumerate(file, 1):
80 line = line.strip() 80 try:
81 if line and not line.startswith('#'): 81 line = line.strip()
82 from re import search 82 if line and not line.startswith('#'):
83 match = search('^option (\w+) = (.+)$', line) 83 from re import search
84 if not match: 84 match = search('^option (\w+) = (.+)$', line)
85 raise ValueError('unable to parse: %r' % line) 85 if not match:
86 name, value = match.groups() 86 raise ValueError('unable to parse: %r' % line)
87 match = search(r'^(\w+)\s*\{(.*)\}$', value) 87 name, value = match.groups()
88 try: 88 match = search(r'^([a-zA-Z0-9_<>]+)\s*\{(.*)\}$', value)
89 typename, value = match.groups() 89 try:
90 if not value: 90 typename, value = match.groups()
91 value = typename + ' {}' 91 if not value:
92 except: 92 value = typename + ' {}'
93 typename = deduce_type(value) 93 except:
94 self.declare(name, typename, value) 94 typename = deduce_type(value)
95 self.declare(name, typename, value)
96 except ValueError as error:
97 from sys import stderr, exit
98 print(str.format(
99 '{file}:{line}: {error}',
100 file = filename,
101 line = linenumber,
102 error = str(error),
103 ), file = stderr)
104 exit(1)
95 # Sort the declarations in alphabetical order 105 # Sort the declarations in alphabetical order
96 self.declarations = OrderedDict(sorted(self.declarations.items(), key = lambda t: t[1]['name'])) 106 self.declarations = OrderedDict(sorted(self.declarations.items(), key = lambda t: t[1]['name']))
97 # Fill in additional information 107 # Fill in additional information
98 for declaration in self.declarations.values(): 108 for declaration in self.declarations.values():
99 declaration['readgate'] = caseconversions.convert_case(declaration['name'], style='java') 109 declaration['readgate'] = caseconversions.convert_case(declaration['name'], style='java')

mercurial