Rev 561 | Rev 567 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 561 | Rev 566 | ||
---|---|---|---|
Line 263... | Line 263... | ||
263 | return True |
263 | return True |
264 | return False |
264 | return False |
265 | 265 | ||
266 | def parse_config(input, output, dlg, defaults={}, askonly=None): |
266 | def parse_config(input, output, dlg, defaults={}, askonly=None): |
267 | "Parse configuration file and create Makefile.config on the fly" |
267 | "Parse configuration file and create Makefile.config on the fly" |
268 | def ask_the_question(): |
268 | def ask_the_question(dialog): |
269 | "Ask question based on the type of variables to ask" |
269 | "Ask question based on the type of variables to ask" |
270 | # This is quite a hack, this thingy is written just to |
270 | # This is quite a hack, this thingy is written just to |
271 | # have access to local variables.. |
271 | # have access to local variables.. |
272 | if vartype == 'y/n': |
272 | if vartype == 'y/n': |
273 | return dlg.yesno(comment, default) |
273 | return dialog.yesno(comment, default) |
274 | elif vartype == 'n/y': |
274 | elif vartype == 'n/y': |
275 | return dlg.noyes(comment, default) |
275 | return dialog.noyes(comment, default) |
276 | elif vartype == 'choice': |
276 | elif vartype == 'choice': |
277 | defopt = None |
277 | defopt = None |
278 | if default is not None: |
278 | if default is not None: |
279 | for i,(key,val) in enumerate(choices): |
279 | for i,(key,val) in enumerate(choices): |
280 | if key == default: |
280 | if key == default: |
281 | defopt = i |
281 | defopt = i |
282 | break |
282 | break |
283 | return dlg.choice(comment, choices, defopt) |
283 | return dialog.choice(comment, choices, defopt) |
284 | else: |
284 | else: |
285 | raise RuntimeError("Bad method: %s" % vartype) |
285 | raise RuntimeError("Bad method: %s" % vartype) |
286 | 286 | ||
287 | 287 | ||
288 | f = file(input, 'r') |
288 | f = file(input, 'r') |
Line 314... | Line 314... | ||
314 | varname = args[0] |
314 | varname = args[0] |
315 | args = args[1:] |
315 | args = args[1:] |
316 | for i,arg in enumerate(args): |
316 | for i,arg in enumerate(args): |
317 | if arg.startswith('$'): |
317 | if arg.startswith('$'): |
318 | args[i] = defaults[arg[1:]] |
318 | args[i] = defaults[arg[1:]] |
319 | - | ||
320 | subc = os.popen(' '.join(args),'r') |
319 | data,status = commands.getstatusoutput(' '.join(args)) |
321 | data = subc.read().strip() |
- | |
322 | if subc.close(): |
320 | if status: |
323 | raise RuntimeError('Error running: %s' % ' '.join(args)) |
321 | raise RuntimeError('Error running: %s' % ' '.join(args)) |
324 | outf.write('%s = %s\n' % (varname,data)) |
322 | outf.write('%s = %s\n' % (varname,data.strip())) |
325 | continue |
323 | continue |
326 | 324 | ||
327 | if line.startswith('!'): |
325 | if line.startswith('!'): |
328 | # Ask a question |
326 | # Ask a question |
329 | res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
327 | res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
Line 345... | Line 343... | ||
345 | continue |
343 | continue |
346 | 344 | ||
347 | asked_names.append((varname,comment)) |
345 | asked_names.append((varname,comment)) |
348 | 346 | ||
349 | if default is None or not askonly or askonly == varname: |
347 | if default is None or not askonly or askonly == varname: |
350 | default = ask_the_question() |
348 | default = ask_the_question(dlg) |
- | 349 | else: |
|
- | 350 | default = ask_the_question(DefaultDialog(dlg)) |
|
351 | 351 | ||
352 | outf.write('%s = %s\n' % (varname, default)) |
352 | outf.write('%s = %s\n' % (varname, default)) |
353 | # Remeber the selected value |
353 | # Remeber the selected value |
354 | defaults[varname] = default |
354 | defaults[varname] = default |
355 | # Clear cumulated values |
355 | # Clear cumulated values |