Changeset e4d540b in mainline
- Timestamp:
- 2010-12-03T21:48:17Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 62bb73e
- Parents:
- 41a7f62
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/config.py
r41a7f62 re4d540b 212 212 return choices[value][0] 213 213 214 def check_choices(defaults, ask_names): 215 "Check whether all accessible variables have a default" 214 ## Infer and verify configuration values. 215 # 216 # Augment @a defaults with values that can be inferred, purge invalid ones 217 # and verify that all variables have a value (previously specified or inferred). 218 # 219 # @param defaults Configuration to work on 220 # @param ask_names Rules 221 # 222 # @return True if configuration is complete and valid, False 223 # otherwise. 224 # 225 def infer_verify_choices(defaults, ask_names): 226 "Infer and verify configuration values." 216 227 217 228 for varname, vartype, name, choices, cond in ask_names: … … 220 231 221 232 if (not varname in defaults): 222 return False 223 233 default = None 234 else: 235 default = defaults[varname] 236 237 if not rule_value_is_valid((varname, vartype, name, choices, cond), default): 238 default = None 239 240 rdef = rule_get_default((varname, vartype, name, choices, cond)) 241 if rdef != None: 242 default = rdef 243 defaults[varname] = rdef 244 245 if (not varname in defaults): 246 return False 247 248 return True 249 250 ## Get default value from a rule. 251 def rule_get_default(rule): 252 varname, vartype, name, choices, cond = rule 253 254 default = None 255 256 if (vartype == 'choice'): 257 # If there is just one option, use it 258 if (len(choices) == 1): 259 default = choices[0][0] 260 elif (vartype == 'y'): 261 default = '*' 262 elif (vartype == 'n'): 263 default = 'n' 264 elif (vartype == 'y/n'): 265 default = 'y' 266 elif (vartype == 'n/y'): 267 default = 'n' 268 else: 269 raise RuntimeError("Unknown variable type: %s" % vartype) 270 271 return default 272 273 ## Get option from a rule. 274 # 275 # @param rule Rule for a variable 276 # @param value Current value of the variable 277 # 278 # @return Option (string) to ask or None which means not to ask. 279 # 280 def rule_get_option(rule, value): 281 varname, vartype, name, choices, cond = rule 282 283 option = None 284 285 if (vartype == 'choice'): 286 # If there is just one option, don't ask 287 if (len(choices) != 1): 288 if (value == None): 289 option = "? %s --> " % name 290 else: 291 option = " %s [%s] --> " % (name, value) 292 elif (vartype == 'y'): 293 pass 294 elif (vartype == 'n'): 295 pass 296 elif (vartype == 'y/n'): 297 option = " <%s> %s " % (yes_no(value), name) 298 elif (vartype == 'n/y'): 299 option =" <%s> %s " % (yes_no(value), name) 300 else: 301 raise RuntimeError("Unknown variable type: %s" % vartype) 302 303 return option 304 305 ## Check if variable value is valid. 306 # 307 # @param rule Rule for the variable 308 # @param value Value of the variable 309 # 310 # @return True if valid, False if not valid. 311 # 312 def rule_value_is_valid(rule, value): 313 varname, vartype, name, choices, cond = rule 314 315 if value == None: 316 return True 317 318 if (vartype == 'choice'): 319 if (not value in [choice[0] for choice in choices]): 320 return False 321 elif (vartype == 'y'): 322 if value != 'y': 323 return False 324 elif (vartype == 'n'): 325 if value != 'n': 326 return False 327 elif (vartype == 'y/n'): 328 if not value in ['y', 'n']: 329 return False 330 elif (vartype == 'n/y'): 331 if not value in ['y', 'n']: 332 return False 333 else: 334 raise RuntimeError("Unknown variable type: %s" % vartype) 335 224 336 return True 225 337 … … 350 462 # Default mode: only check defaults and regenerate configuration 351 463 if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')): 352 if ( check_choices(defaults, ask_names)):464 if (infer_verify_choices(defaults, ask_names)): 353 465 create_output(MAKEFILE, MACROS, defaults, ask_names) 354 466 return 0 … … 356 468 # Check mode: only check defaults 357 469 if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')): 358 if ( check_choices(defaults, ask_names)):470 if (infer_verify_choices(defaults, ask_names)): 359 471 return 0 360 472 return 1 … … 377 489 options.append(" --- Load preconfigured defaults ... ") 378 490 379 for varname, vartype, name, choices, cond in ask_names: 491 for rule in ask_names: 492 varname, vartype, name, choices, cond = rule 380 493 381 494 if ((cond) and (not check_condition(cond, defaults, ask_names))): … … 390 503 default = defaults[varname] 391 504 392 if (vartype == 'choice'): 393 # Check if the default is an acceptable value 394 if ((default) and (not default in [choice[0] for choice in choices])): 395 default = None 396 defaults.pop(varname) 397 398 # If there is just one option, use it 399 if (len(choices) == 1): 400 defaults[varname] = choices[0][0] 401 continue 402 403 if (default == None): 404 options.append("? %s --> " % name) 405 else: 406 options.append(" %s [%s] --> " % (name, default)) 407 elif (vartype == 'y'): 408 defaults[varname] = '*' 409 continue 410 elif (vartype == 'n'): 411 defaults[varname] = 'n' 412 continue 413 elif (vartype == 'y/n'): 414 if (default == None): 415 default = 'y' 416 defaults[varname] = default 417 options.append(" <%s> %s " % (yes_no(default), name)) 418 elif (vartype == 'n/y'): 419 if (default == None): 420 default = 'n' 421 defaults[varname] = default 422 options.append(" <%s> %s " % (yes_no(default), name)) 423 else: 424 raise RuntimeError("Unknown variable type: %s" % vartype) 505 if not rule_value_is_valid(rule, default): 506 default = None 507 508 rdef = rule_get_default(rule) 509 if rdef != None: 510 default = rdef 511 defaults[varname] = rdef 512 513 option = rule_get_option(rule, default) 514 if option != None: 515 options.append(option) 425 516 426 517 opt2row[cnt] = (varname, vartype, name, choices) … … 437 528 438 529 if (button == 'done'): 439 if ( check_choices(defaults, ask_names)):530 if (infer_verify_choices(defaults, ask_names)): 440 531 break 441 532 else: … … 455 546 456 547 if (not selname in defaults): 457 548 default = None 458 549 else: 459 550 default = defaults[selname]
Note:
See TracChangeset
for help on using the changeset viewer.