Rev 3916 | Rev 4054 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3916 | Rev 3937 | ||
---|---|---|---|
1 | #!/usr/bin/env python |
1 | #!/usr/bin/env python |
2 | # |
2 | # |
3 | # Copyright (c) 2006 Ondrej Palkovsky |
3 | # Copyright (c) 2006 Ondrej Palkovsky |
4 | # Copyright (c) 2009 Martin Decky |
4 | # Copyright (c) 2009 Martin Decky |
5 | # All rights reserved. |
5 | # All rights reserved. |
6 | # |
6 | # |
7 | # Redistribution and use in source and binary forms, with or without |
7 | # Redistribution and use in source and binary forms, with or without |
8 | # modification, are permitted provided that the following conditions |
8 | # modification, are permitted provided that the following conditions |
9 | # are met: |
9 | # are met: |
10 | # |
10 | # |
11 | # - Redistributions of source code must retain the above copyright |
11 | # - Redistributions of source code must retain the above copyright |
12 | # notice, this list of conditions and the following disclaimer. |
12 | # notice, this list of conditions and the following disclaimer. |
13 | # - Redistributions in binary form must reproduce the above copyright |
13 | # - Redistributions in binary form must reproduce the above copyright |
14 | # notice, this list of conditions and the following disclaimer in the |
14 | # notice, this list of conditions and the following disclaimer in the |
15 | # documentation and/or other materials provided with the distribution. |
15 | # documentation and/or other materials provided with the distribution. |
16 | # - The name of the author may not be used to endorse or promote products |
16 | # - The name of the author may not be used to endorse or promote products |
17 | # derived from this software without specific prior written permission. |
17 | # derived from this software without specific prior written permission. |
18 | # |
18 | # |
19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | # |
29 | # |
30 | """ |
30 | """ |
31 | HelenOS configuration system |
31 | HelenOS configuration system |
32 | """ |
32 | """ |
33 | import sys |
33 | import sys |
34 | import os |
34 | import os |
35 | import re |
35 | import re |
36 | import commands |
36 | import commands |
37 | import xtui |
37 | import xtui |
38 | 38 | ||
39 | INPUT = sys.argv[1] |
39 | INPUT = sys.argv[1] |
40 | MAKEFILE = 'Makefile.config' |
40 | MAKEFILE = 'Makefile.config' |
41 | MACROS = 'config.h' |
41 | MACROS = 'config.h' |
42 | DEFS = 'config.defs' |
42 | DEFS = 'config.defs' |
43 | 43 | ||
44 | def read_defaults(fname, defaults): |
44 | def read_defaults(fname, defaults): |
45 | "Read saved values from last configuration run" |
45 | "Read saved values from last configuration run" |
46 | 46 | ||
47 | inf = file(fname, 'r') |
47 | inf = file(fname, 'r') |
48 | 48 | ||
49 | for line in inf: |
49 | for line in inf: |
50 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line) |
50 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line) |
51 | if (res): |
51 | if (res): |
52 | defaults[res.group(1)] = res.group(2) |
52 | defaults[res.group(1)] = res.group(2) |
53 | 53 | ||
54 | inf.close() |
54 | inf.close() |
55 | 55 | ||
56 | def check_condition(text, defaults, ask_names): |
56 | def check_condition(text, defaults, ask_names): |
57 | "Check that the condition specified on input line is True (only CNF and DNF is supported)" |
57 | "Check that the condition specified on input line is True (only CNF and DNF is supported)" |
58 | 58 | ||
59 | ctype = 'cnf' |
59 | ctype = 'cnf' |
60 | 60 | ||
61 | if ((')|' in text) or ('|(' in text)): |
61 | if ((')|' in text) or ('|(' in text)): |
62 | ctype = 'dnf' |
62 | ctype = 'dnf' |
63 | 63 | ||
64 | if (ctype == 'cnf'): |
64 | if (ctype == 'cnf'): |
65 | conds = text.split('&') |
65 | conds = text.split('&') |
66 | else: |
66 | else: |
67 | conds = text.split('|') |
67 | conds = text.split('|') |
68 | 68 | ||
69 | for cond in conds: |
69 | for cond in conds: |
70 | if (cond.startswith('(')) and (cond.endswith(')')): |
70 | if (cond.startswith('(')) and (cond.endswith(')')): |
71 | cond = cond[1:-1] |
71 | cond = cond[1:-1] |
72 | 72 | ||
73 | inside = check_inside(cond, defaults, ctype) |
73 | inside = check_inside(cond, defaults, ctype) |
74 | 74 | ||
75 | if (ctype == 'cnf') and (not inside): |
75 | if (ctype == 'cnf') and (not inside): |
76 | return False |
76 | return False |
77 | 77 | ||
78 | if (ctype == 'dnf') and (inside): |
78 | if (ctype == 'dnf') and (inside): |
79 | return True |
79 | return True |
80 | 80 | ||
81 | if (ctype == 'cnf'): |
81 | if (ctype == 'cnf'): |
82 | return True |
82 | return True |
83 | return False |
83 | return False |
84 | 84 | ||
85 | def check_inside(text, defaults, ctype): |
85 | def check_inside(text, defaults, ctype): |
86 | "Check for condition" |
86 | "Check for condition" |
87 | 87 | ||
88 | if (ctype == 'cnf'): |
88 | if (ctype == 'cnf'): |
89 | conds = text.split('|') |
89 | conds = text.split('|') |
90 | else: |
90 | else: |
91 | conds = text.split('&') |
91 | conds = text.split('&') |
92 | 92 | ||
93 | for cond in conds: |
93 | for cond in conds: |
94 | res = re.match(r'^(.*?)(!?=)(.*)$', cond) |
94 | res = re.match(r'^(.*?)(!?=)(.*)$', cond) |
95 | if (not res): |
95 | if (not res): |
96 | raise RuntimeError("Invalid condition: %s" % cond) |
96 | raise RuntimeError("Invalid condition: %s" % cond) |
97 | 97 | ||
98 | condname = res.group(1) |
98 | condname = res.group(1) |
99 | oper = res.group(2) |
99 | oper = res.group(2) |
100 | condval = res.group(3) |
100 | condval = res.group(3) |
101 | 101 | ||
102 | if (not defaults.has_key(condname)): |
102 | if (not defaults.has_key(condname)): |
103 | varval = '' |
103 | varval = '' |
104 | else: |
104 | else: |
105 | varval = defaults[condname] |
105 | varval = defaults[condname] |
- | 106 | if (varval == '*'): |
|
- | 107 | varval = 'y' |
|
106 | 108 | ||
107 | if (ctype == 'cnf'): |
109 | if (ctype == 'cnf'): |
108 | if (oper == '=') and (condval == varval): |
110 | if (oper == '=') and (condval == varval): |
109 | return True |
111 | return True |
110 | 112 | ||
111 | if (oper == '!=') and (condval != varval): |
113 | if (oper == '!=') and (condval != varval): |
112 | return True |
114 | return True |
113 | else: |
115 | else: |
114 | if (oper == '=') and (condval != varval): |
116 | if (oper == '=') and (condval != varval): |
115 | return False |
117 | return False |
116 | 118 | ||
117 | if (oper == '!=') and (condval == varval): |
119 | if (oper == '!=') and (condval == varval): |
118 | return False |
120 | return False |
119 | 121 | ||
120 | if (ctype == 'cnf'): |
122 | if (ctype == 'cnf'): |
121 | return False |
123 | return False |
122 | 124 | ||
123 | return True |
125 | return True |
124 | 126 | ||
125 | def parse_config(fname, ask_names): |
127 | def parse_config(fname, ask_names): |
126 | "Parse configuration file" |
128 | "Parse configuration file" |
127 | 129 | ||
128 | inf = file(fname, 'r') |
130 | inf = file(fname, 'r') |
129 | 131 | ||
130 | name = '' |
132 | name = '' |
131 | choices = [] |
133 | choices = [] |
132 | 134 | ||
133 | for line in inf: |
135 | for line in inf: |
134 | 136 | ||
135 | if (line.startswith('!')): |
137 | if (line.startswith('!')): |
136 | # Ask a question |
138 | # Ask a question |
137 | res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
139 | res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
138 | 140 | ||
139 | if (not res): |
141 | if (not res): |
140 | raise RuntimeError("Weird line: %s" % line) |
142 | raise RuntimeError("Weird line: %s" % line) |
141 | 143 | ||
142 | cond = res.group(1) |
144 | cond = res.group(1) |
143 | varname = res.group(2) |
145 | varname = res.group(2) |
144 | vartype = res.group(3) |
146 | vartype = res.group(3) |
145 | 147 | ||
146 | ask_names.append((varname, vartype, name, choices, cond)) |
148 | ask_names.append((varname, vartype, name, choices, cond)) |
147 | name = '' |
149 | name = '' |
148 | choices = [] |
150 | choices = [] |
149 | continue |
151 | continue |
150 | 152 | ||
151 | if (line.startswith('@')): |
153 | if (line.startswith('@')): |
152 | # Add new line into the 'choices' array |
154 | # Add new line into the 'choices' array |
153 | res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line) |
155 | res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line) |
154 | 156 | ||
155 | if not res: |
157 | if not res: |
156 | raise RuntimeError("Bad line: %s" % line) |
158 | raise RuntimeError("Bad line: %s" % line) |
157 | 159 | ||
158 | choices.append((res.group(2), res.group(3))) |
160 | choices.append((res.group(2), res.group(3))) |
159 | continue |
161 | continue |
160 | 162 | ||
161 | if (line.startswith('%')): |
163 | if (line.startswith('%')): |
162 | # Name of the option |
164 | # Name of the option |
163 | name = line[1:].strip() |
165 | name = line[1:].strip() |
164 | continue |
166 | continue |
165 | 167 | ||
166 | if ((line.startswith('#')) or (line == '\n')): |
168 | if ((line.startswith('#')) or (line == '\n')): |
167 | # Comment or empty line |
169 | # Comment or empty line |
168 | continue |
170 | continue |
169 | 171 | ||
170 | 172 | ||
171 | raise RuntimeError("Unknown syntax: %s" % line) |
173 | raise RuntimeError("Unknown syntax: %s" % line) |
172 | 174 | ||
173 | inf.close() |
175 | inf.close() |
174 | 176 | ||
175 | def yes_no(default): |
177 | def yes_no(default): |
176 | "Return '*' if yes, ' ' if no" |
178 | "Return '*' if yes, ' ' if no" |
177 | 179 | ||
178 | if (default == 'y'): |
180 | if (default == 'y'): |
179 | return '*' |
181 | return '*' |
180 | 182 | ||
181 | return ' ' |
183 | return ' ' |
182 | 184 | ||
183 | def subchoice(screen, name, choices, default): |
185 | def subchoice(screen, name, choices, default): |
184 | "Return choice of choices" |
186 | "Return choice of choices" |
185 | 187 | ||
186 | maxkey = 0 |
188 | maxkey = 0 |
187 | for key, val in choices: |
189 | for key, val in choices: |
188 | length = len(key) |
190 | length = len(key) |
189 | if (length > maxkey): |
191 | if (length > maxkey): |
190 | maxkey = length |
192 | maxkey = length |
191 | 193 | ||
192 | options = [] |
194 | options = [] |
193 | position = None |
195 | position = None |
194 | cnt = 0 |
196 | cnt = 0 |
195 | for key, val in choices: |
197 | for key, val in choices: |
196 | if ((default) and (key == default)): |
198 | if ((default) and (key == default)): |
197 | position = cnt |
199 | position = cnt |
198 | 200 | ||
199 | options.append(" %-*s %s " % (maxkey, key, val)) |
201 | options.append(" %-*s %s " % (maxkey, key, val)) |
200 | cnt += 1 |
202 | cnt += 1 |
201 | 203 | ||
202 | (button, value) = xtui.choice_window(screen, name, 'Choose value', options, position) |
204 | (button, value) = xtui.choice_window(screen, name, 'Choose value', options, position) |
203 | 205 | ||
204 | if (button == 'cancel'): |
206 | if (button == 'cancel'): |
205 | return None |
207 | return None |
206 | 208 | ||
207 | return choices[value][0] |
209 | return choices[value][0] |
208 | 210 | ||
209 | def check_choices(defaults, ask_names): |
211 | def check_choices(defaults, ask_names): |
210 | "Check whether all accessible variables have a default" |
212 | "Check whether all accessible variables have a default" |
211 | 213 | ||
212 | for varname, vartype, name, choices, cond in ask_names: |
214 | for varname, vartype, name, choices, cond in ask_names: |
213 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
215 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
214 | continue |
216 | continue |
215 | 217 | ||
216 | if (not defaults.has_key(varname)): |
218 | if (not defaults.has_key(varname)): |
217 | return False |
219 | return False |
218 | 220 | ||
219 | return True |
221 | return True |
220 | 222 | ||
221 | def create_output(mkname, mcname, dfname, defaults, ask_names): |
223 | def create_output(mkname, mcname, dfname, defaults, ask_names): |
222 | "Create output configuration" |
224 | "Create output configuration" |
223 | 225 | ||
224 | revision = commands.getoutput('svnversion . 2> /dev/null') |
226 | revision = commands.getoutput('svnversion . 2> /dev/null') |
225 | timestamp = commands.getoutput('date "+%Y-%m-%d %H:%M:%S"') |
227 | timestamp = commands.getoutput('date "+%Y-%m-%d %H:%M:%S"') |
226 | 228 | ||
227 | outmk = file(mkname, 'w') |
229 | outmk = file(mkname, 'w') |
228 | outmc = file(mcname, 'w') |
230 | outmc = file(mcname, 'w') |
229 | outdf = file(dfname, 'w') |
231 | outdf = file(dfname, 'w') |
230 | 232 | ||
231 | outmk.write('#########################################\n') |
233 | outmk.write('#########################################\n') |
232 | outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
234 | outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
233 | outmk.write('#########################################\n\n') |
235 | outmk.write('#########################################\n\n') |
234 | 236 | ||
235 | outmc.write('/***************************************\n') |
237 | outmc.write('/***************************************\n') |
236 | outmc.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n') |
238 | outmc.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n') |
237 | outmc.write(' ***************************************/\n\n') |
239 | outmc.write(' ***************************************/\n\n') |
238 | 240 | ||
239 | outdf.write('#########################################\n') |
241 | outdf.write('#########################################\n') |
240 | outdf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
242 | outdf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
241 | outdf.write('#########################################\n\n') |
243 | outdf.write('#########################################\n\n') |
242 | outdf.write('CONFIG_DEFS =') |
244 | outdf.write('CONFIG_DEFS =') |
243 | 245 | ||
244 | for varname, vartype, name, choices, cond in ask_names: |
246 | for varname, vartype, name, choices, cond in ask_names: |
245 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
247 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
246 | continue |
248 | continue |
247 | 249 | ||
248 | if (not defaults.has_key(varname)): |
250 | if (not defaults.has_key(varname)): |
249 | default = '' |
251 | default = '' |
250 | else: |
252 | else: |
251 | default = defaults[varname] |
253 | default = defaults[varname] |
- | 254 | if (default == '*'): |
|
- | 255 | default = 'y' |
|
252 | 256 | ||
253 | outmk.write('# %s\n%s = %s\n\n' % (name, varname, default)) |
257 | outmk.write('# %s\n%s = %s\n\n' % (name, varname, default)) |
254 | 258 | ||
255 | if ((vartype == "y") or (vartype == "y/n") or (vartype == "n/y")): |
259 | if ((vartype == "y") or (vartype == "y/n") or (vartype == "n/y")): |
256 | if (default == "y"): |
260 | if (default == "y"): |
257 | outmc.write('/* %s */\n#define %s\n\n' % (name, varname)) |
261 | outmc.write('/* %s */\n#define %s\n\n' % (name, varname)) |
258 | outdf.write(' -D%s' % varname) |
262 | outdf.write(' -D%s' % varname) |
259 | else: |
263 | else: |
260 | outmc.write('/* %s */\n#define %s %s\n#define %s_%s\n\n' % (name, varname, default, varname, default)) |
264 | outmc.write('/* %s */\n#define %s %s\n#define %s_%s\n\n' % (name, varname, default, varname, default)) |
261 | outdf.write(' -D%s=%s -D%s_%s' % (varname, default, varname, default)) |
265 | outdf.write(' -D%s=%s -D%s_%s' % (varname, default, varname, default)) |
262 | 266 | ||
263 | outmk.write('REVISION = %s\n' % revision) |
267 | outmk.write('REVISION = %s\n' % revision) |
264 | outmk.write('TIMESTAMP = %s\n' % timestamp) |
268 | outmk.write('TIMESTAMP = %s\n' % timestamp) |
265 | 269 | ||
266 | outmc.write('#define REVISION %s\n' % revision) |
270 | outmc.write('#define REVISION %s\n' % revision) |
267 | outmc.write('#define TIMESTAMP %s\n' % timestamp) |
271 | outmc.write('#define TIMESTAMP %s\n' % timestamp) |
268 | 272 | ||
269 | outdf.write(' "-DREVISION=%s" "-DTIMESTAMP=%s"\n' % (revision, timestamp)) |
273 | outdf.write(' "-DREVISION=%s" "-DTIMESTAMP=%s"\n' % (revision, timestamp)) |
270 | 274 | ||
271 | outmk.close() |
275 | outmk.close() |
272 | outmc.close() |
276 | outmc.close() |
273 | outdf.close() |
277 | outdf.close() |
274 | 278 | ||
275 | def main(): |
279 | def main(): |
276 | defaults = {} |
280 | defaults = {} |
277 | ask_names = [] |
281 | ask_names = [] |
278 | 282 | ||
279 | # Parse configuration file |
283 | # Parse configuration file |
280 | parse_config(INPUT, ask_names) |
284 | parse_config(INPUT, ask_names) |
281 | 285 | ||
282 | # Read defaults from previous run |
286 | # Read defaults from previous run |
283 | if os.path.exists(MAKEFILE): |
287 | if os.path.exists(MAKEFILE): |
284 | read_defaults(MAKEFILE, defaults) |
288 | read_defaults(MAKEFILE, defaults) |
285 | 289 | ||
286 | # Default mode: only check defaults and regenerate configuration |
290 | # Default mode: only check defaults and regenerate configuration |
287 | if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')): |
291 | if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')): |
288 | if (check_choices(defaults, ask_names)): |
292 | if (check_choices(defaults, ask_names)): |
289 | create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names) |
293 | create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names) |
290 | return 0 |
294 | return 0 |
291 | 295 | ||
292 | # Check mode: only check defaults |
296 | # Check mode: only check defaults |
293 | if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')): |
297 | if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')): |
294 | if (check_choices(defaults, ask_names)): |
298 | if (check_choices(defaults, ask_names)): |
295 | return 0 |
299 | return 0 |
296 | return 1 |
300 | return 1 |
297 | 301 | ||
298 | screen = xtui.screen_init() |
302 | screen = xtui.screen_init() |
299 | try: |
303 | try: |
300 | selname = None |
304 | selname = None |
301 | while True: |
305 | while True: |
302 | 306 | ||
303 | # Cancel out all defaults which have to be deduced |
307 | # Cancel out all defaults which have to be deduced |
304 | for varname, vartype, name, choices, cond in ask_names: |
308 | for varname, vartype, name, choices, cond in ask_names: |
305 | if (vartype == 'y'): |
309 | if ((vartype == 'y') and (defaults.has_key(varname)) and (defaults[varname] == '*')): |
306 | defaults[varname] = None |
310 | defaults[varname] = None |
307 | 311 | ||
308 | options = [] |
312 | options = [] |
309 | opt2row = {} |
313 | opt2row = {} |
310 | position = None |
314 | position = None |
311 | cnt = 0 |
315 | cnt = 0 |
312 | for varname, vartype, name, choices, cond in ask_names: |
316 | for varname, vartype, name, choices, cond in ask_names: |
313 | 317 | ||
314 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
318 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
315 | continue |
319 | continue |
316 | 320 | ||
317 | if (varname == selname): |
321 | if (varname == selname): |
318 | position = cnt |
322 | position = cnt |
319 | 323 | ||
320 | if (not defaults.has_key(varname)): |
324 | if (not defaults.has_key(varname)): |
321 | default = None |
325 | default = None |
322 | else: |
326 | else: |
323 | default = defaults[varname] |
327 | default = defaults[varname] |
324 | 328 | ||
325 | if (vartype == 'choice'): |
329 | if (vartype == 'choice'): |
326 | # Check if the default is an acceptable value |
330 | # Check if the default is an acceptable value |
327 | if ((default) and (not default in [choice[0] for choice in choices])): |
331 | if ((default) and (not default in [choice[0] for choice in choices])): |
328 | default = None |
332 | default = None |
329 | defaults.pop(varname) |
333 | defaults.pop(varname) |
330 | 334 | ||
331 | # If there is just one option, use it |
335 | # If there is just one option, use it |
332 | if (len(choices) == 1): |
336 | if (len(choices) == 1): |
333 | defaults[varname] = choices[0][0] |
337 | defaults[varname] = choices[0][0] |
334 | continue |
338 | continue |
335 | 339 | ||
336 | options.append(" %s [%s] --> " % (name, default)) |
340 | options.append(" %s [%s] --> " % (name, default)) |
337 | elif (vartype == 'y'): |
341 | elif (vartype == 'y'): |
338 | defaults[varname] = 'y' |
342 | defaults[varname] = '*' |
339 | continue |
343 | continue |
340 | elif (vartype == 'y/n'): |
344 | elif (vartype == 'y/n'): |
341 | if (default == None): |
345 | if (default == None): |
342 | default = 'y' |
346 | default = 'y' |
343 | defaults[varname] = default |
347 | defaults[varname] = default |
344 | options.append(" <%s> %s " % (yes_no(default), name)) |
348 | options.append(" <%s> %s " % (yes_no(default), name)) |
345 | elif (vartype == 'n/y'): |
349 | elif (vartype == 'n/y'): |
346 | if (default == None): |
350 | if (default == None): |
347 | default = 'n' |
351 | default = 'n' |
348 | defaults[varname] = default |
352 | defaults[varname] = default |
349 | options.append(" <%s> %s " % (yes_no(default), name)) |
353 | options.append(" <%s> %s " % (yes_no(default), name)) |
350 | else: |
354 | else: |
351 | raise RuntimeError("Unknown variable type: %s" % vartype) |
355 | raise RuntimeError("Unknown variable type: %s" % vartype) |
352 | 356 | ||
353 | opt2row[cnt] = (varname, vartype, name, choices) |
357 | opt2row[cnt] = (varname, vartype, name, choices) |
354 | 358 | ||
355 | cnt += 1 |
359 | cnt += 1 |
356 | 360 | ||
357 | (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position) |
361 | (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position) |
358 | 362 | ||
359 | if (button == 'cancel'): |
363 | if (button == 'cancel'): |
360 | return 'Configuration canceled' |
364 | return 'Configuration canceled' |
361 | 365 | ||
362 | if (not opt2row.has_key(value)): |
366 | if (not opt2row.has_key(value)): |
363 | raise RuntimeError("Error selecting value: %s" % value) |
367 | raise RuntimeError("Error selecting value: %s" % value) |
364 | 368 | ||
365 | (selname, seltype, name, choices) = opt2row[value] |
369 | (selname, seltype, name, choices) = opt2row[value] |
366 | 370 | ||
367 | if (not defaults.has_key(selname)): |
371 | if (not defaults.has_key(selname)): |
368 | default = None |
372 | default = None |
369 | else: |
373 | else: |
370 | default = defaults[selname] |
374 | default = defaults[selname] |
371 | 375 | ||
372 | if (button == 'done'): |
376 | if (button == 'done'): |
373 | if (check_choices(defaults, ask_names)): |
377 | if (check_choices(defaults, ask_names)): |
374 | break |
378 | break |
375 | else: |
379 | else: |
376 | xtui.error_dialog(screen, 'Error', 'Some options have still undefined values.') |
380 | xtui.error_dialog(screen, 'Error', 'Some options have still undefined values.') |
377 | continue |
381 | continue |
378 | 382 | ||
379 | if (seltype == 'choice'): |
383 | if (seltype == 'choice'): |
380 | defaults[selname] = subchoice(screen, name, choices, default) |
384 | defaults[selname] = subchoice(screen, name, choices, default) |
381 | elif ((seltype == 'y/n') or (seltype == 'n/y')): |
385 | elif ((seltype == 'y/n') or (seltype == 'n/y')): |
382 | if (defaults[selname] == 'y'): |
386 | if (defaults[selname] == 'y'): |
383 | defaults[selname] = 'n' |
387 | defaults[selname] = 'n' |
384 | else: |
388 | else: |
385 | defaults[selname] = 'y' |
389 | defaults[selname] = 'y' |
386 | finally: |
390 | finally: |
387 | xtui.screen_done(screen) |
391 | xtui.screen_done(screen) |
388 | 392 | ||
389 | create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names) |
393 | create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names) |
390 | return 0 |
394 | return 0 |
391 | 395 | ||
392 | if __name__ == '__main__': |
396 | if __name__ == '__main__': |
393 | sys.exit(main()) |
397 | sys.exit(main()) |
394 | 398 |