Subversion Repositories HelenOS-historic

Rev

Rev 556 | Rev 559 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 556 Rev 558
1
#!/usr/bin/env python
1
#!/usr/bin/env python
2
"""
2
"""
3
Kernel configuration script
3
Kernel configuration script
4
"""
4
"""
5
import sys
5
import sys
6
import os
6
import os
7
import re
7
import re
8
 
8
 
9
INPUT = 'kernel.config'
9
INPUT = 'kernel.config'
10
OUTPUT = 'Makefile.config'
10
OUTPUT = 'Makefile.config'
11
TMPOUTPUT = 'Makefile.config.tmp'
11
TMPOUTPUT = 'Makefile.config.tmp'
12
 
12
 
13
class DefaultDialog:
13
class DefaultDialog:
14
    "Wrapper dialog that tries to return default values"
14
    "Wrapper dialog that tries to return default values"
15
    def __init__(self, dlg):
15
    def __init__(self, dlg):
16
        self.dlg = dlg
16
        self.dlg = dlg
17
 
17
 
18
    def set_title(self,text):
18
    def set_title(self,text):
19
        self.dlg.set_title(text)
19
        self.dlg.set_title(text)
20
       
20
       
21
    def yesno(self, text, default=None):
21
    def yesno(self, text, default=None):
22
        if default is not None:
22
        if default is not None:
23
            return default
23
            return default
24
        return self.dlg.yesno(text, default)
24
        return self.dlg.yesno(text, default)
25
    def noyes(self, text, default=None):
25
    def noyes(self, text, default=None):
26
        if default is not None:
26
        if default is not None:
27
            return default
27
            return default
28
        return self.dlg.noyes(text, default)
28
        return self.dlg.noyes(text, default)
29
   
29
   
30
    def choice(self, text, choices, defopt=None):
30
    def choice(self, text, choices, defopt=None):
31
        if defopt is not None:
31
        if defopt is not None:
32
            return choices[defopt][0]
32
            return choices[defopt][0]
33
        return self.dlg.choice(text, choices, defopt)
33
        return self.dlg.choice(text, choices, defopt)
34
 
34
 
35
class NoDialog:
35
class NoDialog:
36
    def __init__(self):
36
    def __init__(self):
37
        self.printed = None
37
        self.printed = None
38
        self.title = 'HelenOS Configuration'
38
        self.title = 'HelenOS Configuration'
39
 
39
 
40
    def print_title(self):
40
    def print_title(self):
41
        if not self.printed:
41
        if not self.printed:
42
            sys.stdout.write("\n*** %s ***\n" % self.title)
42
            sys.stdout.write("\n*** %s ***\n" % self.title)
43
            self.printed = True
43
            self.printed = True
44
 
44
 
45
    def set_title(self, text):
45
    def set_title(self, text):
46
        self.title = text
46
        self.title = text
47
        self.printed = False
47
        self.printed = False
48
   
48
   
49
    def noyes(self, text, default=None):
49
    def noyes(self, text, default=None):
50
        if not default:
50
        if not default:
51
            default = 'n'
51
            default = 'n'
52
        return self.yesno(text, default)
52
        return self.yesno(text, default)
53
   
53
   
54
    def yesno(self, text, default=None):
54
    def yesno(self, text, default=None):
55
        self.print_title()
55
        self.print_title()
56
       
56
       
57
        if default != 'n':
57
        if default != 'n':
58
            default = 'y'
58
            default = 'y'
59
        while 1:
59
        while 1:
60
            sys.stdout.write("%s (y/n)[%s]: " % (text,default))
60
            sys.stdout.write("%s (y/n)[%s]: " % (text,default))
61
            inp = sys.stdin.readline()
61
            inp = sys.stdin.readline()
62
            if not inp:
62
            if not inp:
63
                raise EOFError
63
                raise EOFError
64
            inp = inp.strip().lower()
64
            inp = inp.strip().lower()
65
            if not inp:
65
            if not inp:
66
                return default
66
                return default
67
            if inp == 'y':
67
            if inp == 'y':
68
                return 'y'
68
                return 'y'
69
            elif inp == 'n':
69
            elif inp == 'n':
70
                return 'n'
70
                return 'n'
71
 
71
 
72
    def _print_choice(self, text, choices, defopt):
72
    def _print_choice(self, text, choices, defopt):
73
        sys.stdout.write('%s:\n' % text)
