34,7 → 34,7 |
import os |
import re |
import commands |
import xtui |
import snack |
|
INPUT = sys.argv[1] |
OUTPUT = 'Makefile.config' |
178,36 → 178,33 |
|
return ' ' |
|
def subchoice(screen, name, choices, default): |
def subchoice(screen, name, choices): |
"Return choice of choices" |
|
maxkey = 0 |
for key, val in choices: |
length = len(key) |
if (length > maxkey): |
maxkey = length |
maxlen = 0 |
for choice in choices: |
length = len(choice[0]) |
if (length > maxlen): |
maxlen = length |
|
options = [] |
position = None |
cnt = 0 |
for key, val in choices: |
if ((default) and (key == default)): |
position = cnt |
for choice in choices: |
options.append(" %-*s %s " % (maxlen, choice[0], choice[1])) |
|
options.append(" %-*s %s " % (maxkey, key, val)) |
cnt += 1 |
retval = snack.ListboxChoiceWindow(screen, name, 'Choose value', options) |
|
(button, value) = xtui.choice_window(screen, name, 'Choose value', options, position) |
|
if (button == 'cancel'): |
if (retval[0] == 'cancel'): |
return None |
|
return choices[value][0] |
return choices[retval[1]][0] |
|
def check_choices(defaults, ask_names): |
"Check whether all accessible variables have a default" |
|
for varname, vartype, name, choices, cond in ask_names: |
for row in ask_names: |
varname = row[0] |
cond = row[4] |
|
if ((cond) and (not check_condition(cond, defaults, ask_names))): |
continue |
|
225,7 → 222,11 |
outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n') |
outf.write('#########################################\n\n') |
|
for varname, vartype, name, choices, cond in ask_names: |
for row in ask_names: |
varname = row[0] |
name = row[2] |
cond = row[4] |
|
if ((cond) and (not check_condition(cond, defaults, ask_names))): |
continue |
|
257,7 → 258,7 |
create_output(OUTPUT, defaults, ask_names) |
return 0 |
|
screen = xtui.screen_init() |
screen = snack.SnackScreen() |
try: |
selname = None |
while True: |
266,8 → 267,14 |
opt2row = {} |
position = None |
cnt = 0 |
for varname, vartype, name, choices, cond in ask_names: |
for row in ask_names: |
|
varname = row[0] |
vartype = row[1] |
name = row[2] |
choices = row[3] |
cond = row[4] |
|
if ((cond) and (not check_condition(cond, defaults, ask_names))): |
continue |
|
304,34 → 311,33 |
else: |
raise RuntimeError("Unknown variable type: %s" % vartype) |
|
opt2row[cnt] = (varname, vartype, name, choices) |
opt2row[cnt] = row |
|
cnt += 1 |
|
(button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position) |
retval = snack.ListboxChoiceWindow(screen, 'HelenOS configuration', 'Choose configuration option', options, default = position) |
|
if (button == 'cancel'): |
if (retval[0] == 'cancel'): |
return 'Configuration canceled' |
|
if (not opt2row.has_key(value)): |
raise RuntimeError("Error selecting value: %s" % value) |
row = opt2row[retval[1]] |
if (row == None): |
raise RuntimeError("Error selecting value: %s" % retval[1]) |
|
(selname, seltype, name, choices) = opt2row[value] |
selname = row[0] |
seltype = row[1] |
name = row[2] |
choices = row[3] |
|
if (not defaults.has_key(selname)): |
default = None |
else: |
default = defaults[selname] |
|
if (button == 'done'): |
if (retval[0] == 'ok'): |
if (check_choices(defaults, ask_names)): |
break |
else: |
xtui.error_dialog(screen, 'Error', 'Some options have still undefined values.') |
snack.ButtonChoiceWindow(screen, 'Error', 'Some options have still undefined values.', ['Ok']); |
continue |
|
if (seltype == 'choice'): |
defaults[selname] = subchoice(screen, name, choices, default) |
defaults[selname] = subchoice(screen, name, choices) |
elif ((seltype == 'y/n') or (seltype == 'n/y')): |
if (defaults[selname] == 'y'): |
defaults[selname] = 'n' |
338,7 → 344,7 |
else: |
defaults[selname] = 'y' |
finally: |
xtui.screen_done(screen) |
screen.finish() |
|
create_output(OUTPUT, defaults, ask_names) |
return 0 |