Rev 4344 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4344 | Rev 4346 | ||
---|---|---|---|
Line 38... | Line 38... | ||
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 | PRECONF = 'defaults' |
|
43 | 44 | ||
44 | def read_defaults(fname, defaults): |
45 | def read_defaults(fname, defaults): |
45 | "Read saved values from last configuration run" |
46 | "Read saved values from last configuration run" |
46 | 47 | ||
47 | inf = file(fname, 'r') |
48 | inf = file(fname, 'r') |
Line 254... | Line 255... | ||
254 | if (default == '*'): |
255 | if (default == '*'): |
255 | default = 'y' |
256 | default = 'y' |
256 | 257 | ||
257 | outmk.write('# %s\n%s = %s\n\n' % (name, varname, default)) |
258 | outmk.write('# %s\n%s = %s\n\n' % (name, varname, default)) |
258 | 259 | ||
259 | if ((vartype == "y") or (vartype == "y/n") or (vartype == "n/y")): |
260 | if ((vartype == "y") or (vartype == "n") or (vartype == "y/n") or (vartype == "n/y")): |
260 | if (default == "y"): |
261 | if (default == "y"): |
261 | outmc.write('/* %s */\n#define %s\n\n' % (name, varname)) |
262 | outmc.write('/* %s */\n#define %s\n\n' % (name, varname)) |
262 | outdf.write(' -D%s' % varname) |
263 | outdf.write(' -D%s' % varname) |
263 | else: |
264 | else: |
264 | outmc.write('/* %s */\n#define %s %s\n#define %s_%s\n\n' % (name, varname, default, varname, default)) |
265 | outmc.write('/* %s */\n#define %s %s\n#define %s_%s\n\n' % (name, varname, default, varname, default)) |
Line 274... | Line 275... | ||
274 | 275 | ||
275 | outmk.close() |
276 | outmk.close() |
276 | outmc.close() |
277 | outmc.close() |
277 | outdf.close() |
278 | outdf.close() |
278 | 279 | ||
- | 280 | def sorted_dir(root): |
|
- | 281 | list = os.listdir(root) |
|
- | 282 | list.sort() |
|
- | 283 | return list |
|
- | 284 | ||
- | 285 | def read_preconfigured(root, fname, screen, defaults): |
|
- | 286 | options = [] |
|
- | 287 | opt2path = {} |
|
- | 288 | cnt = 0 |
|
- | 289 | ||
- | 290 | # Look for profiles |
|
- | 291 | for name in sorted_dir(root): |
|
- | 292 | path = os.path.join(root, name) |
|
- | 293 | canon = os.path.join(path, fname) |
|
- | 294 | ||
- | 295 | if ((os.path.isdir(path)) and (os.path.exists(canon)) and (os.path.isfile(canon))): |
|
- | 296 | subprofile = False |
|
- | 297 | ||
- | 298 | # Look for subprofiles |
|
- | 299 | for subname in sorted_dir(path): |
|
- | 300 | subpath = os.path.join(path, subname) |
|
- | 301 | subcanon = os.path.join(subpath, fname) |
|
- | 302 | ||
- | 303 | if ((os.path.isdir(subpath)) and (os.path.exists(subcanon)) and (os.path.isfile(subcanon))): |
|
- | 304 | subprofile = True |
|
- | 305 | options.append("%s (%s)" % (name, subname)) |
|
- | 306 | opt2path[cnt] = (canon, subcanon) |
|
- | 307 | cnt += 1 |
|
- | 308 | ||
- | 309 | if (not subprofile): |
|
- | 310 | options.append(name) |
|
- | 311 | opt2path[cnt] = (canon, None) |
|
- | 312 | cnt += 1 |
|
- | 313 | ||
- | 314 | (button, value) = xtui.choice_window(screen, 'Load preconfigured defaults', 'Choose configuration profile', options, None) |
|
- | 315 | ||
- | 316 | if (button == 'cancel'): |
|
- | 317 | return None |
|
- | 318 | ||
- | 319 | read_defaults(opt2path[value][0], defaults) |
|
- | 320 | if (opt2path[value][1] != None): |
|
- | 321 | read_defaults(opt2path[value][1], defaults) |
|
- | 322 | ||
279 | def main(): |
323 | def main(): |
280 | defaults = {} |
324 | defaults = {} |
281 | ask_names = [] |
325 | ask_names = [] |
282 | 326 | ||
283 | # Parse configuration file |
327 | # Parse configuration file |
Line 300... | Line 344... | ||
300 | return 1 |
344 | return 1 |
301 | 345 | ||
302 | screen = xtui.screen_init() |
346 | screen = xtui.screen_init() |
303 | try: |
347 | try: |
304 | selname = None |
348 | selname = None |
- | 349 | position = None |
|
305 | while True: |
350 | while True: |
306 | 351 | ||
307 | # Cancel out all defaults which have to be deduced |
352 | # Cancel out all defaults which have to be deduced |
308 | for varname, vartype, name, choices, cond in ask_names: |
353 | for varname, vartype, name, choices, cond in ask_names: |
309 | if ((vartype == 'y') and (defaults.has_key(varname)) and (defaults[varname] == '*')): |
354 | if ((vartype == 'y') and (defaults.has_key(varname)) and (defaults[varname] == '*')): |
310 | defaults[varname] = None |
355 | defaults[varname] = None |
311 | 356 | ||
312 | options = [] |
357 | options = [] |
313 | opt2row = {} |
358 | opt2row = {} |
314 | position = None |
359 | cnt = 1 |
315 | cnt = 0 |
360 | |
- | 361 | options.append(" --- Load preconfigured defaults ... ") |
|
- | 362 | ||
316 | for varname, vartype, name, choices, cond in ask_names: |
363 | for varname, vartype, name, choices, cond in ask_names: |
317 | 364 | ||
318 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
365 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
319 | continue |
366 | continue |
320 | 367 | ||
Line 335... | Line 382... | ||
335 | # If there is just one option, use it |
382 | # If there is just one option, use it |
336 | if (len(choices) == 1): |
383 | if (len(choices) == 1): |
337 | defaults[varname] = choices[0][0] |
384 | defaults[varname] = choices[0][0] |
338 | continue |
385 | continue |
339 | 386 | ||
- | 387 | if (default == None): |
|
- | 388 | options.append("? %s --> " % name) |
|
- | 389 | else: |
|
340 | options.append(" %s [%s] --> " % (name, default)) |
390 | options.append(" %s [%s] --> " % (name, default)) |
341 | elif (vartype == 'y'): |
391 | elif (vartype == 'y'): |
342 | defaults[varname] = '*' |
392 | defaults[varname] = '*' |
343 | continue |
393 | continue |
- | 394 | elif (vartype == 'n'): |
|
- | 395 | defaults[varname] = 'n' |
|
- | 396 | continue |
|
344 | elif (vartype == 'y/n'): |
397 | elif (vartype == 'y/n'): |
345 | if (default == None): |
398 | if (default == None): |
346 | default = 'y' |
399 | default = 'y' |
347 | defaults[varname] = default |
400 | defaults[varname] = default |
348 | options.append(" <%s> %s " % (yes_no(default), name)) |
401 | options.append(" <%s> %s " % (yes_no(default), name)) |
349 | elif (vartype == 'n/y'): |
402 | elif (vartype == 'n/y'): |
350 | if (default == None): |
403 | if (default == None): |
351 | default = 'n' |
404 | default = 'n' |
352 | defaults[varname] = default |
405 | defaults[varname] = default |
353 | options.append(" <%s> %s " % (yes_no(default), name)) |
406 | options.append(" <%s> %s " % (yes_no(default), name)) |
354 | else: |
407 | else: |
355 | raise RuntimeError("Unknown variable type: %s" % vartype) |
408 | raise RuntimeError("Unknown variable type: %s" % vartype) |
356 | 409 | ||
357 | opt2row[cnt] = (varname, vartype, name, choices) |
410 | opt2row[cnt] = (varname, vartype, name, choices) |
358 | 411 | ||
359 | cnt += 1 |
412 | cnt += 1 |
360 | 413 | ||
- | 414 | if (position >= options): |
|
- | 415 | position = None |
|
- | 416 | ||
361 | (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position) |
417 | (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position) |
362 | 418 | ||
363 | if (button == 'cancel'): |
419 | if (button == 'cancel'): |
364 | return 'Configuration canceled' |
420 | return 'Configuration canceled' |
365 | 421 | ||
- | 422 | if (button == 'done'): |
|
- | 423 | if (check_choices(defaults, ask_names)): |
|
- | 424 | break |
|
- | 425 | else: |
|
- | 426 | xtui.error_dialog(screen, 'Error', 'Some options have still undefined values. These options are marked with the "?" sign.') |
|
- | 427 | continue |
|
- | 428 | ||
- | 429 | if (value == 0): |
|
- | 430 | read_preconfigured(PRECONF, MAKEFILE, screen, defaults) |
|
- | 431 | position = 1 |
|
- | 432 | continue |
|
- | 433 | ||
- | 434 | position = None |
|
366 | if (not opt2row.has_key(value)): |
435 | if (not opt2row.has_key(value)): |
367 | raise RuntimeError("Error selecting value: %s" % value) |
436 | raise RuntimeError("Error selecting value: %s" % value) |
368 | 437 | ||
369 | (selname, seltype, name, choices) = opt2row[value] |
438 | (selname, seltype, name, choices) = opt2row[value] |
370 | 439 | ||
371 | if (not defaults.has_key(selname)): |
440 | if (not defaults.has_key(selname)): |
372 | default = None |
441 | default = None |
373 | else: |
442 | else: |
374 | default = defaults[selname] |
443 | default = defaults[selname] |
375 | 444 | ||
376 | if (button == 'done'): |
- | |
377 | if (check_choices(defaults, ask_names)): |
- | |
378 | break |
- | |
379 | else: |
- | |
380 | xtui.error_dialog(screen, 'Error', 'Some options have still undefined values.') |
- | |
381 | continue |
- | |
382 | - | ||
383 | if (seltype == 'choice'): |
445 | if (seltype == 'choice'): |
384 | defaults[selname] = subchoice(screen, name, choices, default) |
446 | defaults[selname] = subchoice(screen, name, choices, default) |
385 | elif ((seltype == 'y/n') or (seltype == 'n/y')): |
447 | elif ((seltype == 'y/n') or (seltype == 'n/y')): |
386 | if (defaults[selname] == 'y'): |
448 | if (defaults[selname] == 'y'): |
387 | defaults[selname] = 'n' |
449 | defaults[selname] = 'n' |