Subversion Repositories HelenOS-historic

Rev

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

Rev 552 Rev 554
Line 75... Line 75...
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
 
-
 
81
    def menu(self, text, choices, button, defopt=None):
-
 
82
        return self.choice(text, [button] + choices)
80
       
83
       
81
    def choice(self, text, choices, defopt=None):
84
    def choice(self, text, choices, defopt=None):
82
        self.print_title()
85
        self.print_title()
83
        while 1:
86
        while 1:
84
            self._print_choice(text, choices, defopt)
87
            self._print_choice(text, choices, defopt)
Line 100... Line 103...
100
 
103
 
101
class Dialog(NoDialog):
104
class Dialog(NoDialog):
102
    def __init__(self):
105
    def __init__(self):
103
        NoDialog.__init__(self)
106
        NoDialog.__init__(self)
104
        self.dlgcmd = os.environ.get('DIALOG','dialog')
107
        self.dlgcmd = os.environ.get('DIALOG','dialog')
-
 
108
        self.title = ''
105
        self.title = 'HelenOS Configuration'
109
        self.backtitle = 'HelenOS Kernel Configuration'
106
       
110
       
107
        if os.system('%s --print-maxsize >/dev/null 2>&1' % self.dlgcmd) != 0:
111
        if os.system('%s --print-maxsize >/dev/null 2>&1' % self.dlgcmd) != 0:
108
            raise NotImplementedError
112
            raise NotImplementedError
109
 
113
 
110
    def set_title(self,text):
114
    def set_title(self,text):
Line 117... Line 121...
117
        if not pid:
121
        if not pid:
118
            os.close(2)
122
            os.close(2)
119
            os.dup(outdesc)
123
            os.dup(outdesc)
120
            os.close(indesc)
124
            os.close(indesc)
121
           
125
           
122
            dlgargs = [self.dlgcmd,'--title',self.title]
126
            dlgargs = [self.dlgcmd,'--title',self.title,
-
 
127
                       '--backtitle', self.backtitle]
123
            for key,val in kw.items():
128
            for key,val in kw.items():
124
                dlgargs.append('--'+key)
129
                dlgargs.append('--'+key)
125
                dlgargs.append(val)
130
                dlgargs.append(val)
126
            dlgargs += args            
131
            dlgargs += args            
127
            os.execlp(self.dlgcmd,*dlgargs)
132
            os.execlp(self.dlgcmd,*dlgargs)
Line 154... Line 159...
154
            res,data = self.calldlg('--yesno',text,height,width)
159
            res,data = self.calldlg('--yesno',text,height,width)
155
 
160
 
156
        if res == 0:
161
        if res == 0:
157
            return 'y'
162
            return 'y'
158
        return 'n'
163
        return 'n'
-
 
164
 
-
 
165
    def menu(self, text, choices, button, defopt=None):
-
 
166
        text = text + ':'
-
 
167
        width = '70'
-
 
168
        height = str(8 + len(choices))
-
 
169
        args = []
-
 
170
        for key,val in choices:
-
 
171
            args.append(key)
-
 
172
            args.append(val)
-
 
173
 
-
 
174
        kw = {}
-
 
175
        if defopt:
-
 
176
            kw['default-item'] = choices[defopt][0]
-
 
177
        res,data = self.calldlg('--cancel-label',button[1],
-
 
178
                                '--menu',text,height,width,
-
 
179
                                str(len(choices)),*args,**kw)
-
 
180
        if res == 1:
-
 
181
            return button[0]
-
 
182
        elif res:
-
 
183
            print data
-
 
184
            raise EOFError
-
 
185
        return data
159
   
186
   
160
    def choice(self, text, choices, defopt=None):
187
    def choice(self, text, choices, defopt=None):
161
        text = text + ':'
188
        text = text + ':'
162
        width = '50'
189
        width = '50'
163
        height = str(8 + len(choices))
190
        height = str(8 + len(choices))
Line 217... Line 244...
217
            return True
244
            return True
218
        if oper == '!=' and condval != defaults[condname]:
245
        if oper == '!=' and condval != defaults[condname]:
219
            return True
246
            return True
220
    return False
247
    return False
221
 
248
 
222
def parse_config(input, output, dlg, defaults={}):
249
def parse_config(input, output, dlg, defaults={}, askonly=None):
223
    "Parse configuration file and create Makefile.config on the fly"
250
    "Parse configuration file and create Makefile.config on the fly"
224
    f = file(input, 'r')
251
    f = file(input, 'r')
225
    outf = file(output, 'w')
252
    outf = file(output, 'w')
226
 
253
 
227
    outf.write('#########################################\n')
254
    outf.write('#########################################\n')
228
    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
255
    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
229
    outf.write('#########################################\n\n')
256
    outf.write('#########################################\n\n')
230
 
257
 
-
 
258
    asked_names = []
-
 
259
 
231
    comment = ''
260
    comment = ''
232
    default = None
261
    default = None
233
    choices = []
262
    choices = []
234
    for line in f:
263
    for line in f:
235
        if line.startswith('%'):
264
        if line.startswith('%'):
Line 240... Line 269...
240
                if not check_condition(res.group(1), defaults):
