~martin-decky/helenos/rcu

« back to all changes in this revision

Viewing changes to tools/config.py

  • Committer: Jiri Svoboda
  • Date: 2010-12-05 12:59:48 UTC
  • mfrom: (735.1.6 config)
  • Revision ID: jiri@wiwaxia-20101205125948-rr9jk6prqtm0atve
Merge two-level profile fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
412
412
        list.sort()
413
413
        return list
414
414
 
415
 
## Choose a profile and load configuration presets.
 
415
## Ask user to choose a configuration profile.
416
416
#
417
 
def load_presets(root, fname, screen, config):
 
417
def profile_choose(root, fname, screen, config):
418
418
        options = []
419
419
        opt2path = {}
420
420
        cnt = 0
435
435
                                if os.path.isdir(subpath) and os.path.exists(subcanon) and os.path.isfile(subcanon):
436
436
                                        subprofile = True
437
437
                                        options.append("%s (%s)" % (name, subname))
438
 
                                        opt2path[cnt] = (canon, subcanon)
 
438
                                        opt2path[cnt] = [name, subname]
439
439
                                        cnt += 1
440
440
                        
441
441
                        if not subprofile:
442
442
                                options.append(name)
443
 
                                opt2path[cnt] = (canon, None)
 
443
                                opt2path[cnt] = [name]
444
444
                                cnt += 1
445
445
        
446
446
        (button, value) = xtui.choice_window(screen, 'Load preconfigured defaults', 'Choose configuration profile', options, None)
448
448
        if button == 'cancel':
449
449
                return None
450
450
        
451
 
        read_config(opt2path[value][0], config)
452
 
        if opt2path[value][1] != None:
453
 
                read_config(opt2path[value][1], config)
 
451
        return opt2path[value]
 
452
 
 
453
## Read presets from a configuration profile.
 
454
#
 
455
# @param profile        Profile to load from (a list of string components)
 
456
# @param config         Output configuration
 
457
#
 
458
def presets_read(profile, config):
 
459
        path = os.path.join(PRESETS_DIR, profile[0], MAKEFILE)
 
460
        read_config(path, config)
 
461
 
 
462
        if len(profile) > 1:
 
463
                path = os.path.join(PRESETS_DIR, profile[0], profile[1], MAKEFILE)
 
464
                read_config(path, config)
 
465
 
 
466
## Parse profile name (relative OS path) into a list of components.
 
467
#
 
468
# @param profile_name   Relative path (using OS separator)
 
469
# @return               List of components
 
470
#
 
471
def parse_profile_name(profile_name):
 
472
        profile = []
 
473
 
 
474
        head, tail = os.path.split(profile_name)
 
475
        if head != '':
 
476
                profile.append(head)
 
477
 
 
478
        profile.append(tail)
 
479
        return profile
454
480
 
455
481
def main():
456
 
        cfgfile_in = None
 
482
        profile = None
457
483
        config = {}
458
484
        rules = []
459
485
        
463
489
        # Input configuration file can be specified on command line
464
490
        # otherwise configuration from previous run is used.
465
491
        if len(sys.argv) >= 4:
466
 
                cfgfile_in = sys.argv[3]
467
 
        else:
468
 
                cfgfile_in = MAKEFILE
469
 
        
470
 
        # Read configuration file
471
 
        if os.path.exists(cfgfile_in):
472
 
                read_config(cfgfile_in, config)
 
492
                profile = parse_profile_name(sys.argv[3])
 
493
                presets_read(profile, config)
 
494
        elif os.path.exists(MAKEFILE):
 
495
                read_config(MAKEFILE, config)
473
496
        
474
497
        # Default mode: only check values and regenerate configuration files
475
498
        if (len(sys.argv) >= 3) and (sys.argv[2] == 'default'):
546
569
                                        continue
547
570
                        
548
571
                        if value == 0:
549
 
                                load_presets(PRESETS_DIR, MAKEFILE, screen, config)
 
572
                                profile = profile_choose(PRESETS_DIR, MAKEFILE, screen, config)
 
573
                                if profile != None:
 
574
                                        presets_read(profile, config)
550
575
                                position = 1
551
576
                                continue
552
577