Rev 555 | Rev 558 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 555 | Rev 556 | ||
---|---|---|---|
Line 251... | Line 251... | ||
251 | return True |
251 | return True |
252 | return False |
252 | return False |
253 | 253 | ||
254 | def parse_config(input, output, dlg, defaults={}, askonly=None): |
254 | def parse_config(input, output, dlg, defaults={}, askonly=None): |
255 | "Parse configuration file and create Makefile.config on the fly" |
255 | "Parse configuration file and create Makefile.config on the fly" |
- | 256 | def ask_the_question(): |
|
- | 257 | "Ask question based on the type of variables to ask" |
|
- | 258 | # This is quite a hack, this thingy is written just to |
|
- | 259 | # have access to local variables.. |
|
- | 260 | if vartype == 'y/n': |
|
- | 261 | return dlg.yesno(comment, default) |
|
- | 262 | elif vartype == 'n/y': |
|
- | 263 | return dlg.noyes(comment, default) |
|
- | 264 | elif vartype == 'choice': |
|
- | 265 | defopt = None |
|
- | 266 | if default is not None: |
|
- | 267 | for i,(key,val) in enumerate(choices): |
|
- | 268 | if key == default: |
|
- | 269 | defopt = i |
|
- | 270 | break |
|
- | 271 | return dlg.choice(comment, choices, defopt) |
|
- | 272 | else: |
|
- | 273 | raise RuntimeError("Bad method: %s" % vartype) |
|
- | 274 | ||
- | 275 | ||
256 | f = file(input, 'r') |
276 | f = file(input, 'r') |
257 | outf = file(output, 'w') |
277 | outf = file(output, 'w') |
258 | 278 | ||
259 | outf.write('#########################################\n') |
279 | outf.write('#########################################\n') |
260 | outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
280 | outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
Line 301... | Line 321... | ||
301 | choices = [] |
321 | choices = [] |
302 | continue |
322 | continue |
303 | 323 | ||
304 | asked_names.append((varname,comment)) |
324 | asked_names.append((varname,comment)) |
305 | 325 | ||
306 | if default is not None and askonly and askonly != varname: |
326 | if default is None or not askonly or askonly == varname: |
307 | outf.write('%s = %s\n' % (varname, default)) |
327 | default = ask_the_question() |
308 | continue |
- | |
309 | 328 | ||
310 | if vartype == 'y/n': |
- | |
311 | result = dlg.yesno(comment, default) |
- | |
312 | elif vartype == 'n/y': |
- | |
313 | result = dlg.noyes(comment, default) |
- | |
314 | elif vartype == 'choice': |
- | |
315 | defopt = None |
- | |
316 | if default is not None: |
- | |
317 | for i,(key,val) in enumerate(choices): |
- | |
318 | if key == default: |
- | |
319 | defopt = i |
- | |
320 | break |
- | |
321 | result = dlg.choice(comment, choices, defopt) |
- | |
322 | else: |
- | |
323 | raise RuntimeError("Bad method: %s" % vartype) |
- | |
324 | outf.write('%s = %s\n' % (varname, result)) |
329 | outf.write('%s = %s\n' % (varname, default)) |
325 | # Remeber the selected value |
330 | # Remeber the selected value |
326 | defaults[varname] = result |
331 | defaults[varname] = default |
327 | # Clear cumulated values |
332 | # Clear cumulated values |
328 | comment = '' |
333 | comment = '' |
329 | default = None |
334 | default = None |
330 | choices = [] |
335 | choices = [] |
331 | continue |
336 | continue |