Subversion Repositories HelenOS-historic

Rev

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

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