Rev 4055 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4055 | Rev 4156 | ||
---|---|---|---|
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 342... | Line 389... | ||
342 | else: |
389 | else: |
343 | options.append(" %s [%s] --> " % (name, default)) |
390 | options.append(" %s [%s] --> " % (name, default)) |
344 | elif (vartype == 'y'): |
391 | elif (vartype == 'y'): |
345 | defaults[varname] = '*' |
392 | defaults[varname] = '*' |
346 | continue |
393 | continue |
- | 394 | elif (vartype == 'n'): |
|
- | 395 | defaults[varname] = 'n' |
|
- | 396 | continue |
|
347 | elif (vartype == 'y/n'): |
397 | elif (vartype == 'y/n'): |
348 | if (default == None): |
398 | if (default == None): |
349 | default = 'y' |
399 | default = 'y' |
350 | defaults[varname] = default |
400 | defaults[varname] = default |
351 | options.append(" <%s> %s " % (yes_no(default), name)) |
401 | options.append(" <%s> %s " % (yes_no(default), name)) |
Line 359... | Line 409... | ||
359 | 409 | ||
360 | opt2row[cnt] = (varname, vartype, name, choices) |
410 | opt2row[cnt] = (varname, vartype, name, choices) |
361 | 411 | ||
362 | cnt += 1 |
412 | cnt += 1 |
363 | 413 | ||
- | 414 | if (position >= options): |
|
- | 415 | position = None |
|
- | 416 | ||
364 | (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) |
365 | 418 | ||
366 | if (button == 'cancel'): |
419 | if (button == 'cancel'): |
367 | return 'Configuration canceled' |
420 | return 'Configuration canceled' |
368 | 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 |
|
369 | if (not opt2row.has_key(value)): |
435 | if (not opt2row.has_key(value)): |
370 | raise RuntimeError("Error selecting value: %s" % value) |
436 | raise RuntimeError("Error selecting value: %s" % value) |
371 | 437 | ||
372 | (selname, seltype, name, choices) = opt2row[value] |
438 | (selname, seltype, name, choices) = opt2row[value] |
373 | 439 | ||
374 | if (not defaults.has_key(selname)): |
440 | if (not defaults.has_key(selname)): |
375 | default = None |
441 | default = None |
376 | else: |
442 | else: |
377 | default = defaults[selname] |
443 | default = defaults[selname] |
378 | 444 | ||
379 | if (button == 'done'): |
- | |
380 | if (check_choices(defaults, ask_names)): |
- | |
381 | break |
- | |
382 | else: |
- | |
383 | xtui.error_dialog(screen, 'Error', 'Some options have still undefined values. These options are marked with the "?" sign.') |
- | |
384 | continue |
- | |
385 | - | ||
386 | if (seltype == 'choice'): |
445 | if (seltype == 'choice'): |
387 | defaults[selname] = subchoice(screen, name, choices, default) |
446 | defaults[selname] = subchoice(screen, name, choices, default) |
388 | elif ((seltype == 'y/n') or (seltype == 'n/y')): |
447 | elif ((seltype == 'y/n') or (seltype == 'n/y')): |
389 | if (defaults[selname] == 'y'): |
448 | if (defaults[selname] == 'y'): |
390 | defaults[selname] = 'n' |
449 | defaults[selname] = 'n' |