269
                if not check_condition(res.group(1), defaults):
241
                    continue
270
                    continue
242
            args = res.group(2).strip().split(' ')
271
            args = res.group(2).strip().split(' ')
243
            cmd = args[0].lower()
272
            cmd = args[0].lower()
244
            args = args[1:]
273
            args = args[1:]
245
            if cmd == 'askdefault':
-
 
246
                if isinstance(dlg, DefaultDialog):
-
 
247
                    continue
-
 
248
                res = dlg.noyes('Change kernel configuration')
-
 
249
                if res == 'n':
-
 
250
                    dlg = DefaultDialog(dlg)
-
 
251
            elif cmd == 'saveas':
274
            if cmd == 'saveas':
252
                outf.write('%s = %s\n' % (args[1],defaults[args[0]]))
275
                outf.write('%s = %s\n' % (args[1],defaults[args[0]]))
253
               
276
               
254
            continue
277
            continue
255
           
278
           
256
        if line.startswith('!'):
279
        if line.startswith('!'):
Line 260... Line 283...
260
                raise RuntimeError("Weird line: %s" % line)
283
                raise RuntimeError("Weird line: %s" % line)
261
            varname = res.group(2)
284
            varname = res.group(2)
262
            vartype = res.group(3)
285
            vartype = res.group(3)
263
 
286
 
264
            default = defaults.get(varname,None)
287
            default = defaults.get(varname,None)
265
 
288
           
266
            if res.group(1):
289
            if res.group(1):
267
                if not check_condition(res.group(1), defaults):
290
                if not check_condition(res.group(1), defaults):
268
                    if default is not None:
291
                    if default is not None:
269
                        outf.write('#!# %s = %s\n' % (varname, default))
292
                        outf.write('#!# %s = %s\n' % (varname, default))
270
                    # Clear cumulated values
293
                    # Clear cumulated values
271
                    comment = ''
294
                    comment = ''
272
                    default = None
295
                    default = None
273
                    choices = []
296
                    choices = []
274
                    continue
297
                    continue
-
 
298
               
-
 
299
            asked_names.append((varname,comment))
-
 
300
 
-
 
301
            if default is not None and askonly and askonly != varname:
-
 
302
                outf.write('%s = %s\n' % (varname, default))
-
 
303
                continue
275
 
304
 
276
            if vartype == 'y/n':
305
            if vartype == 'y/n':
277
                result = dlg.yesno(comment, default)
306
                result = dlg.yesno(comment, default)
278
            elif vartype == 'n/y':
307
            elif vartype == 'n/y':
279
                result = dlg.noyes(comment, default)
308
                result = dlg.noyes(comment, default)
Line 316... Line 345...
316
            # Set title of the dialog window
345
            # Set title of the dialog window
317
            dlg.set_title(line[2:].strip())
346
            dlg.set_title(line[2:].strip())
318
       
347
       
319
    outf.close()
348
    outf.close()
320
    f.close()
349
    f.close()
-
 
350
    return asked_names
321
 
351
 
322
def main():
352
def main():
323
    defaults = {}
353
    defaults = {}
324
    try:
354
    try:
325
        dlg = Dialog()
355
        dlg = Dialog()
326
    except NotImplementedError:
356
    except NotImplementedError:
327
        dlg = NoDialog()
357
        dlg = NoDialog()
328
 
358
 
329
    # Default run will update the configuration file
-
 
330
    # with newest options
-
 
331
    if len(sys.argv) == 2 and sys.argv[1]=='default':
359
    if len(sys.argv) == 2 and sys.argv[1]=='default':
-
 
360
        defmode = True
-
 
361
    else:
332
        dlg = DefaultDialog(dlg)
362
        defmode = False
333
 
363
 
-
 
364
    # Default run will update the configuration file
-
 
365
    # with newest options
334
    if os.path.exists(OUTPUT):
366
    if os.path.exists(OUTPUT):
335
        read_defaults(OUTPUT, defaults)
367
        read_defaults(OUTPUT, defaults)
336
   
368
   
-
 
369
    varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
-
 
370
    # If not in default mode, present selection of all possibilities
-
 
371
    if not defmode:
-
 
372
        defopt = 0
-
 
373
        while 1:
-
 
374
            choices = [ (x[1],defaults[x[0]]) for x in varnames ]
-
 
375
            res = dlg.menu('Configuration',choices,('save','Save'),defopt)
-
 
376
            if res == 'save':
-
 
377
                parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
-
 
378
                break
-
 
379
            # transfer description back to varname
-
 
380
            for i,(vname,descr) in enumerate(varnames):
-
 
381
                if res == descr:
-
 
382
                    defopt = i
-
 
383
                    break
337
    parse_config(INPUT, TMPOUTPUT, dlg, defaults)
384
            varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults,
-
 
385
                                    askonly=varnames[i][0])
-
 
386
       
-
 
387
   
338
    if os.path.exists(OUTPUT):
388
    if os.path.exists(OUTPUT):
339
        os.unlink(OUTPUT)
389
        os.unlink(OUTPUT)
340
    os.rename(TMPOUTPUT, OUTPUT)
390
    os.rename(TMPOUTPUT, OUTPUT)
341
       
391
       
342
 
392