Changeset ba8de9c3 in mainline
- Timestamp:
- 2010-12-03T22:21:16Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 421250e, 8c2b3ef
- Parents:
- 4756634
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/config.py
r4756634 rba8de9c3 53 53 for line in inf: 54 54 res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line) 55 if (res):55 if res: 56 56 config[res.group(1)] = res.group(2) 57 57 … … 63 63 ctype = 'cnf' 64 64 65 if ( (')|' in text) or ('|(' in text)):65 if (')|' in text) or ('|(' in text): 66 66 ctype = 'dnf' 67 67 68 if (ctype == 'cnf'):68 if ctype == 'cnf': 69 69 conds = text.split('&') 70 70 else: … … 72 72 73 73 for cond in conds: 74 if (cond.startswith('(')) and (cond.endswith(')')):74 if cond.startswith('(') and cond.endswith(')'): 75 75 cond = cond[1:-1] 76 76 … … 80 80 return False 81 81 82 if (ctype == 'dnf') and (inside):82 if (ctype == 'dnf') and inside: 83 83 return True 84 84 85 if (ctype == 'cnf'):85 if ctype == 'cnf': 86 86 return True 87 87 return False … … 90 90 "Check for condition" 91 91 92 if (ctype == 'cnf'):92 if ctype == 'cnf': 93 93 conds = text.split('|') 94 94 else: … … 97 97 for cond in conds: 98 98 res = re.match(r'^(.*?)(!?=)(.*)$', cond) 99 if (not res):99 if not res: 100 100 raise RuntimeError("Invalid condition: %s" % cond) 101 101 … … 104 104 condval = res.group(3) 105 105 106 if (not condname in config):106 if not condname in config: 107 107 varval = '' 108 108 else: … … 111 111 varval = 'y' 112 112 113 if (ctype == 'cnf'):113 if ctype == 'cnf': 114 114 if (oper == '=') and (condval == varval): 115 115 return True … … 124 124 return False 125 125 126 if (ctype == 'cnf'):126 if ctype == 'cnf': 127 127 return False 128 128 … … 139 139 for line in inf: 140 140 141 if (line.startswith('!')):141 if line.startswith('!'): 142 142 # Ask a question 143 143 res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) 144 144 145 if (not res):145 if not res: 146 146 raise RuntimeError("Weird line: %s" % line) 147 147 … … 155 155 continue 156 156 157 if (line.startswith('@')):157 if line.startswith('@'): 158 158 # Add new line into the 'choices' array 159 159 res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line) … … 165 165 continue 166 166 167 if (line.startswith('%')):167 if line.startswith('%'): 168 168 # Name of the option 169 169 name = line[1:].strip() 170 170 continue 171 171 172 if ((line.startswith('#')) or (line == '\n')):172 if line.startswith('#') or (line == '\n'): 173 173 # Comment or empty line 174 174 continue … … 182 182 "Return '*' if yes, ' ' if no" 183 183 184 if (default == 'y'):184 if default == 'y': 185 185 return '*' 186 186 … … 200 200 cnt = 0 201 201 for key, val in choices: 202 if ( (default) and (key == default)):202 if (default) and (key == default): 203 203 position = cnt 204 204 … … 208 208 (button, value) = xtui.choice_window(screen, name, 'Choose value', options, position) 209 209 210 if (button == 'cancel'):210 if button == 'cancel': 211 211 return None 212 212 … … 227 227 "Infer and verify configuration values." 228 228 229 for varname, vartype, name, choices, cond in rules: 230 if ((cond) and (not check_condition(cond, config, rules))): 229 for rule in rules: 230 varname, vartype, name, choices, cond = rule 231 232 if cond and (not check_condition(cond, config, rules)): 231 233 continue 232 234 233 if (not varname in config):235 if not varname in config: 234 236 value = None 235 237 else: 236 238 value = config[varname] 237 239 238 if not rule_value_is_valid( (varname, vartype, name, choices, cond), value):240 if not rule_value_is_valid(rule, value): 239 241 value = None 240 242 241 default = rule_get_default( (varname, vartype, name, choices, cond))243 default = rule_get_default(rule) 242 244 if default != None: 243 245 config[varname] = default 244 246 245 if (not varname in config):247 if not varname in config: 246 248 return False 247 249 … … 254 256 default = None 255 257 256 if (vartype == 'choice'):258 if vartype == 'choice': 257 259 # If there is just one option, use it 258 if (len(choices) == 1):260 if len(choices) == 1: 259 261 default = choices[0][0] 260 elif (vartype == 'y'):262 elif vartype == 'y': 261 263 default = '*' 262 elif (vartype == 'n'):264 elif vartype == 'n': 263 265 default = 'n' 264 elif (vartype == 'y/n'):266 elif vartype == 'y/n': 265 267 default = 'y' 266 elif (vartype == 'n/y'):268 elif vartype == 'n/y': 267 269 default = 'n' 268 270 else: … … 283 285 option = None 284 286 285 if (vartype == 'choice'):287 if vartype == 'choice': 286 288 # If there is just one option, don't ask 287 if (len(choices) != 1):289 if len(choices) != 1: 288 290 if (value == None): 289 291 option = "? %s --> " % name 290 292 else: 291 293 option = " %s [%s] --> " % (name, value) 292 elif (vartype == 'y'):294 elif vartype == 'y': 293 295 pass 294 elif (vartype == 'n'):296 elif vartype == 'n': 295 297 pass 296 elif (vartype == 'y/n'):298 elif vartype == 'y/n': 297 299 option = " <%s> %s " % (yes_no(value), name) 298 elif (vartype == 'n/y'):300 elif vartype == 'n/y': 299 301 option =" <%s> %s " % (yes_no(value), name) 300 302 else: … … 316 318 return True 317 319 318 if (vartype == 'choice'):319 if (not value in [choice[0] for choice in choices]):320 return False 321 elif (vartype == 'y'):320 if vartype == 'choice': 321 if not value in [choice[0] for choice in choices]: 322 return False 323 elif vartype == 'y': 322 324 if value != 'y': 323 325 return False 324 elif (vartype == 'n'):326 elif vartype == 'n': 325 327 if value != 'n': 326 328 return False 327 elif (vartype == 'y/n'):329 elif vartype == 'y/n': 328 330 if not value in ['y', 'n']: 329 331 return False 330 elif (vartype == 'n/y'):332 elif vartype == 'n/y': 331 333 if not value in ['y', 'n']: 332 334 return False … … 350 352 sys.stderr.write("failed\n") 351 353 352 if (len(version) == 3):354 if len(version) == 3: 353 355 revision = version[1] 354 if (version[0] != 1):356 if version[0] != 1: 355 357 revision += 'M' 356 358 revision += ' (%s)' % version[2] … … 372 374 373 375 for varname, vartype, name, choices, cond in rules: 374 if ((cond) and (not check_condition(cond, config, rules))):376 if cond and (not check_condition(cond, config, rules)): 375 377 continue 376 378 377 if (not varname in config):379 if not varname in config: 378 380 value = '' 379 381 else: … … 384 386 outmk.write('# %s\n%s = %s\n\n' % (name, varname, value)) 385 387 386 if ((vartype == "y") or (vartype == "n") or (vartype == "y/n") or (vartype == "n/y")):387 if (value == "y"):388 if vartype in ["y", "n", "y/n", "n/y"]: 389 if value == "y": 388 390 outmc.write('/* %s */\n#define %s\n\n' % (name, varname)) 389 391 defs += ' -D%s' % varname … … 392 394 defs += ' -D%s=%s -D%s_%s' % (varname, value, varname, value) 393 395 394 if (revision is not None):396 if revision is not None: 395 397 outmk.write('REVISION = %s\n' % revision) 396 398 outmc.write('#define REVISION %s\n' % revision) … … 423 425 canon = os.path.join(path, fname) 424 426 425 if ((os.path.isdir(path)) and (os.path.exists(canon)) and (os.path.isfile(canon))):427 if os.path.isdir(path) and os.path.exists(canon) and os.path.isfile(canon): 426 428 subprofile = False 427 429 … … 431 433 subcanon = os.path.join(subpath, fname) 432 434 433 if ((os.path.isdir(subpath)) and (os.path.exists(subcanon)) and (os.path.isfile(subcanon))):435 if os.path.isdir(subpath) and os.path.exists(subcanon) and os.path.isfile(subcanon): 434 436 subprofile = True 435 437 options.append("%s (%s)" % (name, subname)) … … 437 439 cnt += 1 438 440 439 if (not subprofile):441 if not subprofile: 440 442 options.append(name) 441 443 opt2path[cnt] = (canon, None) … … 444 446 (button, value) = xtui.choice_window(screen, 'Load preconfigured defaults', 'Choose configuration profile', options, None) 445 447 446 if (button == 'cancel'):448 if button == 'cancel': 447 449 return None 448 450 449 451 read_config(opt2path[value][0], config) 450 if (opt2path[value][1] != None):452 if opt2path[value][1] != None: 451 453 read_config(opt2path[value][1], config) 452 454 … … 463 465 464 466 # Default mode: only check values and regenerate configuration files 465 if ( (len(sys.argv) >= 3) and (sys.argv[2] == 'default')):467 if (len(sys.argv) >= 3) and (sys.argv[2] == 'default'): 466 468 if (infer_verify_choices(config, rules)): 467 469 create_output(MAKEFILE, MACROS, config, rules) … … 469 471 470 472 # Check mode: only check configuration 471 if ( (len(sys.argv) >= 3) and (sys.argv[2] == 'check')):472 if (infer_verify_choices(config, rules)):473 if (len(sys.argv) >= 3) and (sys.argv[2] == 'check'): 474 if infer_verify_choices(config, rules): 473 475 return 0 474 476 return 1 … … 482 484 # Cancel out all values which have to be deduced 483 485 for varname, vartype, name, choices, cond in rules: 484 if ( (vartype == 'y') and (varname in config) and (config[varname] == '*')):486 if (vartype == 'y') and (varname in config) and (config[varname] == '*'): 485 487 config[varname] = None 486 488 … … 494 496 varname, vartype, name, choices, cond = rule 495 497 496 if ((cond) and (not check_condition(cond, config, rules))):498 if cond and (not check_condition(cond, config, rules)): 497 499 continue 498 500 499 if (varname == selname):501 if varname == selname: 500 502 position = cnt 501 503 502 if (not varname in config):504 if not varname in config: 503 505 value = None 504 506 else: … … 526 528 (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position) 527 529 528 if (button == 'cancel'):530 if button == 'cancel': 529 531 return 'Configuration canceled' 530 532 531 if (button == 'done'):533 if button == 'done': 532 534 if (infer_verify_choices(config, rules)): 533 535 break … … 536 538 continue 537 539 538 if (value == 0):540 if value == 0: 539 541 load_presets(PRESETS_DIR, MAKEFILE, screen, config) 540 542 position = 1 … … 542 544 543 545 position = None 544 if (not value in opt2row):546 if not value in opt2row: 545 547 raise RuntimeError("Error selecting value: %s" % value) 546 548 547 549 (selname, seltype, name, choices) = opt2row[value] 548 550 549 if (not selname in config):551 if not selname in config: 550 552 value = None 551 553 else: 552 554 value = config[selname] 553 555 554 if (seltype == 'choice'):556 if seltype == 'choice': 555 557 config[selname] = subchoice(screen, name, choices, value) 556 elif ( (seltype == 'y/n') or (seltype == 'n/y')):557 if (config[selname] == 'y'):558 elif (seltype == 'y/n') or (seltype == 'n/y'): 559 if config[selname] == 'y': 558 560 config[selname] = 'n' 559 561 else:
Note:
See TracChangeset
for help on using the changeset viewer.