tools/configcollector.py

Thu, 17 Nov 2016 12:18:13 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 17 Nov 2016 12:18:13 +0200
changeset 1055
c28d07a583ac
parent 1017
fc1c13db9618
child 1125
d8f94e56d42e
permissions
-rw-r--r--

Cleaned up PrimitiveScanner

971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 # coding: utf-8
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 #
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 # Copyright 2015 Teemu Piippo
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 # All rights reserved.
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 #
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 # Redistribution and use in source and binary forms, with or without
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 # modification, are permitted provided that the following conditions
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 # are met:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 #
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 # 1. Redistributions of source code must retain the above copyright
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 # notice, this list of conditions and the following disclaimer.
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 # 2. Redistributions in binary form must reproduce the above copyright
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 # notice, this list of conditions and the following disclaimer in the
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 # documentation and/or other materials provided with the distribution.
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 # 3. Neither the name of the copyright holder nor the names of its
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 # contributors may be used to endorse or promote products derived from
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 # this software without specific prior written permission.
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 import argparse
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 import caseconversions
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 import collections
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 import outputfile
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 import re
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 from pprint import pprint
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 passbyvalue = {'int', 'bool', 'float', 'double' }
982
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
41 variantconversions = {
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
42 'QString': 'toString',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
43 'bool': 'toBool',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
44 'int': 'toInt',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
45 'float': 'toFloat',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
46 'double': 'toDouble',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
47 'QChar': 'toChar',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
48 'QBitArray': 'toBitArray',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
49 'QDate': 'toDate',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
50 'QDateTime': 'toDateTime',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
51 'uint': 'toUInt',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
52 'unsigned int': 'toUInt',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
53 'QUrl': 'toUrl',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
54 'QTime': 'toTime',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
55 'QPoint': 'toPoint',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
56 'QPointF': 'toPointF',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
57 'QSize': 'toSize',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
58 'QSizeF': 'toSizeF',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
59 'qreal': 'toReal',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
60 'QRect': 'toRect',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
61 'QRectF': 'toRectF',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
62 'QLine': 'toLine',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
63 'QLineF': 'toLineF',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
64 'QEasingCurve': 'toEasingCurve',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
65 'qlonglong': 'toLongLong',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
66 'qulonglong': 'toULongLong',
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
67 }
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 class ConfigCollector (object):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 def __init__ (self, args):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 self.pattern = re.compile (r'\s*ConfigOption\s*\((.+)\)\s*')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 self.declpattern = re.compile (r'^([A-Za-z0-9,<>\[\]\(\)\{\}\s]+)\s+(\w+)(\s*=\s*(.+))?$')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 self.decls = []
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 self.qttypes = set()
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 self.args = args
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 def collect (self, filenames):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 for filename in filenames:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 with open (filename, 'r') as fp:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 lines = fp.read().splitlines()
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 for line in lines:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 matches = self.pattern.findall (line)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 for match in matches:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 match = match.strip()
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 declarations = self.declpattern.findall (match)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 for decl in declarations:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 self.add_config_declaration (decl)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 self.decls.sort (key=lambda x: x['name'].upper())
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 def add_config_declaration (self, decl):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 decltype, declname, junk, decldefault = decl
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 if not decldefault:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 if decltype == 'int':
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 decldefault = '0'
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 elif decltype == 'float':
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 decldefault = '0.0f'
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 elif decltype == 'double':
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 decldefault = '0.0'
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 elif decltype == 'bool':
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 raise TypeError ('bool entries must provide a default value')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 else:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 decldefault = decltype + '()'
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 self.decls.append (dict (name=declname, type=decltype, default=decldefault))
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 # Take note of any Qt types we may want to #include in our source file (we'll need to #include them).
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 self.qttypes.update (re.findall (r'(Q[A-Za-z]+)', decltype))
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 def make_config_key_type (self, basetype):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 result = 'ConfigTypeKey_' + basetype
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 result = re.sub (r'[^\w]+', '_', result)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 return result
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 def make_enums (self):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 self.enums = collections.OrderedDict()
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 for decl in self.decls:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 enumname = self.make_config_key_type (decl['type'])
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 decl['enumerator'] = caseconversions.convert_case (decl['name'], style='upper')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 decl['enumname'] = enumname
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 decl['getter'] = caseconversions.convert_case (decl['name'], style='java')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 decl['varname'] = 'm_' + decl['getter']
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 decl['setter'] = 'set' + caseconversions.convert_case (decl['name'], style='camel')
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
126 decl['toggler'] = 'toggle' + caseconversions.convert_case (decl['name'], style='camel')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 decl['typecref'] = 'const %s&' % decl['type'] if decl['type'] not in passbyvalue else decl['type']
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128
982
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
129 try:
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
130 decl['valuefunc'] = variantconversions[decl['type']]
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
131 except KeyError:
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
132 decl['valuefunc'] = 'value<' + decl['type'] + '>'
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
133
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 if enumname not in self.enums:
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 self.enums[enumname] = dict (
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 name = enumname,
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 typename = decl['type'],
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 values = [],
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 numvalues = 0,
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 highestkey = -1)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 self.enums[enumname]['values'].append (decl)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 self.enums[enumname]['numvalues'] += 1
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 self.enums[enumname]['highestkey'] += 1
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 self.enums = collections.OrderedDict (sorted (self.enums.items(), key=lambda x: x[0].upper()))
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 for name, enum in self.enums.items():
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 for i, value in enumerate (enum['values']):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 value['index'] = i
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 def write_header (self, fp):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 fp.write ('#pragma once\n')
972
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
154 fp.write ('#include <QMap>\n')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 for qttype in sorted (self.qttypes):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 fp.write ('#include <%s>\n' % qttype)
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
157 fp.write ('\n')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 formatargs = {}
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 write = lambda value: fp.write (value)
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
160 write ('class Configuration\n')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 write ('{\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 write ('public:\n')
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
163 write ('\tConfiguration();\n')
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
164 write ('\t~Configuration();\n')
972
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
165 write ('\tbool existsEntry (const QString& name);\n')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 write ('\tQVariant defaultValueByName (const QString& name);\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 for decl in self.decls:
982
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
169 write ('\t{type} {getter}() const;\n'.format (**decl))
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 for decl in self.decls:
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
171 write ('\tvoid {setter}({typecref} value);\n'.format (**decl))
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
172
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
173 for decl in filter(lambda decl: decl['type'] == 'bool', self.decls):
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
174 write('\tvoid {toggler}();\n'.format(**decl))
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 write ('\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 write ('private:\n')
972
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
178 write ('\tQMap<QString, QVariant> m_defaults;\n')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 write ('\tclass QSettings* m_settings;\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 write ('};\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 def write_source (self, fp, headername):
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 fp.write ('#include <QSet>\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 fp.write ('#include <QSettings>\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 fp.write ('#include <QVariant>\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 fp.write ('#include "%s/mainwindow.h"\n' % (self.args.sourcedir))
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 fp.write ('#include "%s"\n' % headername)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 fp.write (
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 '\n'
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
192 'Configuration::Configuration() :\n'
1012
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 982
diff changeset
193 '\tm_settings (makeSettings (nullptr))\n'
972
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
194 '{\n')
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
195
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
196 for decl in self.decls:
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
197 fp.write ('\tm_defaults["{name}"] = QVariant::fromValue<{type}> ({default});\n'.format (**decl))
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
198
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
199 fp.write ('}\n'
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 '\n'
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
201 'Configuration::~Configuration()\n'
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 '{\n'
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 '\tm_settings->deleteLater();\n'
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 '}\n'
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 '\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 maptype = 'QMap<QString, QVariant>'
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
208 fp.write ('QVariant Configuration::defaultValueByName (const QString& name)\n')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 fp.write ('{\n')
972
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
210 fp.write ('\t%s::iterator it = m_defaults.find (name);\n' % maptype)
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
211 fp.write ('\tif (it != m_defaults.end())\n')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 fp.write ('\t\treturn *it;\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 fp.write ('\treturn QVariant();\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 fp.write ('}\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 fp.write ('\n')
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
216 fp.write ('bool Configuration::existsEntry (const QString& name)\n')
972
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
217 fp.write ('{\n')
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
218 fp.write ('\treturn m_defaults.find (name) != m_defaults.end();\n')
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
219 fp.write ('}\n')
a34b73114823 Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
220 fp.write ('\n')
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 for decl in self.decls:
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
223 fp.write ('{type} Configuration::{getter}() const\n'.format (**decl))
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 fp.write ('{\n')
982
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
225 fp.write ('\tstatic const QVariant defaultvalue = QVariant::fromValue<{type}> ({default});\n'.format (**decl))
a3a2e62a581b Optimize QVariant in ConfigurationValueBag
Teemu Piippo <crimsondusk64@gmail.com>
parents: 972
diff changeset
226 fp.write ('\treturn m_settings->value ("{name}", defaultvalue).{valuefunc}();\n'.format (**decl))
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 fp.write ('}\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 fp.write ('\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 for decl in self.decls:
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
231 fp.write ('void Configuration::{setter}({typecref} value)\n'.format (**decl))
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 fp.write ('{\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 fp.write ('\tif (value != {default})\n'.format (**decl))
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 fp.write ('\t\tm_settings->setValue ("{name}", QVariant::fromValue<{type}> (value));\n'.format (**decl))
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 fp.write ('\telse\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 fp.write ('\t\tm_settings->remove ("{name}");\n'.format (**decl))
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 fp.write ('}\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 fp.write ('\n')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
240 for decl in filter(lambda decl: decl['type'] == 'bool', self.decls):
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
241 fp.write('void Configuration::{toggler}()\n'.format(**decl))
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
242 fp.write('{\n')
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
243 fp.write('\t{setter}(not {getter}());\n'.format(**decl))
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
244 fp.write('}\n')
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
245 fp.write('\n')
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
246
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 def main():
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 parser = argparse.ArgumentParser (description='Collects a list of configuration objects')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 parser.add_argument ('inputs', nargs='+')
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 parser.add_argument ('--header', required=True)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 parser.add_argument ('--source', required=True)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 parser.add_argument ('--sourcedir', required=True)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 args = parser.parse_args()
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 collector = ConfigCollector (args)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 collector.collect (args.inputs)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 collector.make_enums()
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 header = outputfile.OutputFile (args.header)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 source = outputfile.OutputFile (args.source)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 collector.write_source (source, headername=args.header)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 collector.write_header (header)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 header.save (verbose = True)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 source.save (verbose = True)
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 if __name__ == '__main__':
1012
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 982
diff changeset
265 main()

mercurial