tools/configcollector.py

Thu, 09 Mar 2017 12:50:14 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 09 Mar 2017 12:50:14 +0200
changeset 1209
c2723022b173
parent 1206
743dc95e0be6
permissions
-rwxr-xr-x

Laid groundwork for library collection support.

1125
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
1 #!/usr/bin/env python3
971
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 #
1125
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
4 # Copyright 2015 - 2017 Teemu Piippo
971
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,
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
25 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
971
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
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
971
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
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
33 from argparse import ArgumentParser
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
34 from collections import OrderedDict
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 import caseconversions
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
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
38 # These types are passed by value
1125
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
39 passbyvalue = {'int', 'bool', 'float', 'double', 'qreal'}
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
40
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
41 def deduce_type(value):
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
42 '''
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
43 Try to determine the type of value from the value itself.
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
44 '''
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
45 if value in('true', 'false'):
1125
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
46 return 'bool'
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
47 elif value.startswith('"') and value.endswith('"'):
1125
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
48 return 'QString'
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
49
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
50 try:
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
51 int(value)
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
52 return 'int'
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
53 except:
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
54 pass
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
55
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
56 try:
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
57 float(value)
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
58 return 'double'
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
59 except:
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
60 pass
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
61
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
62 if endswith(value, 'f'):
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
63 try:
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
64 float(value[:-1])
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
65 return 'float'
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
66 except:
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
67 pass
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
68
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
69 raise ValueError('unable to deduce type of %r' % value)
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
71 class ConfigCollector:
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
72 def __init__(self, args):
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
73 self.declarations = OrderedDict()
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
74 self.qtTypes = set()
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 self.args = args
1203
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
76 self.includes = []
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
78 def collect(self, filename):
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
79 with open(filename) as file:
1125
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
80 for line in file:
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
81 line = line.strip()
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1017
diff changeset
82 if line and not line.startswith('#'):
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
83 from re import search
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
84 match = search('^option (\w+) = (.+)$', line)
1203
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
85 if match:
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
86 name, value = match.groups()
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
87 match = search(r'^(\w+)\s*\{(.*)\}$', value)
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
88 try:
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
89 typename, value = match.groups()
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
90 if not value:
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
91 value = typename + ' {}'
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
92 except:
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
93 typename = deduce_type(value)
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
94 self.declare(name, typename, value)
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
95 else:
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
96 match = search('^include (.+)$', line)
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
97 if match:
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
98 filename = match.group(1)
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
99 if filename.startswith('"'):
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
100 from os.path import join
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
101 filename = '"' + join(self.args.sourcedir, filename[1:-1]) + '"'
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
102 self.includes.append(filename)
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
103 else:
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
104 raise ValueError('unable to parse: %r' % line)
7e34dd7559ce Configuration changes can now be detected with signals.
Teemu Piippo <teemu@hecknology.net>
parents: 1157
diff changeset
105
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
106 # Sort the declarations in alphabetical order
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
107 self.declarations = OrderedDict(sorted(self.declarations.items(), key = lambda t: t[1]['name']))
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
108 # Fill in additional information
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
109 for declaration in self.declarations.values():
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
110 declaration['readgate'] = caseconversions.convert_case(declaration['name'], style='java')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
111 declaration['writegate'] = 'set' + caseconversions.convert_case(declaration['name'], style='camel')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
112 declaration['togglefunction'] = 'toggle' + caseconversions.convert_case(declaration['name'], style='camel')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
113 if declaration['type'] in passbyvalue:
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
114 declaration['typereference'] = declaration['type']
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
115 else:
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
116 declaration['typereference'] = 'const %s&' % declaration['type']
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
118 def declare(self, name, typename, default):
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
119 from re import findall
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
120 if name in self.declarations:
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
121 raise ValueError('Attempted to redeclare %r' % name)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
122 self.declarations[name] = {
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
123 'name': name,
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
124 'type': typename,
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
125 'default': default
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
126 }
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
127 # Keep a file of any Qt types, we'll need to #include them.
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
128 self.qtTypes.update(findall(r'Q\w+', typename))
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
130 def writeHeader(self, device):
1204
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
131 write = lambda value: device.write(value + '\n')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
132 write('#pragma once')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
133 write('#include "{sourcedir}/baseconfiguration.h"'.format(sourcedir = self.args.sourcedir))
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
134 write('class Configuration : public BaseConfiguration')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
135 write('{')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
136 write('public:')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
137 write('\tvoid initDefaults() override;')
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
138 for declaration in self.declarations.values():
1206
743dc95e0be6 Better encapsulated the BaseConfiguration class.
Teemu Piippo <teemu@hecknology.net>
parents: 1204
diff changeset
139 write('\t{type} {readgate}();'.format(**declaration))
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
140 for declaration in self.declarations.values():
1204
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
141 write('\tvoid {writegate}({typereference} value);'.format(**declaration))
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
142 for declaration in filter(lambda declaration: declaration['type'] == 'bool', self.declarations.values()):
1204
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
143 write('\tvoid {togglefunction}();'.format(**declaration))
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
144 write('};')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
145 write('')
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
146
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
147 def writeSource(self, device, headername):
1206
743dc95e0be6 Better encapsulated the BaseConfiguration class.
Teemu Piippo <teemu@hecknology.net>
parents: 1204
diff changeset
148 for qttype in sorted(self.qtTypes):
1204
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
149 device.write('#include <%s>\n' % qttype)
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
150 device.write('#include "configuration.h"\n')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
151 device.write('void Configuration::initDefaults()\n')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
152 device.write('{\n')
1d25231dd7c9 Split the configuration main interface to a new class, BaseInterface, so that moc can properly deal with it.
Teemu Piippo <teemu@hecknology.net>
parents: 1203
diff changeset
153 device.write('\tBaseConfiguration::initDefaults();\n')
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
154 for declaration in self.declarations.values():
1206
743dc95e0be6 Better encapsulated the BaseConfiguration class.
Teemu Piippo <teemu@hecknology.net>
parents: 1204
diff changeset
155 device.write('\tregisterConfigurationEntry("{name}", QVariant::fromValue<{type}>({default}));\n'.format(**declaration))
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
156 device.write('}\n')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
157 for declaration in self.declarations.values():
1206
743dc95e0be6 Better encapsulated the BaseConfiguration class.
Teemu Piippo <teemu@hecknology.net>
parents: 1204
diff changeset
158 device.write('{type} Configuration::{readgate}()\n'.format(**declaration))
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
159 device.write('{\n')
1206
743dc95e0be6 Better encapsulated the BaseConfiguration class.
Teemu Piippo <teemu@hecknology.net>
parents: 1204
diff changeset
160 device.write('\treturn value("{name}").value<{type}>();\n'.format(**declaration))
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
161 device.write('}\n')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
162 device.write('\n')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
163 for declaration in self.declarations.values():
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
164 device.write('void Configuration::{writegate}({typereference} value)\n'.format(**declaration))
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
165 device.write('{\n')
1206
743dc95e0be6 Better encapsulated the BaseConfiguration class.
Teemu Piippo <teemu@hecknology.net>
parents: 1204
diff changeset
166 device.write('\tsetValue("{name}", QVariant::fromValue(value));\n'.format(**declaration))
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
167 device.write('}\n')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
168 device.write('\n')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
169 for declaration in filter(lambda declaration: declaration['type'] == 'bool', self.declarations.values()):
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
170 device.write('void Configuration::{togglefunction}()\n'.format(**declaration))
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
171 device.write('{\n')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
172 device.write('\t{writegate}(not {readgate}());\n'.format(**declaration))
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
173 device.write('}\n')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
174 device.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
175
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 def main():
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
177 parser = ArgumentParser(description='Collects a list of configuration objects')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
178 parser.add_argument('input')
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
179 parser.add_argument('--header', required=True)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
180 parser.add_argument('--source', required=True)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
181 parser.add_argument('--sourcedir', required=True)
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 args = parser.parse_args()
1126
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
183 collector = ConfigCollector(args)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
184 collector.collect(args.input)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
185 header = outputfile.OutputFile(args.header)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
186 source = outputfile.OutputFile(args.source)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
187 collector.writeSource(source, headername=args.header)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
188 collector.writeHeader(header)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
189 header.save(verbose = True)
508950e27fcd Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
190 source.save(verbose = True)
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 if __name__ == '__main__':
1012
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 982
diff changeset
193 main()

mercurial