73
        sys.stdout.write('%s:\n' % text)
74
        for i,(text,descr) in enumerate(choices):
74
        for i,(text,descr) in enumerate(choices):
75
            sys.stdout.write('\t%2d. %s\n' % (i, descr))
75
            sys.stdout.write('\t%2d. %s\n' % (i, descr))
76
        if defopt is not None:
76
        if defopt is not None:
77
            sys.stdout.write('Enter choice number[%d]: ' % defopt)
77
            sys.stdout.write('Enter choice number[%d]: ' % defopt)
78
        else:
78
        else:
79
            sys.stdout.write('Enter choice number: ')
79
            sys.stdout.write('Enter choice number: ')
80
 
80
 
81
    def menu(self, text, choices, button, defopt=None):
81
    def menu(self, text, choices, button, defopt=None):
82
        menu = []
82
        menu = []
83
        for key, descr in choices:
83
        for key, descr in choices:
84
            txt = key + (45-len(key))*' ' + ': ' + descr
84
            txt = key + (45-len(key))*' ' + ': ' + descr
85
            menu.append((key, txt))
85
            menu.append((key, txt))
86
           
86
           
87
        return self.choice(text, [button] + menu)
87
        return self.choice(text, [button] + menu)
88
       
88
       
89
    def choice(self, text, choices, defopt=None):
89
    def choice(self, text, choices, defopt=None):
90
        self.print_title()
90
        self.print_title()
91
        while 1:
91
        while 1:
92
            self._print_choice(text, choices, defopt)
92
            self._print_choice(text, choices, defopt)
93
            inp = sys.stdin.readline()
93
            inp = sys.stdin.readline()
94
            if not inp:
94
            if not inp:
95
                raise EOFError
95
                raise EOFError
96
            if not inp.strip():
96
            if not inp.strip():
97
                if defopt is not None:
97
                if defopt is not None:
98
                    return choices[defopt][0]
98
                    return choices[defopt][0]
99
                continue
99
                continue
100
            try:
100
            try:
101
                number = int(inp.strip())
101
                number = int(inp.strip())
102
            except ValueError:
102
            except ValueError:
103
                continue
103
                continue
104
            if number < 0 or number >= len(choices):
104
            if number < 0 or number >= len(choices):
105
                continue
105
                continue
106
            return choices[number][0]
106
            return choices[number][0]
107
 
107
 
108
 
108
 
109
class Dialog(NoDialog):
109
class Dialog(NoDialog):
110
    def __init__(self):
110
    def __init__(self):
111
        NoDialog.__init__(self)
111
        NoDialog.__init__(self)
112
        self.dlgcmd = os.environ.get('DIALOG','dialog')
112
        self.dlgcmd = os.environ.get('DIALOG','dialog')
113
        self.title = ''
113
        self.title = ''
114
        self.backtitle = 'HelenOS Kernel Configuration'
114
        self.backtitle = 'HelenOS Kernel Configuration'
115
       
115
       
116
        if os.system('%s --print-maxsize >/dev/null 2>&1' % self.dlgcmd) != 0:
116
        if os.system('%s --print-maxsize >/dev/null 2>&1' % self.dlgcmd) != 0:
117
            raise NotImplementedError
117
            raise NotImplementedError
118
 
118
 
119
    def set_title(self,text):
119
    def set_title(self,text):
120
        self.title = text
120
        self.title = text
121
       
121
       
122
    def calldlg(self,*args,**kw):
122
    def calldlg(self,*args,**kw):
123
        "Wrapper for calling 'dialog' program"
123
        "Wrapper for calling 'dialog' program"
124
        indesc, outdesc = os.pipe()
124
        indesc, outdesc = os.pipe()
125
        pid = os.fork()
125
        pid = os.fork()
126
        if not pid:
126
        if not pid:
127
            os.close(2)
127
            os.close(2)
128
            os.dup(outdesc)
128
            os.dup(outdesc)
129
            os.close(indesc)
129
            os.close(indesc)
130
           
130
           
131
            dlgargs = [self.dlgcmd,'--title',self.title,
131
            dlgargs = [self.dlgcmd,'--title',self.title,
132
                       '--backtitle', self.backtitle]
132
                       '--backtitle', self.backtitle]
133
            for key,val in kw.items():
133
            for key,val in kw.items():
134
                dlgargs.append('--'+key)
134
                dlgargs.append('--'+key)
