Changeset 8e7c9fe in mainline for tools/config.py
- Timestamp:
- 2014-09-12T03:45:25Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c53b58e
- Parents:
- 3eb0c85 (diff), 105d8d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/config.py
r3eb0c85 r8e7c9fe 40 40 import subprocess 41 41 import xtui 42 import random 42 43 43 44 RULES_FILE = sys.argv[1] … … 256 257 257 258 return True 259 260 ## Fill the configuration with random (but valid) values. 261 # 262 # The random selection takes next rule and if the condition does 263 # not violate existing configuration, random value of the variable 264 # is selected. 265 # This happens recursively as long as there are more rules. 266 # If a conflict is found, we backtrack and try other settings of the 267 # variable or ignoring the variable altogether. 268 # 269 # @param config Configuration to work on 270 # @param rules Rules 271 # @param start_index With which rule to start (initial call must specify 0 here). 272 # @return True if able to find a valid configuration 273 def random_choices(config, rules, start_index): 274 "Fill the configuration with random (but valid) values." 275 if start_index >= len(rules): 276 return True 277 278 varname, vartype, name, choices, cond = rules[start_index] 279 280 # First check that this rule would make sense 281 if cond: 282 if not check_condition(cond, config, rules): 283 return random_choices(config, rules, start_index + 1) 284 285 # Remember previous choices for backtracking 286 yes_no = 0 287 choices_indexes = range(0, len(choices)) 288 random.shuffle(choices_indexes) 289 290 # Remember current configuration value 291 old_value = None 292 try: 293 old_value = config[varname] 294 except KeyError: 295 old_value = None 296 297 # For yes/no choices, we ran the loop at most 2 times, for select 298 # choices as many times as there are options. 299 try_counter = 0 300 while True: 301 if vartype == 'choice': 302 if try_counter >= len(choices_indexes): 303 break 304 value = choices[choices_indexes[try_counter]][0] 305 elif vartype == 'y' or vartype == 'n': 306 if try_counter > 0: 307 break 308 value = vartype 309 elif vartype == 'y/n' or vartype == 'n/y': 310 if try_counter == 0: 311 yes_no = random.randint(0, 1) 312 elif try_counter == 1: 313 yes_no = 1 - yes_no 314 else: 315 break 316 if yes_no == 0: 317 value = 'n' 318 else: 319 value = 'y' 320 else: 321 raise RuntimeError("Unknown variable type: %s" % vartype) 322 323 config[varname] = value 324 325 ok = random_choices(config, rules, start_index + 1) 326 if ok: 327 return True 328 329 try_counter = try_counter + 1 330 331 # Restore the old value and backtrack 332 # (need to delete to prevent "ghost" variables that do not exist under 333 # certain configurations) 334 config[varname] = old_value 335 if old_value is None: 336 del config[varname] 337 338 return random_choices(config, rules, start_index + 1) 339 258 340 259 341 ## Get default value from a rule. … … 555 637 return 1 556 638 639 # Random mode 640 if (len(sys.argv) == 3) and (sys.argv[2] == 'random'): 641 ok = random_choices(config, rules, 0) 642 if not ok: 643 sys.stderr.write("Internal error: unable to generate random config.\n") 644 return 2 645 if not infer_verify_choices(config, rules): 646 sys.stderr.write("Internal error: random configuration not consistent.\n") 647 return 2 648 preprocess_config(config, rules) 649 create_output(MAKEFILE, MACROS, config, rules) 650 651 return 0 652 557 653 screen = xtui.screen_init() 558 654 try:
Note:
See TracChangeset
for help on using the changeset viewer.