Changeset 31fb9a0 in mainline for tools


Ignore:
Timestamp:
2009-03-08T13:38:22Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0af8bcd
Parents:
ec944b1
Message:

add support for predefined configuration profiles (and subprofiles, configuration can be nested)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config.py

    rec944b1 r31fb9a0  
    4141MACROS = 'config.h'
    4242DEFS = 'config.defs'
     43PRECONF = 'defaults'
    4344
    4445def read_defaults(fname, defaults):
     
    277278        outdf.close()
    278279
     280def sorted_dir(root):
     281        list = os.listdir(root)
     282        list.sort()
     283        return list
     284
     285def read_preconfigured(root, fname, screen, defaults):
     286        options = []
     287        opt2path = {}
     288        cnt = 0
     289       
     290        # Look for profiles
     291        for name in sorted_dir(root):
     292                path = os.path.join(root, name)
     293                canon = os.path.join(path, fname)
     294               
     295                if ((os.path.isdir(path)) and (os.path.exists(canon)) and (os.path.isfile(canon))):
     296                        subprofile = False
     297                       
     298                        # Look for subprofiles
     299                        for subname in sorted_dir(path):
     300                                subpath = os.path.join(path, subname)
     301                                subcanon = os.path.join(subpath, fname)
     302                               
     303                                if ((os.path.isdir(subpath)) and (os.path.exists(subcanon)) and (os.path.isfile(subcanon))):
     304                                        subprofile = True
     305                                        options.append("%s (%s)" % (name, subname))
     306                                        opt2path[cnt] = (canon, subcanon)
     307                                        cnt += 1
     308                       
     309                        if (not subprofile):
     310                                options.append(name)
     311                                opt2path[cnt] = (canon, None)
     312                                cnt += 1
     313       
     314        (button, value) = xtui.choice_window(screen, 'Load preconfigured defaults', 'Choose configuration profile', options, None)
     315       
     316        if (button == 'cancel'):
     317                return None
     318       
     319        read_defaults(opt2path[value][0], defaults)
     320        if (opt2path[value][1] != None):
     321                read_defaults(opt2path[value][1], defaults)
     322
    279323def main():
    280324        defaults = {}
     
    303347        try:
    304348                selname = None
     349                position = None
    305350                while True:
    306351                       
     
    312357                        options = []
    313358                        opt2row = {}
    314                         position = None
    315                         cnt = 0
     359                        cnt = 1
     360                       
     361                        options.append("  --- Load preconfigured defaults ... ")
     362                       
    316363                        for varname, vartype, name, choices, cond in ask_names:
    317364                               
     
    362409                                cnt += 1
    363410                       
     411                        if (position >= options):
     412                                position = None
     413                       
    364414                        (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position)
    365415                       
     
    367417                                return 'Configuration canceled'
    368418                       
     419                        if (value == 0):
     420                                read_preconfigured(PRECONF, MAKEFILE, screen, defaults)
     421                                position = 1
     422                                continue
     423                       
     424                        position = None
    369425                        if (not opt2row.has_key(value)):
    370426                                raise RuntimeError("Error selecting value: %s" % value)
Note: See TracChangeset for help on using the changeset viewer.