135
                dlgargs.append(val)
135
                dlgargs.append(val)
136
            dlgargs += args            
136
            dlgargs += args            
137
            os.execlp(self.dlgcmd,*dlgargs)
137
            os.execlp(self.dlgcmd,*dlgargs)
138
 
138
 
139
        os.close(outdesc)
139
        os.close(outdesc)
-
 
140
       
-
 
141
        try:
140
        errout = os.fdopen(indesc,'r')
142
            errout = os.fdopen(indesc,'r')
141
        data = errout.read()
143
            data = errout.read()
142
        errout.close()
144
            errout.close()
-
 
145
            pid,status = os.wait()
143
           
146
        except:
-
 
147
            os.system('reset') # Reset terminal
144
        pid,status = os.wait()
148
            raise
-
 
149
       
145
        if not os.WIFEXITED(status):
150
        if not os.WIFEXITED(status):
-
 
151
            os.system('reset') # Reset terminal
146
            raise EOFError
152
            raise EOFError
-
 
153
       
147
        status = os.WEXITSTATUS(status)
154
        status = os.WEXITSTATUS(status)
148
        if status == 255:
155
        if status == 255:
149
            raise EOFError
156
            raise EOFError
150
        return status,data
157
        return status,data
151
       
158
       
152
    def yesno(self, text, default=None):
159
    def yesno(self, text, default=None):
-
 
160
        if text[-1] not in ('?',':'):
153
        text = text + ':'
161
            text = text + ':'
154
        width = '50'
162
        width = '50'
155
        height = '5'
163
        height = '5'
156
        if len(text) < 48:
164
        if len(text) < 48:
157
            text = ' '*int(((48-len(text))/2)) + text
165
            text = ' '*int(((48-len(text))/2)) + text
158
        else:
166
        else:
159
            width = '0'
167
            width = '0'
160
            height = '0'
168
            height = '0'
161
        if default == 'n':
169
        if default == 'n':
162
            res,data = self.calldlg('--defaultno','--yesno',text,height,width)
170
            res,data = self.calldlg('--defaultno','--yesno',text,height,width)
163
        else:
171
        else:
164
            res,data = self.calldlg('--yesno',text,height,width)
172
            res,data = self.calldlg('--yesno',text,height,width)
165
 
173
 
166
        if res == 0:
174
        if res == 0:
167
            return 'y'
175
            return 'y'
168
        return 'n'
176
        return 'n'
169
 
177
 
170
    def menu(self, text, choices, button, defopt=None):
178
    def menu(self, text, choices, button, defopt=None):
171
        text = text + ':'
179
        text = text + ':'
172
        width = '70'
180
        width = '70'
173
        height = str(8 + len(choices))
181
        height = str(8 + len(choices))
174
        args = []
182
        args = []
175
        for key,val in choices:
183
        for key,val in choices:
176
            args.append(key)
184
            args.append(key)
177
            args.append(val)
185
            args.append(val)
178
 
186
 
179
        kw = {}
187
        kw = {}
180
        if defopt:
188
        if defopt:
181
            kw['default-item'] = choices[defopt][0]
189
            kw['default-item'] = choices[defopt][0]
182
        res,data = self.calldlg('--cancel-label',button[1],
190
        res,data = self.calldlg('--cancel-label',button[1],
183
                                '--menu',text,height,width,
191
                                '--menu',text,height,width,
184
                                str(len(choices)),*args,**kw)
192
                                str(len(choices)),*args,**kw)
185
        if res == 1:
193
        if res == 1:
186
            return button[0]
194
            return button[0]
187
        elif res:
195
        elif res:
188
            print data
196
            print data
189
            raise EOFError
197
            raise EOFError
190
        return data
198
        return data
191
   
199
   
192
    def choice(self, text, choices, defopt=None):
200
    def choice(self, text, choices, defopt=None):
193
        text = text + ':'
201
        text = text + ':'
194
        width = '50'
202
        width = '50'
195
        height = str(8 + len(choices))
203
        height = str(8 + len(choices))
196
        args = []
204
        args = []
197
        for key,val in choices:
205
        for key,val in choices:
198
            args.append(key)
206
            args.append(key)
199
            args.append(val)
207
            args.append(val)
200
 
208
 
201
        kw = {}
209
        kw = {}
202
        if defopt:
210
        if defopt:
203
            kw['default-item'] = choices[defopt][0]
211
            kw['default-item'] = choices[defopt][0]
