Changeset 9371c30 in mainline for tools/config.py


Ignore:
Timestamp:
2005-12-06T20:53:03Z (20 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
36e7b6c3
Parents:
090e7ea1
Message:

Completely reworked configuration system.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config.py

    r090e7ea1 r9371c30  
    187187
    188188def check_condition(text, defaults):
    189     "Check that the condition specified on input line is True"
    190     result = False
     189    result = True
     190    conds = text.split('&')
     191    for cond in conds:
     192        if cond.startswith('(') and cond.endswith(')'):
     193            cond = cond[1:-1]
     194        if not check_dnf(cond, defaults):
     195            return False
     196    return True
     197
     198def check_dnf(text, defaults):
     199    """
     200    Check that the condition specified on input line is True
     201
     202    only CNF is supported
     203    """
    191204    conds = text.split('|')
    192205    for cond in conds:
    193         condname,condval = cond.split('=')
     206        res = re.match(r'^(.*?)(!?=)(.*)$', cond)
     207        if not res:
     208            raise RuntimeError("Invalid condition: %s" % cond)
     209        condname = res.group(1)
     210        oper = res.group(2)
     211        condval = res.group(3)
    194212        if not defaults.has_key(condname):
    195213            raise RuntimeError("Condition var %s does not exist: %s" % \
    196                                (condname,line))
    197         # None means wildcard
    198         if defaults[condname] is None:
     214                               (condname,text))
     215
     216        if oper=='=' and  condval == defaults[condname]:
    199217            return True
    200         if  condval == defaults[condname]:
     218        if oper == '!=' and condval != defaults[condname]:
    201219            return True
    202220    return False
     
    214232    default = None
    215233    choices = []
    216     for line in f:       
     234    for line in f:
     235        if line.startswith('%'):
     236            res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line)
     237            if not res:
     238                raise RuntimeError('Invalid command: %s' % line)
     239            if res.group(1):
     240                if not check_condition(res.group(1), defaults):
     241                    continue
     242            args = res.group(2).strip().split(' ')
     243            cmd = args[0].lower()
     244            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':
     252                outf.write('%s = %s\n' % (args[1],defaults[args[0]]))
     253               
     254            continue
     255           
    217256        if line.startswith('!'):
    218257            # Ask a question
     
    229268                    if default is not None:
    230269                        outf.write('#!# %s = %s\n' % (varname, default))
     270                    # Clear cumulated values
     271                    comment = ''
     272                    default = None
     273                    choices = []
    231274                    continue
    232275
     
    278321
    279322def main():
    280     defaults = {'ARCH':None}
     323    defaults = {}
    281324    try:
    282325        dlg = Dialog()
     
    286329    # Default run will update the configuration file
    287330    # with newest options
    288     if len(sys.argv) >= 2:
    289         defaults['ARCH'] = sys.argv[1]
    290     if len(sys.argv) == 3 and sys.argv[2]=='default':
     331    if len(sys.argv) == 2 and sys.argv[1]=='default':
    291332        dlg = DefaultDialog(dlg)
    292333
Note: See TracChangeset for help on using the changeset viewer.