Subversion Repositories HelenOS

Rev

Rev 3803 | Rev 3808 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3803 Rev 3804
Line 32... Line 32...
32
"""
32
"""
33
import sys
33
import sys
34
import os
34
import os
35
import re
35
import re
36
import commands
36
import commands
37
import snack
37
import xtui
38
 
38
 
39
INPUT = sys.argv[1]
39
INPUT = sys.argv[1]
40
OUTPUT = 'Makefile.config'
40
OUTPUT = 'Makefile.config'
41
 
41
 
42
def read_defaults(fname, defaults):
42
def read_defaults(fname, defaults):
Line 176... Line 176...
176
    if (default == 'y'):
176
    if (default == 'y'):
177
        return '*'
177
        return '*'
178
   
178
   
179
    return ' '
179
    return ' '
180
 
180
 
181
def subchoice(screen, name, choices):
181
def subchoice(screen, name, choices, default):
182
    "Return choice of choices"
182
    "Return choice of choices"
183
   
183
   
184
    maxlen = 0
184
    maxkey = 0
185
    for choice in choices:
185
    for key, val in choices:
186
        length = len(choice[0])
186
        length = len(key)
187
        if (length > maxlen):
187
        if (length > maxkey):
188
            maxlen = length
188
            maxkey = length
189
   
189
   
190
    options = []
190
    options = []
-
 
191
    position = None
-
 
192
    cnt = 0
191
    for choice in choices:
193
    for key, val in choices:
-
 
194
        if ((default) and (key == default)):
-
 
195
            position = cnt
-
 
196
       
192
        options.append(" %-*s  %s " % (maxlen, choice[0], choice[1]))
197
        options.append(" %-*s  %s " % (maxkey, key, val))
-
 
198
        cnt += 1
193
   
199
   
194
    retval = snack.ListboxChoiceWindow(screen, name, 'Choose value', options)
200
    (button, value) = xtui.choice_window(screen, name, 'Choose value', options, position)
195
   
201
   
196
    if (retval[0] == 'cancel'):
202
    if (button == 'cancel'):
197
        return None
203
        return None
198
   
204
   
199
    return choices[retval[1]][0]
205
    return choices[value][0]
200
 
206
 
201
def check_choices(defaults, ask_names):
207
def check_choices(defaults, ask_names):
202
    "Check whether all accessible variables have a default"
208
    "Check whether all accessible variables have a default"
203
   
209
   
204
    for row in ask_names:
210
    for varname, vartype, name, choices, cond in ask_names:
205
        varname = row[0]
-
 
206
        cond = row[4]
-
 
207
       
-
 
208
        if ((cond) and (not check_condition(cond, defaults, ask_names))):
211
        if ((cond) and (not check_condition(cond, defaults, ask_names))):
209
            continue
212
            continue
210
       
213
       
211
        if (not defaults.has_key(varname)):
214
        if (not defaults.has_key(varname)):
212
            return False
215
            return False
Line 220... Line 223...
220
   
223
   
221
    outf.write('#########################################\n')
224
    outf.write('#########################################\n')
222
    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
225
    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
223
    outf.write('#########################################\n\n')
226
    outf.write('#########################################\n\n')
224
   
227
   
225
    for row in ask_names:
228
    for varname, vartype, name, choices, cond in ask_names:
226
        varname = row[0]
-
 
227
        name = row[2]
-
 
228
        cond = row[4]
-
 
229
       
-
 
230
        if ((cond) and (not check_condition(cond, defaults, ask_names))):
229
        if ((cond) and (not check_condition(cond, defaults, ask_names))):
231
            continue
230
            continue
232
       
231
       
233
        if (not defaults.has_key(varname)):
232
        if (not defaults.has_key(varname)):
234
            default = ''
233
            default = ''
Line 256... Line 255...
256
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
255
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
257
        if (check_choices(defaults, ask_names)):
256
        if (check_choices(defaults, ask_names)):
258
            create_output(OUTPUT, defaults, ask_names)
257
            create_output(OUTPUT, defaults, ask_names)
259
            return 0
258
            return 0
260
   
259
   