204
        res,data = self.calldlg('--nocancel','--menu',text,height,width,
212
        res,data = self.calldlg('--nocancel','--menu',text,height,width,
205
                                str(len(choices)),*args, **kw)
213
                                str(len(choices)),*args, **kw)
206
        if res:
214
        if res:
207
            print data
215
            print data
208
            raise EOFError
216
            raise EOFError
209
        return data
217
        return data
210
   
218
   
211
def read_defaults(fname,defaults):
219
def read_defaults(fname,defaults):
212
    "Read saved values from last configuration run"
220
    "Read saved values from last configuration run"
213
    f = file(fname,'r')
221
    f = file(fname,'r')
214
    for line in f:
222
    for line in f:
215
        res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
223
        res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
216
        if res:
224
        if res:
217
            defaults[res.group(1)] = res.group(2)
225
            defaults[res.group(1)] = res.group(2)
218
    f.close()
226
    f.close()
219
 
227
 
220
def check_condition(text, defaults):
228
def check_condition(text, defaults):
221
    result = True
229
    result = True
222
    conds = text.split('&')
230
    conds = text.split('&')
223
    for cond in conds:
231
    for cond in conds:
224
        if cond.startswith('(') and cond.endswith(')'):
232
        if cond.startswith('(') and cond.endswith(')'):
225
            cond = cond[1:-1]
233
            cond = cond[1:-1]
226
        if not check_dnf(cond, defaults):
234
        if not check_dnf(cond, defaults):
227
            return False
235
            return False
228
    return True
236
    return True
229
 
237
 
230
def check_dnf(text, defaults):
238
def check_dnf(text, defaults):
231
    """
239
    """
232
    Check that the condition specified on input line is True
240
    Check that the condition specified on input line is True
233
 
241
 
234
    only CNF is supported
242
    only CNF is supported
235
    """
243
    """
236
    conds = text.split('|')
244
    conds = text.split('|')
237
    for cond in conds:
245
    for cond in conds:
238
        res = re.match(r'^(.*?)(!?=)(.*)$', cond)
246
        res = re.match(r'^(.*?)(!?=)(.*)$', cond)
239
        if not res:
247
        if not res:
240
            raise RuntimeError("Invalid condition: %s" % cond)
248
            raise RuntimeError("Invalid condition: %s" % cond)
241
        condname = res.group(1)
249
        condname = res.group(1)
242
        oper = res.group(2)
250
        oper = res.group(2)
243
        condval = res.group(3)
251
        condval = res.group(3)
244
        if not defaults.has_key(condname):
252
        if not defaults.has_key(condname):
245
            raise RuntimeError("Condition var %s does not exist: %s" % \
253
            raise RuntimeError("Condition var %s does not exist: %s" % \
246
                               (condname,text))
254
                               (condname,text))
247
 
255
 
248
        if oper=='=' and  condval == defaults[condname]:
256
        if oper=='=' and  condval == defaults[condname]:
249
            return True
257
            return True
250
        if oper == '!=' and condval != defaults[condname]:
258
        if oper == '!=' and condval != defaults[condname]:
251
            return True
259
            return True
252
    return False
260
    return False
253
 
261
 
254
def parse_config(input, output, dlg, defaults={}, askonly=None):
262
def parse_config(input, output, dlg, defaults={}, askonly=None):
255
    "Parse configuration file and create Makefile.config on the fly"
263
    "Parse configuration file and create Makefile.config on the fly"
256
    def ask_the_question():
264
    def ask_the_question():
257
        "Ask question based on the type of variables to ask"
265
        "Ask question based on the type of variables to ask"
258
        # This is quite a hack, this thingy is written just to
266
        # This is quite a hack, this thingy is written just to
259
        # have access to local variables..
267
        # have access to local variables..
260
        if vartype == 'y/n':
268
        if vartype == 'y/n':
261
            return dlg.yesno(comment, default)
269
            return dlg.yesno(comment, default)
262
        elif vartype == 'n/y':
270
        elif vartype == 'n/y':
263
            return dlg.noyes(comment, default)
271
            return dlg.noyes(comment, default)
264
        elif vartype == 'choice':
272
        elif vartype == 'choice':
265
            defopt = None
273
            defopt = None
266
            if default is not None:
274
            if default is not None:
267
                for i,(key,val) in enumerate(choices):
275
                for i,(key,val) in enumerate(choices):
