Changeset d40ffbb in mainline
- Timestamp:
- 2010-12-06T12:29:04Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e3c3172
- Parents:
- 8fe3f832
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/config.py
r8fe3f832 rd40ffbb 47 47 48 48 def read_config(fname, config): 49 "Read saved values from last configuration run "49 "Read saved values from last configuration run or a preset file" 50 50 51 51 inf = open(fname, 'r') … … 218 218 # and verify that all variables have a value (previously specified or inferred). 219 219 # 220 # @param config 221 # @param rules 222 # 223 # @return 224 # 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 225 # 226 226 def infer_verify_choices(config, rules): … … 229 229 for rule in rules: 230 230 varname, vartype, name, choices, cond = rule 231 231 232 232 if cond and (not check_condition(cond, config, rules)): 233 233 continue … … 237 237 else: 238 238 value = config[varname] 239 240 if not rule_value_is_valid(rule, value):239 240 if not validate_rule_value(rule, value): 241 241 value = None 242 243 default = rule_get_default(rule)242 243 default = get_default_rule(rule) 244 244 if default != None: 245 245 config[varname] = default 246 246 247 247 if not varname in config: 248 248 return False … … 251 251 252 252 ## Get default value from a rule. 253 def rule_get_default(rule):253 def get_default_rule(rule): 254 254 varname, vartype, name, choices, cond = rule 255 255 256 256 default = None 257 257 258 258 if vartype == 'choice': 259 259 # If there is just one option, use it … … 270 270 else: 271 271 raise RuntimeError("Unknown variable type: %s" % vartype) 272 272 273 273 return default 274 274 275 275 ## Get option from a rule. 276 276 # 277 # @param rule 278 # @param value 277 # @param rule Rule for a variable 278 # @param value Current value of the variable 279 279 # 280 280 # @return Option (string) to ask or None which means not to ask. 281 281 # 282 def rule_get_option(rule, value):282 def get_rule_option(rule, value): 283 283 varname, vartype, name, choices, cond = rule 284 284 285 285 option = None 286 286 287 287 if vartype == 'choice': 288 288 # If there is just one option, don't ask … … 302 302 else: 303 303 raise RuntimeError("Unknown variable type: %s" % vartype) 304 304 305 305 return option 306 306 307 307 ## Check if variable value is valid. 308 308 # 309 # @param rule 310 # @param value 311 # 312 # @return 313 # 314 def rule_value_is_valid(rule, value):309 # @param rule Rule for the variable 310 # @param value Value of the variable 311 # 312 # @return True if valid, False if not valid. 313 # 314 def validate_rule_value(rule, value): 315 315 varname, vartype, name, choices, cond = rule 316 316 317 317 if value == None: 318 318 return True 319 319 320 320 if vartype == 'choice': 321 321 if not value in [choice[0] for choice in choices]: … … 335 335 else: 336 336 raise RuntimeError("Unknown variable type: %s" % vartype) 337 337 338 338 return True 339 339 … … 415 415 ## Ask user to choose a configuration profile. 416 416 # 417 def profile_choose(root, fname, screen, config):417 def choose_profile(root, fname, screen, config): 418 418 options = [] 419 419 opt2path = {} … … 453 453 ## Read presets from a configuration profile. 454 454 # 455 # @param profile 456 # @param config 457 # 458 def presets_read(profile, config):455 # @param profile Profile to load from (a list of string components) 456 # @param config Output configuration 457 # 458 def read_presets(profile, config): 459 459 path = os.path.join(PRESETS_DIR, profile[0], MAKEFILE) 460 460 read_config(path, config) 461 461 462 462 if len(profile) > 1: 463 463 path = os.path.join(PRESETS_DIR, profile[0], profile[1], MAKEFILE) … … 466 466 ## Parse profile name (relative OS path) into a list of components. 467 467 # 468 # @param profile_name 469 # @return 468 # @param profile_name Relative path (using OS separator) 469 # @return List of components 470 470 # 471 471 def parse_profile_name(profile_name): 472 472 profile = [] 473 473 474 474 head, tail = os.path.split(profile_name) 475 475 if head != '': 476 476 profile.append(head) 477 477 478 478 profile.append(tail) 479 479 return profile … … 491 491 if len(sys.argv) >= 4: 492 492 profile = parse_profile_name(sys.argv[3]) 493 presets_read(profile, config)493 read_presets(profile, config) 494 494 elif os.path.exists(MAKEFILE): 495 495 read_config(MAKEFILE, config) … … 538 538 value = config[varname] 539 539 540 if not rule_value_is_valid(rule, value):540 if not validate_rule_value(rule, value): 541 541 value = None 542 543 default = rule_get_default(rule)542 543 default = get_default_rule(rule) 544 544 if default != None: 545 545 if value == None: 546 546 value = default 547 547 config[varname] = value 548 549 option = rule_get_option(rule, value)548 549 option = get_rule_option(rule, value) 550 550 if option != None: 551 551 options.append(option) … … 573 573 574 574 if value == 0: 575 profile = profile_choose(PRESETS_DIR, MAKEFILE, screen, config)575 profile = choose_profile(PRESETS_DIR, MAKEFILE, screen, config) 576 576 if profile != None: 577 presets_read(profile, config)577 read_presets(profile, config) 578 578 position = 1 579 579 continue
Note:
See TracChangeset
for help on using the changeset viewer.