186,36 → 186,18 |
f.close() |
|
def check_condition(text, defaults): |
result = True |
conds = text.split('&') |
for cond in conds: |
if cond.startswith('(') and cond.endswith(')'): |
cond = cond[1:-1] |
if not check_dnf(cond, defaults): |
return False |
return True |
|
def check_dnf(text, defaults): |
""" |
Check that the condition specified on input line is True |
|
only CNF is supported |
""" |
"Check that the condition specified on input line is True" |
result = False |
conds = text.split('|') |
for cond in conds: |
res = re.match(r'^(.*?)(!?=)(.*)$', cond) |
if not res: |
raise RuntimeError("Invalid condition: %s" % cond) |
condname = res.group(1) |
oper = res.group(2) |
condval = res.group(3) |
condname,condval = cond.split('=') |
if not defaults.has_key(condname): |
raise RuntimeError("Condition var %s does not exist: %s" % \ |
(condname,text)) |
|
if oper=='=' and condval == defaults[condname]: |
(condname,line)) |
# None means wildcard |
if defaults[condname] is None: |
return True |
if oper == '!=' and condval != defaults[condname]: |
if condval == defaults[condname]: |
return True |
return False |
|
231,28 → 213,7 |
comment = '' |
default = None |
choices = [] |
for line in f: |
if line.startswith('%'): |
res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line) |
if not res: |
raise RuntimeError('Invalid command: %s' % line) |
if res.group(1): |
if not check_condition(res.group(1), defaults): |
continue |
args = res.group(2).strip().split(' ') |
cmd = args[0].lower() |
args = args[1:] |
if cmd == 'askdefault': |
if isinstance(dlg, DefaultDialog): |
continue |
res = dlg.noyes('Change kernel configuration') |
if res == 'n': |
dlg = DefaultDialog(dlg) |
elif cmd == 'saveas': |
outf.write('%s = %s\n' % (args[1],defaults[args[0]])) |
|
continue |
|
for line in f: |
if line.startswith('!'): |
# Ask a question |
res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
267,10 → 228,6 |
if not check_condition(res.group(1), defaults): |
if default is not None: |
outf.write('#!# %s = %s\n' % (varname, default)) |
# Clear cumulated values |
comment = '' |
default = None |
choices = [] |
continue |
|
if vartype == 'y/n': |
320,7 → 277,7 |
f.close() |
|
def main(): |
defaults = {} |
defaults = {'ARCH':None} |
try: |
dlg = Dialog() |
except NotImplementedError: |
328,7 → 285,9 |
|
# Default run will update the configuration file |
# with newest options |
if len(sys.argv) == 2 and sys.argv[1]=='default': |
if len(sys.argv) >= 2: |
defaults['ARCH'] = sys.argv[1] |
if len(sys.argv) == 3 and sys.argv[2]=='default': |
dlg = DefaultDialog(dlg) |
|
if os.path.exists(OUTPUT): |