268
                    if key == default:
276
                    if key == default:
269
                        defopt = i
277
                        defopt = i
270
                        break
278
                        break
271
            return dlg.choice(comment, choices, defopt)
279
            return dlg.choice(comment, choices, defopt)
272
        else:
280
        else:
273
            raise RuntimeError("Bad method: %s" % vartype)
281
            raise RuntimeError("Bad method: %s" % vartype)
274
 
282
 
275
   
283
   
276
    f = file(input, 'r')
284
    f = file(input, 'r')
277
    outf = file(output, 'w')
285
    outf = file(output, 'w')
278
 
286
 
279
    outf.write('#########################################\n')
287
    outf.write('#########################################\n')
280
    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
288
    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
281
    outf.write('#########################################\n\n')
289
    outf.write('#########################################\n\n')
282
 
290
 
283
    asked_names = []
291
    asked_names = []
284
 
292
 
285
    comment = ''
293
    comment = ''
286
    default = None
294
    default = None
287
    choices = []
295
    choices = []
288
    for line in f:
296
    for line in f:
289
        if line.startswith('%'):
297
        if line.startswith('%'):
290
            res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line)
298
            res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line)
291
            if not res:
299
            if not res:
292
                raise RuntimeError('Invalid command: %s' % line)
300
                raise RuntimeError('Invalid command: %s' % line)
293
            if res.group(1):
301
            if res.group(1):
294
                if not check_condition(res.group(1), defaults):
302
                if not check_condition(res.group(1), defaults):
295
                    continue
303
                    continue
296
            args = res.group(2).strip().split(' ')
304
            args = res.group(2).strip().split(' ')
297
            cmd = args[0].lower()
305
            cmd = args[0].lower()
298
            args = args[1:]
306
            args = args[1:]
299
            if cmd == 'saveas':
307
            if cmd == 'saveas':
300
                outf.write('%s = %s\n' % (args[1],defaults[args[0]]))
308
                outf.write('%s = %s\n' % (args[1],defaults[args[0]]))
301
               
309
               
302
            continue
310
            continue
303
           
311
           
304
        if line.startswith('!'):
312
        if line.startswith('!'):
305
            # Ask a question
313
            # Ask a question
306
            res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line)
314
            res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line)
307
            if not res:
315
            if not res:
308
                raise RuntimeError("Weird line: %s" % line)
316
                raise RuntimeError("Weird line: %s" % line)
309
            varname = res.group(2)
317
            varname = res.group(2)
310
            vartype = res.group(3)
318
            vartype = res.group(3)
311
 
319
 
312
            default = defaults.get(varname,None)
320
            default = defaults.get(varname,None)
313
           
321
           
314
            if res.group(1):
322
            if res.group(1):
315
                if not check_condition(res.group(1), defaults):
323
                if not check_condition(res.group(1), defaults):
316
                    if default is not None:
324
                    if default is not None:
317
                        outf.write('#!# %s = %s\n' % (varname, default))
325
                        outf.write('#!# %s = %s\n' % (varname, default))
318
                    # Clear cumulated values
326
                    # Clear cumulated values
319
                    comment = ''
327
                    comment = ''
320
                    default = None
328
                    default = None
321
                    choices = []
329
                    choices = []
322
                    continue
330
                    continue
323
               
331
               
324
            asked_names.append((varname,comment))
332
            asked_names.append((varname,comment))
325
 
333
 
326
            if default is None or not askonly or askonly == varname:
334
            if default is None or not askonly or askonly == varname:
327
                default = ask_the_question()
335
                default = ask_the_question()
328
 
336
 
329
            outf.write('%s = %s\n' % (varname, default))
337
            outf.write('%s = %s\n' % (varname, default))
330
            # Remeber the selected value
338
            # Remeber the selected value
331
            defaults[varname] = default
339
            defaults[varname] = default
332
            # Clear cumulated values
340
            # Clear cumulated values
333
            comment = ''
341
            comment = ''
334
            default = None
342
            default = None
335
            choices = []
343
            choices = []
336
            continue
344
            continue
337
       
345
       
338
        if line.startswith('@'):
346
        if line.startswith('@'):
339
            # Add new line into the 'choice array' 
347
            # Add new line into the 'choice array' 
340
            res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
348
            res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
341
            if not res:
349
            if not res:
342
                raise RuntimeError("Bad line: %s" % line)
