Changeset ba8de9c3 in mainline


Ignore:
Timestamp:
2010-12-03T22:21:16Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
421250e, 8c2b3ef
Parents:
4756634
Message:

Remove L.I.S.P. from configuration script.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config.py

    r4756634 rba8de9c3  
    5353        for line in inf:
    5454                res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
    55                 if (res):
     55                if res:
    5656                        config[res.group(1)] = res.group(2)
    5757       
     
    6363        ctype = 'cnf'
    6464       
    65         if ((')|' in text) or ('|(' in text)):
     65        if (')|' in text) or ('|(' in text):
    6666                ctype = 'dnf'
    6767       
    68         if (ctype == 'cnf'):
     68        if ctype == 'cnf':
    6969                conds = text.split('&')
    7070        else:
     
    7272       
    7373        for cond in conds:
    74                 if (cond.startswith('(')) and (cond.endswith(')')):
     74                if cond.startswith('(') and cond.endswith(')'):
    7575                        cond = cond[1:-1]
    7676               
     
    8080                        return False
    8181               
    82                 if (ctype == 'dnf') and (inside):
     82                if (ctype == 'dnf') and inside:
    8383                        return True
    8484       
    85         if (ctype == 'cnf'):
     85        if ctype == 'cnf':
    8686                return True
    8787        return False
     
    9090        "Check for condition"
    9191       
    92         if (ctype == 'cnf'):
     92        if ctype == 'cnf':
    9393                conds = text.split('|')
    9494        else:
     
    9797        for cond in conds:
    9898                res = re.match(r'^(.*?)(!?=)(.*)$', cond)
    99                 if (not res):
     99                if not res:
    100100                        raise RuntimeError("Invalid condition: %s" % cond)
    101101               
     
    104104                condval = res.group(3)
    105105               
    106                 if (not condname in config):
     106                if not condname in config:
    107107                        varval = ''
    108108                else:
     
    111111                                varval = 'y'
    112112               
    113                 if (ctype == 'cnf'):
     113                if ctype == 'cnf':
    114114                        if (oper == '=') and (condval == varval):
    115115                                return True
     
    124124                                return False
    125125       
    126         if (ctype == 'cnf'):
     126        if ctype == 'cnf':
    127127                return False
    128128       
     
    139139        for line in inf:
    140140               
    141                 if (line.startswith('!')):
     141                if line.startswith('!'):
    142142                        # Ask a question
    143143                        res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line)
    144144                       
    145                         if (not res):
     145                        if not res:
    146146                                raise RuntimeError("Weird line: %s" % line)
    147147                       
     
    155155                        continue
    156156               
    157                 if (line.startswith('@')):
     157                if line.startswith('@'):
    158158                        # Add new line into the 'choices' array
    159159                        res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
     
    165165                        continue
    166166               
    167                 if (line.startswith('%')):
     167                if line.startswith('%'):
    168168                        # Name of the option
    169169                        name = line[1:].strip()
    170170                        continue
    171171               
    172                 if ((line.startswith('#')) or (line == '\n')):
     172                if line.startswith('#') or (line == '\n'):
    173173                        # Comment or empty line
    174174                        continue
     
    182182        "Return '*' if yes, ' ' if no"
    183183       
    184         if (default == 'y'):
     184        if default == 'y':
    185185                return '*'
    186186       
     
    200200        cnt = 0
    201201        for key, val in choices:
    202                 if ((default) and (key == default)):
     202                if (default) and (key == default):
    203203                        position = cnt
    204204               
     
    208208        (button, value) = xtui.choice_window(screen, name, 'Choose value', options, position)
    209209       
    210         if (button == 'cancel'):
     210        if button == 'cancel':
    211211                return None
    212212       
     
    227227        "Infer and verify configuration values."
    228228       
    229         for varname, vartype, name, choices, cond in rules:
    230                 if ((cond) and (not check_condition(cond, config, rules))):
     229        for rule in rules:
     230                varname, vartype, name, choices, cond = rule
     231
     232                if cond and (not check_condition(cond, config, rules)):
    231233                        continue
    232234               
    233                 if (not varname in config):
     235                if not varname in config:
    234236                        value = None
    235237                else:
    236238                        value = config[varname]
    237239
    238                 if not rule_value_is_valid((varname, vartype, name, choices, cond), value):
     240                if not rule_value_is_valid(rule, value):
    239241                        value = None
    240242
    241                 default = rule_get_default((varname, vartype, name, choices, cond))
     243                default = rule_get_default(rule)
    242244                if default != None:
    243245                        config[varname] = default
    244246
    245                 if (not varname in config):
     247                if not varname in config:
    246248                        return False
    247249       
     
    254256        default = None
    255257
    256         if (vartype == 'choice'):
     258        if vartype == 'choice':
    257259                # If there is just one option, use it
    258                 if (len(choices) == 1):
     260                if len(choices) == 1:
    259261                        default = choices[0][0]
    260         elif (vartype == 'y'):
     262        elif vartype == 'y':
    261263                default = '*'
    262         elif (vartype == 'n'):
     264        elif vartype == 'n':
    263265                default = 'n'
    264         elif (vartype == 'y/n'):
     266        elif vartype == 'y/n':
    265267                default = 'y'
    266         elif (vartype == 'n/y'):
     268        elif vartype == 'n/y':
    267269                default = 'n'
    268270        else:
     
    283285        option = None
    284286
    285         if (vartype == 'choice'):
     287        if vartype == 'choice':
    286288                # If there is just one option, don't ask
    287                 if (len(choices) != 1):
     289                if len(choices) != 1:
    288290                        if (value == None):
    289291                                option = "?     %s --> " % name
    290292                        else:
    291293                                option = "      %s [%s] --> " % (name, value)
    292         elif (vartype == 'y'):
     294        elif vartype == 'y':
    293295                pass
    294         elif (vartype == 'n'):
     296        elif vartype == 'n':
    295297                pass
    296         elif (vartype == 'y/n'):
     298        elif vartype == 'y/n':
    297299                option = "  <%s> %s " % (yes_no(value), name)
    298         elif (vartype == 'n/y'):
     300        elif vartype == 'n/y':
    299301                option ="  <%s> %s " % (yes_no(value), name)
    300302        else:
     
    316318                return True
    317319
    318         if (vartype == 'choice'):
    319                 if (not value in [choice[0] for choice in choices]):
    320                         return False
    321         elif (vartype == 'y'):
     320        if vartype == 'choice':
     321                if not value in [choice[0] for choice in choices]:
     322                        return False
     323        elif vartype == 'y':
    322324                if value != 'y':
    323325                        return False
    324         elif (vartype == 'n'):
     326        elif vartype == 'n':
    325327                if value != 'n':
    326328                        return False
    327         elif (vartype == 'y/n'):
     329        elif vartype == 'y/n':
    328330                if not value in ['y', 'n']:
    329331                        return False
    330         elif (vartype == 'n/y'):
     332        elif vartype == 'n/y':
    331333                if not value in ['y', 'n']:
    332334                        return False
     
    350352                sys.stderr.write("failed\n")
    351353       
    352         if (len(version) == 3):
     354        if len(version) == 3:
    353355                revision = version[1]
    354                 if (version[0] != 1):
     356                if version[0] != 1:
    355357                        revision += 'M'
    356358                revision += ' (%s)' % version[2]
     
    372374       
    373375        for varname, vartype, name, choices, cond in rules:
    374                 if ((cond) and (not check_condition(cond, config, rules))):
     376                if cond and (not check_condition(cond, config, rules)):
    375377                        continue
    376378               
    377                 if (not varname in config):
     379                if not varname in config:
    378380                        value = ''
    379381                else:
     
    384386                outmk.write('# %s\n%s = %s\n\n' % (name, varname, value))
    385387               
    386                 if ((vartype == "y") or (vartype == "n") or (vartype == "y/n") or (vartype == "n/y")):
    387                         if (value == "y"):
     388                if vartype in ["y", "n", "y/n", "n/y"]:
     389                        if value == "y":
    388390                                outmc.write('/* %s */\n#define %s\n\n' % (name, varname))
    389391                                defs += ' -D%s' % varname
     
    392394                        defs += ' -D%s=%s -D%s_%s' % (varname, value, varname, value)
    393395       
    394         if (revision is not None):
     396        if revision is not None:
    395397                outmk.write('REVISION = %s\n' % revision)
    396398                outmc.write('#define REVISION %s\n' % revision)
     
    423425                canon = os.path.join(path, fname)
    424426               
    425                 if ((os.path.isdir(path)) and (os.path.exists(canon)) and (os.path.isfile(canon))):
     427                if os.path.isdir(path) and os.path.exists(canon) and os.path.isfile(canon):
    426428                        subprofile = False
    427429                       
     
    431433                                subcanon = os.path.join(subpath, fname)
    432434                               
    433                                 if ((os.path.isdir(subpath)) and (os.path.exists(subcanon)) and (os.path.isfile(subcanon))):
     435                                if os.path.isdir(subpath) and os.path.exists(subcanon) and os.path.isfile(subcanon):
    434436                                        subprofile = True
    435437                                        options.append("%s (%s)" % (name, subname))
     
    437439                                        cnt += 1
    438440                       
    439                         if (not subprofile):
     441                        if not subprofile:
    440442                                options.append(name)
    441443                                opt2path[cnt] = (canon, None)
     
    444446        (button, value) = xtui.choice_window(screen, 'Load preconfigured defaults', 'Choose configuration profile', options, None)
    445447       
    446         if (button == 'cancel'):
     448        if button == 'cancel':
    447449                return None
    448450       
    449451        read_config(opt2path[value][0], config)
    450         if (opt2path[value][1] != None):
     452        if opt2path[value][1] != None:
    451453                read_config(opt2path[value][1], config)
    452454
     
    463465       
    464466        # Default mode: only check values and regenerate configuration files
    465         if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
     467        if (len(sys.argv) >= 3) and (sys.argv[2] == 'default'):
    466468                if (infer_verify_choices(config, rules)):
    467469                        create_output(MAKEFILE, MACROS, config, rules)
     
    469471       
    470472        # Check mode: only check configuration
    471         if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')):
    472                 if (infer_verify_choices(config, rules)):
     473        if (len(sys.argv) >= 3) and (sys.argv[2] == 'check'):
     474                if infer_verify_choices(config, rules):
    473475                        return 0
    474476                return 1
     
    482484                        # Cancel out all values which have to be deduced
    483485                        for varname, vartype, name, choices, cond in rules:
    484                                 if ((vartype == 'y') and (varname in config) and (config[varname] == '*')):
     486                                if (vartype == 'y') and (varname in config) and (config[varname] == '*'):
    485487                                        config[varname] = None
    486488                       
     
    494496                                varname, vartype, name, choices, cond = rule
    495497                               
    496                                 if ((cond) and (not check_condition(cond, config, rules))):
     498                                if cond and (not check_condition(cond, config, rules)):
    497499                                        continue
    498500                               
    499                                 if (varname == selname):
     501                                if varname == selname:
    500502                                        position = cnt
    501503                               
    502                                 if (not varname in config):
     504                                if not varname in config:
    503505                                        value = None
    504506                                else:
     
    526528                        (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position)
    527529                       
    528                         if (button == 'cancel'):
     530                        if button == 'cancel':
    529531                                return 'Configuration canceled'
    530532                       
    531                         if (button == 'done'):
     533                        if button == 'done':
    532534                                if (infer_verify_choices(config, rules)):
    533535                                        break
     
    536538                                        continue
    537539                       
    538                         if (value == 0):
     540                        if value == 0:
    539541                                load_presets(PRESETS_DIR, MAKEFILE, screen, config)
    540542                                position = 1
     
    542544                       
    543545                        position = None
    544                         if (not value in opt2row):
     546                        if not value in opt2row:
    545547                                raise RuntimeError("Error selecting value: %s" % value)
    546548                       
    547549                        (selname, seltype, name, choices) = opt2row[value]
    548550                       
    549                         if (not selname in config):
     551                        if not selname in config:
    550552                                value = None
    551553                        else:
    552554                                value = config[selname]
    553555                       
    554                         if (seltype == 'choice'):
     556                        if seltype == 'choice':
    555557                                config[selname] = subchoice(screen, name, choices, value)
    556                         elif ((seltype == 'y/n') or (seltype == 'n/y')):
    557                                 if (config[selname] == 'y'):
     558                        elif (seltype == 'y/n') or (seltype == 'n/y'):
     559                                if config[selname] == 'y':
    558560                                        config[selname] = 'n'
    559561                                else:
Note: See TracChangeset for help on using the changeset viewer.