Changeset 62bb73e in mainline
- Timestamp:
- 2010-12-03T22:05:46Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4756634
- Parents:
- e4d540b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/config.py
re4d540b r62bb73e 3 3 # Copyright (c) 2006 Ondrej Palkovsky 4 4 # Copyright (c) 2009 Martin Decky 5 # Copyright (c) 2010 Jiri Svoboda 5 6 # All rights reserved. 6 7 # … … 40 41 import xtui 41 42 42 INPUT= sys.argv[1]43 RULES_FILE = sys.argv[1] 43 44 MAKEFILE = 'Makefile.config' 44 45 MACROS = 'config.h' 45 PRE CONF= 'defaults'46 47 def read_ defaults(fname, defaults):46 PRESETS_DIR = 'defaults' 47 48 def read_config(fname, config): 48 49 "Read saved values from last configuration run" 49 50 … … 53 54 res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line) 54 55 if (res): 55 defaults[res.group(1)] = res.group(2)56 config[res.group(1)] = res.group(2) 56 57 57 58 inf.close() 58 59 59 def check_condition(text, defaults, ask_names):60 def check_condition(text, config, rules): 60 61 "Check that the condition specified on input line is True (only CNF and DNF is supported)" 61 62 … … 74 75 cond = cond[1:-1] 75 76 76 inside = check_inside(cond, defaults, ctype)77 inside = check_inside(cond, config, ctype) 77 78 78 79 if (ctype == 'cnf') and (not inside): … … 86 87 return False 87 88 88 def check_inside(text, defaults, ctype):89 def check_inside(text, config, ctype): 89 90 "Check for condition" 90 91 … … 103 104 condval = res.group(3) 104 105 105 if (not condname in defaults):106 if (not condname in config): 106 107 varval = '' 107 108 else: 108 varval = defaults[condname]109 varval = config[condname] 109 110 if (varval == '*'): 110 111 varval = 'y' … … 128 129 return True 129 130 130 def parse_ config(fname, ask_names):131 "Parse configurationfile"131 def parse_rules(fname, rules): 132 "Parse rules file" 132 133 133 134 inf = open(fname, 'r') … … 149 150 vartype = res.group(3) 150 151 151 ask_names.append((varname, vartype, name, choices, cond))152 rules.append((varname, vartype, name, choices, cond)) 152 153 name = '' 153 154 choices = [] … … 214 215 ## Infer and verify configuration values. 215 216 # 216 # Augment @a defaultswith values that can be inferred, purge invalid ones217 # Augment @a config with values that can be inferred, purge invalid ones 217 218 # and verify that all variables have a value (previously specified or inferred). 218 219 # 219 # @param defaultsConfiguration to work on220 # @param ask_names Rules221 # 222 # @return 223 # 224 # 225 def infer_verify_choices( defaults, ask_names):220 # @param config Configuration to work on 221 # @param rules Rules 222 # 223 # @return True if configuration is complete and valid, False 224 # otherwise. 225 # 226 def infer_verify_choices(config, rules): 226 227 "Infer and verify configuration values." 227 228 228 for varname, vartype, name, choices, cond in ask_names:229 if ((cond) and (not check_condition(cond, defaults, ask_names))):229 for varname, vartype, name, choices, cond in rules: 230 if ((cond) and (not check_condition(cond, config, rules))): 230 231 continue 231 232 232 if (not varname in defaults):233 if (not varname in config): 233 234 default = None 234 235 else: 235 default = defaults[varname]236 default = config[varname] 236 237 237 238 if not rule_value_is_valid((varname, vartype, name, choices, cond), default): … … 241 242 if rdef != None: 242 243 default = rdef 243 defaults[varname] = rdef244 245 if (not varname in defaults):244 config[varname] = rdef 245 246 if (not varname in config): 246 247 return False 247 248 … … 336 337 return True 337 338 338 def create_output(mkname, mcname, defaults, ask_names):339 def create_output(mkname, mcname, config, rules): 339 340 "Create output configuration" 340 341 … … 371 372 defs = 'CONFIG_DEFS =' 372 373 373 for varname, vartype, name, choices, cond in ask_names:374 if ((cond) and (not check_condition(cond, defaults, ask_names))):374 for varname, vartype, name, choices, cond in rules: 375 if ((cond) and (not check_condition(cond, config, rules))): 375 376 continue 376 377 377 if (not varname in defaults):378 if (not varname in config): 378 379 default = '' 379 380 else: 380 default = defaults[varname]381 default = config[varname] 381 382 if (default == '*'): 382 383 default = 'y' … … 411 412 return list 412 413 413 def read_preconfigured(root, fname, screen, defaults): 414 ## Choose a profile and load configuration presets. 415 # 416 def load_presets(root, fname, screen, config): 414 417 options = [] 415 418 opt2path = {} … … 445 448 return None 446 449 447 read_ defaults(opt2path[value][0], defaults)450 read_config(opt2path[value][0], config) 448 451 if (opt2path[value][1] != None): 449 read_ defaults(opt2path[value][1], defaults)452 read_config(opt2path[value][1], config) 450 453 451 454 def main(): 452 defaults= {}453 ask_names = []454 455 # Parse configurationfile456 parse_ config(INPUT, ask_names)457 458 # Read defaultsfrom previous run455 config = {} 456 rules = [] 457 458 # Parse rules file 459 parse_rules(RULES_FILE, rules) 460 461 # Read configuration from previous run 459 462 if os.path.exists(MAKEFILE): 460 read_ defaults(MAKEFILE, defaults)461 462 # Default mode: only check defaults and regenerate configuration463 read_config(MAKEFILE, config) 464 465 # Default mode: only check values and regenerate configuration files 463 466 if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')): 464 if (infer_verify_choices( defaults, ask_names)):465 create_output(MAKEFILE, MACROS, defaults, ask_names)467 if (infer_verify_choices(config, rules)): 468 create_output(MAKEFILE, MACROS, config, rules) 466 469 return 0 467 470 468 # Check mode: only check defaults471 # Check mode: only check configuration 469 472 if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')): 470 if (infer_verify_choices( defaults, ask_names)):473 if (infer_verify_choices(config, rules)): 471 474 return 0 472 475 return 1 … … 478 481 while True: 479 482 480 # Cancel out all defaults which have to be deduced481 for varname, vartype, name, choices, cond in ask_names:482 if ((vartype == 'y') and (varname in defaults) and (defaults[varname] == '*')):483 defaults[varname] = None483 # Cancel out all values which have to be deduced 484 for varname, vartype, name, choices, cond in rules: 485 if ((vartype == 'y') and (varname in config) and (config[varname] == '*')): 486 config[varname] = None 484 487 485 488 options = [] … … 489 492 options.append(" --- Load preconfigured defaults ... ") 490 493 491 for rule in ask_names:494 for rule in rules: 492 495 varname, vartype, name, choices, cond = rule 493 496 494 if ((cond) and (not check_condition(cond, defaults, ask_names))):497 if ((cond) and (not check_condition(cond, config, rules))): 495 498 continue 496 499 … … 498 501 position = cnt 499 502 500 if (not varname in defaults):503 if (not varname in config): 501 504 default = None 502 505 else: 503 default = defaults[varname]506 default = config[varname] 504 507 505 508 if not rule_value_is_valid(rule, default): … … 509 512 if rdef != None: 510 513 default = rdef 511 defaults[varname] = rdef514 config[varname] = rdef 512 515 513 516 option = rule_get_option(rule, default) … … 528 531 529 532 if (button == 'done'): 530 if (infer_verify_choices( defaults, ask_names)):533 if (infer_verify_choices(config, rules)): 531 534 break 532 535 else: … … 535 538 536 539 if (value == 0): 537 read_preconfigured(PRECONF, MAKEFILE, screen, defaults)540 load_presets(PRESETS_DIR, MAKEFILE, screen, config) 538 541 position = 1 539 542 continue … … 545 548 (selname, seltype, name, choices) = opt2row[value] 546 549 547 if (not selname in defaults):550 if (not selname in config): 548 551 default = None 549 552 else: 550 default = defaults[selname]553 default = config[selname] 551 554 552 555 if (seltype == 'choice'): 553 defaults[selname] = subchoice(screen, name, choices, default)556 config[selname] = subchoice(screen, name, choices, default) 554 557 elif ((seltype == 'y/n') or (seltype == 'n/y')): 555 if ( defaults[selname] == 'y'):556 defaults[selname] = 'n'558 if (config[selname] == 'y'): 559 config[selname] = 'n' 557 560 else: 558 defaults[selname] = 'y'561 config[selname] = 'y' 559 562 finally: 560 563 xtui.screen_done(screen) 561 564 562 create_output(MAKEFILE, MACROS, defaults, ask_names)565 create_output(MAKEFILE, MACROS, config, rules) 563 566 return 0 564 567
Note:
See TracChangeset
for help on using the changeset viewer.