350
                raise RuntimeError("Bad line: %s" % line)
343
            if res.group(1):
351
            if res.group(1):
344
                if not check_condition(res.group(1),defaults):
352
                if not check_condition(res.group(1),defaults):
345
                    continue
353
                    continue
346
            choices.append((res.group(2), res.group(3)))
354
            choices.append((res.group(2), res.group(3)))
347
            continue
355
            continue
348
 
356
 
349
        # All other things print to output file
357
        # All other things print to output file
350
        outf.write(line)
358
        outf.write(line)
351
        if re.match(r'^#[^#]', line):
359
        if re.match(r'^#[^#]', line):
352
            # Last comment before question will be displayed to the user
360
            # Last comment before question will be displayed to the user
353
            comment = line[1:].strip()
361
            comment = line[1:].strip()
354
        elif line.startswith('## '):
362
        elif line.startswith('## '):
355
            # Set title of the dialog window
363
            # Set title of the dialog window
356
            dlg.set_title(line[2:].strip())
364
            dlg.set_title(line[2:].strip())
357
       
365
       
358
    outf.close()
366
    outf.close()
359
    f.close()
367
    f.close()
360
    return asked_names
368
    return asked_names
361
 
369
 
362
def main():
370
def main():
363
    defaults = {}
371
    defaults = {}
364
    try:
372
    try:
365
        dlg = Dialog()
373
        dlg = Dialog()
366
    except NotImplementedError:
374
    except NotImplementedError:
367
        dlg = NoDialog()
375
        dlg = NoDialog()
368
 
376
 
369
    if len(sys.argv) == 2 and sys.argv[1]=='default':
377
    if len(sys.argv) == 2 and sys.argv[1]=='default':
370
        defmode = True
378
        defmode = True
371
    else:
379
    else:
372
        defmode = False
380
        defmode = False
373
 
381
 
374
    # Default run will update the configuration file
382
    # Default run will update the configuration file
375
    # with newest options
383
    # with newest options
376
    if os.path.exists(OUTPUT):
384
    if os.path.exists(OUTPUT):
377
        read_defaults(OUTPUT, defaults)
385
        read_defaults(OUTPUT, defaults)
378
 
386
 
379
    # Dry run only with defaults
387
    # Dry run only with defaults
380
    varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
388
    varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
381
    # If not in default mode, present selection of all possibilities
389
    # If not in default mode, present selection of all possibilities
382
    if not defmode:
390
    if not defmode:
383
        defopt = 0
391
        defopt = 0
384
        while 1:
392
        while 1:
385
            # varnames contains variable names that were in the
393
            # varnames contains variable names that were in the
386
            # last question set
394
            # last question set
387
            choices = [ (x[1],defaults[x[0]]) for x in varnames ]
395
            choices = [ (x[1],defaults[x[0]]) for x in varnames ]
388
            res = dlg.menu('Configuration',choices,('save','Save'),defopt)
396
            res = dlg.menu('Configuration',choices,('save','Save'),defopt)
389
            if res == 'save':
397
            if res == 'save':
390
                parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
398
                parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
391
                break
399
                break
392
            # transfer description back to varname
400
            # transfer description back to varname
393
            for i,(vname,descr) in enumerate(varnames):
401
            for i,(vname,descr) in enumerate(varnames):
394
                if res == descr:
402
                if res == descr:
395
                    defopt = i
403
                    defopt = i
396
                    break
404
                    break
397
            # Ask the user a simple question, produce output
405
            # Ask the user a simple question, produce output
398
            # as if the user answered all the other questions
406
            # as if the user answered all the other questions
399
            # with default answer
407
            # with default answer
400
            varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults,
408
            varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults,
401
                                    askonly=varnames[i][0])
409
                                    askonly=varnames[i][0])
402
       
410
       
403
   
411
   
404
    if os.path.exists(OUTPUT):
412
    if os.path.exists(OUTPUT):
405
        os.unlink(OUTPUT)
413
        os.unlink(OUTPUT)
406
    os.rename(TMPOUTPUT, OUTPUT)
414
    os.rename(TMPOUTPUT, OUTPUT)
407
       
415
   
-
 
416
    if not defmode and dlg.yesno('Rebuild kernel?') == 'y':
-
 
417
        os.execlp('make','make','clean','all')
408
 
418
 
409
if __name__ == '__main__':
419
if __name__ == '__main__':
410
    main()
420
    main()
411
 
421