261
    screen = snack.SnackScreen()
260
    screen = xtui.screen_init()
262
    try:
261
    try:
263
        selname = None
262
        selname = None
264
        while True:
263
        while True:
265
           
264
           
266
            options = []
265
            options = []
267
            opt2row = {}
266
            opt2row = {}
268
            position = None
267
            position = None
269
            cnt = 0
268
            cnt = 0
270
            for row in ask_names:
269
            for varname, vartype, name, choices, cond in ask_names:
271
               
-
 
272
                varname = row[0]
-
 
273
                vartype = row[1]
-
 
274
                name = row[2]
-
 
275
                choices = row[3]
-
 
276
                cond = row[4]
-
 
277
               
270
               
278
                if ((cond) and (not check_condition(cond, defaults, ask_names))):
271
                if ((cond) and (not check_condition(cond, defaults, ask_names))):
279
                    continue
272
                    continue
280
               
273
               
281
                if (varname == selname):
274
                if (varname == selname):
Line 309... Line 302...
309
                        defaults[varname] = default
302
                        defaults[varname] = default
310
                    options.append(" <%s> %s " % (yes_no(default), name))
303
                    options.append(" <%s> %s " % (yes_no(default), name))
311
                else:
304
                else:
312
                    raise RuntimeError("Unknown variable type: %s" % vartype)
305
                    raise RuntimeError("Unknown variable type: %s" % vartype)
313
               
306
               
314
                opt2row[cnt] = row
307
                opt2row[cnt] = (varname, vartype, name, choices)
315
               
308
               
316
                cnt += 1
309
                cnt += 1
317
           
310
           
318
            retval = snack.ListboxChoiceWindow(screen, 'HelenOS configuration', 'Choose configuration option', options, default = position)
311
            (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position)
319
           
312
           
320
            if (retval[0] == 'cancel'):
313
            if (button == 'cancel'):
321
                return 'Configuration canceled'
314
                return 'Configuration canceled'
322
           
315
           
323
            row = opt2row[retval[1]]
316
            if (not opt2row.has_key(value)):
324
            if (row == None):
-
 
325
                raise RuntimeError("Error selecting value: %s" % retval[1])
317
                raise RuntimeError("Error selecting value: %s" % value)
326
           
318
           
327
            selname = row[0]
319
            (selname, seltype, name, choices) = opt2row[value]
-
 
320
           
-
 
321
            if (not defaults.has_key(selname)):
328
            seltype = row[1]
322
                    default = None
329
            name = row[2]
323
            else:
330
            choices = row[3]
324
                default = defaults[selname]
331
           
325
           
332
            if (retval[0] == 'ok'):
326
            if (button == 'done'):
333
                if (check_choices(defaults, ask_names)):
327
                if (check_choices(defaults, ask_names)):
334
                    break
328
                    break
335
                else:
329
                else:
336
                    snack.ButtonChoiceWindow(screen, 'Error', 'Some options have still undefined values.', ['Ok']);
330
                    xtui.error_dialog(screen, 'Error', 'Some options have still undefined values.')
337
                    continue
331
                    continue
338
           
332
           
339
            if (seltype == 'choice'):
333
            if (seltype == 'choice'):
340
                defaults[selname] = subchoice(screen, name, choices)
334
                defaults[selname] = subchoice(screen, name, choices, default)
341
            elif ((seltype == 'y/n') or (seltype == 'n/y')):
335
            elif ((seltype == 'y/n') or (seltype == 'n/y')):
342
                if (defaults[selname] == 'y'):
336
                if (defaults[selname] == 'y'):
343
                    defaults[selname] = 'n'
337
                    defaults[selname] = 'n'
344
                else:
338
                else:
345
                    defaults[selname] = 'y'
339
                    defaults[selname] = 'y'
346
    finally:
340
    finally:
347
        screen.finish()
341
        xtui.screen_done(screen)
348
   
342
   
349
    create_output(OUTPUT, defaults, ask_names)
343
    create_output(OUTPUT, defaults, ask_names)
350
    return 0
344
    return 0
351
 
345
 
352
if __name__ == '__main__':
346
if __name__ == '__main__':