Changeset 944b15c in mainline for tools/config.py


Ignore:
Timestamp:
2005-12-08T16:15:20Z (20 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b00fdde
Parents:
ac0cb2a
Message:

Configuration tweaks, now supports both CNF and DNF in config.file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config.py

    rac0cb2a r944b15c  
    231231    f.close()
    232232
    233 def check_condition(text, defaults):
    234     result = True
    235     conds = text.split('&')
     233def check_condition(text, defaults, asked_names):
     234    seen_vars = [ x[0] for x in asked_names ]
     235    ctype = 'cnf'
     236    if ')|' in text or '|(' in text:
     237        ctype = 'dnf'
     238   
     239    if ctype == 'cnf':
     240        conds = text.split('&')
     241    else:
     242        conds = text.split('|')
     243
    236244    for cond in conds:
    237245        if cond.startswith('(') and cond.endswith(')'):
    238246            cond = cond[1:-1]
    239         if not check_dnf(cond, defaults):
     247           
     248        inside = check_inside(cond, defaults, ctype, seen_vars)
     249       
     250        if ctype == 'cnf' and not inside:
    240251            return False
    241     return True
    242 
    243 def check_dnf(text, defaults):
     252        if ctype == 'dnf' and inside:
     253            return True
     254
     255    if ctype == 'cnf':
     256        return True
     257    return False
     258
     259def check_inside(text, defaults, ctype, seen_vars):
    244260    """
    245261    Check that the condition specified on input line is True
     
    247263    only CNF is supported
    248264    """
    249     conds = text.split('|')
     265    if ctype == 'cnf':
     266        conds = text.split('|')
     267    else:
     268        conds = text.split('&')
    250269    for cond in conds:
    251270        res = re.match(r'^(.*?)(!?=)(.*)$', cond)
     
    255274        oper = res.group(2)
    256275        condval = res.group(3)
     276        if condname not in seen_vars:
     277            raise RuntimeError("Variable %s not defined before being asked." %\
     278                               condname)
    257279        if not defaults.has_key(condname):
    258280            raise RuntimeError("Condition var %s does not exist: %s" % \
    259281                               (condname,text))
    260282
    261         if oper=='=' and  condval == defaults[condname]:
    262             return True
    263         if oper == '!=' and condval != defaults[condname]:
    264             return True
    265     return False
     283        if ctype == 'cnf':
     284            if oper == '=' and  condval == defaults[condname]:
     285                return True
     286            if oper == '!=' and condval != defaults[condname]:
     287                return True
     288        else:
     289            if oper== '=' and condval != defaults[condname]:
     290                return False
     291            if oper== '!=' and condval == defaults[condname]:
     292                print 2
     293                return False
     294    if ctype=='cnf':
     295        return False
     296    return True
    266297
    267298def parse_config(input, output, dlg, defaults={}, askonly=None):
     
    305336                raise RuntimeError('Invalid command: %s' % line)
    306337            if res.group(1):
    307                 if not check_condition(res.group(1), defaults):
     338                if not check_condition(res.group(1), defaults,
     339                                       asked_names):
    308340                    continue
    309341            args = res.group(2).strip().split(' ')
     
    335367           
    336368            if res.group(1):
    337                 if not check_condition(res.group(1), defaults):
     369                if not check_condition(res.group(1), defaults,
     370                                       asked_names):
    338371                    if default is not None:
    339372                        outf.write('#!# %s = %s\n' % (varname, default))
     
    366399                raise RuntimeError("Bad line: %s" % line)
    367400            if res.group(1):
    368                 if not check_condition(res.group(1),defaults):
     401                if not check_condition(res.group(1),defaults,
     402                                       asked_names):
    369403                    continue
    370404            choices.append((res.group(2), res.group(3)))
     
    434468   
    435469    if not defmode and dlg.yesno('Rebuild kernel?') == 'y':
    436         os.execlp('make','make','clean','all')
     470        os.execlp('make','make','clean','build')
    437471
    438472if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.