Changeset d40ffbb in mainline for tools/config.py


Ignore:
Timestamp:
2010-12-06T12:29:04Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e3c3172
Parents:
8fe3f832
Message:

coding style fixes (no change in functionality)

  • consistent tab indentation
  • no tabs for non-indentation
  • non-yoda function names
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config.py

    r8fe3f832 rd40ffbb  
    4747
    4848def read_config(fname, config):
    49         "Read saved values from last configuration run"
     49        "Read saved values from last configuration run or a preset file"
    5050       
    5151        inf = open(fname, 'r')
     
    218218# and verify that all variables have a value (previously specified or inferred).
    219219#
    220 # @param config Configuration to work on
    221 # @param rules  Rules
    222 #
    223 # @return       True if configuration is complete and valid, False
    224 #               otherwise.
     220# @param config Configuration to work on
     221# @param rules  Rules
     222#
     223# @return True if configuration is complete and valid, False
     224#         otherwise.
    225225#
    226226def infer_verify_choices(config, rules):
     
    229229        for rule in rules:
    230230                varname, vartype, name, choices, cond = rule
    231 
     231               
    232232                if cond and (not check_condition(cond, config, rules)):
    233233                        continue
     
    237237                else:
    238238                        value = config[varname]
    239 
    240                 if not rule_value_is_valid(rule, value):
     239               
     240                if not validate_rule_value(rule, value):
    241241                        value = None
    242 
    243                 default = rule_get_default(rule)
     242               
     243                default = get_default_rule(rule)
    244244                if default != None:
    245245                        config[varname] = default
    246 
     246               
    247247                if not varname in config:
    248248                        return False
     
    251251
    252252## Get default value from a rule.
    253 def rule_get_default(rule):
     253def get_default_rule(rule):
    254254        varname, vartype, name, choices, cond = rule
    255 
     255       
    256256        default = None
    257 
     257       
    258258        if vartype == 'choice':
    259259                # If there is just one option, use it
     
    270270        else:
    271271                raise RuntimeError("Unknown variable type: %s" % vartype)
    272 
     272       
    273273        return default
    274274
    275275## Get option from a rule.
    276276#
    277 # @param rule   Rule for a variable
    278 # @param value  Current value of the variable
     277# @param rule  Rule for a variable
     278# @param value Current value of the variable
    279279#
    280280# @return Option (string) to ask or None which means not to ask.
    281281#
    282 def rule_get_option(rule, value):
     282def get_rule_option(rule, value):
    283283        varname, vartype, name, choices, cond = rule
    284 
     284       
    285285        option = None
    286 
     286       
    287287        if vartype == 'choice':
    288288                # If there is just one option, don't ask
     
    302302        else:
    303303                raise RuntimeError("Unknown variable type: %s" % vartype)
    304 
     304       
    305305        return option
    306306
    307307## Check if variable value is valid.
    308308#
    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 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#
     314def validate_rule_value(rule, value):
    315315        varname, vartype, name, choices, cond = rule
    316316       
    317317        if value == None:
    318318                return True
    319 
     319       
    320320        if vartype == 'choice':
    321321                if not value in [choice[0] for choice in choices]:
     
    335335        else:
    336336                raise RuntimeError("Unknown variable type: %s" % vartype)
    337 
     337       
    338338        return True
    339339
     
    415415## Ask user to choose a configuration profile.
    416416#
    417 def profile_choose(root, fname, screen, config):
     417def choose_profile(root, fname, screen, config):
    418418        options = []
    419419        opt2path = {}
     
    453453## Read presets from a configuration profile.
    454454#
    455 # @param profile        Profile to load from (a list of string components)
    456 # @param config         Output configuration
    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#
     458def read_presets(profile, config):
    459459        path = os.path.join(PRESETS_DIR, profile[0], MAKEFILE)
    460460        read_config(path, config)
    461 
     461       
    462462        if len(profile) > 1:
    463463                path = os.path.join(PRESETS_DIR, profile[0], profile[1], MAKEFILE)
     
    466466## Parse profile name (relative OS path) into a list of components.
    467467#
    468 # @param profile_name   Relative path (using OS separator)
    469 # @return               List of components
     468# @param profile_name Relative path (using OS separator)
     469# @return             List of components
    470470#
    471471def parse_profile_name(profile_name):
    472472        profile = []
    473 
     473       
    474474        head, tail = os.path.split(profile_name)
    475475        if head != '':
    476476                profile.append(head)
    477 
     477       
    478478        profile.append(tail)
    479479        return profile
     
    491491        if len(sys.argv) >= 4:
    492492                profile = parse_profile_name(sys.argv[3])
    493                 presets_read(profile, config)
     493                read_presets(profile, config)
    494494        elif os.path.exists(MAKEFILE):
    495495                read_config(MAKEFILE, config)
     
    538538                                        value = config[varname]
    539539                               
    540                                 if not rule_value_is_valid(rule, value):
     540                                if not validate_rule_value(rule, value):
    541541                                        value = None
    542 
    543                                 default = rule_get_default(rule)
     542                               
     543                                default = get_default_rule(rule)
    544544                                if default != None:
    545545                                        if value == None:
    546546                                                value = default
    547547                                        config[varname] = value
    548 
    549                                 option = rule_get_option(rule, value)
     548                               
     549                                option = get_rule_option(rule, value)
    550550                                if option != None:
    551551                                        options.append(option)
     
    573573                       
    574574                        if value == 0:
    575                                 profile = profile_choose(PRESETS_DIR, MAKEFILE, screen, config)
     575                                profile = choose_profile(PRESETS_DIR, MAKEFILE, screen, config)
    576576                                if profile != None:
    577                                         presets_read(profile, config)
     577                                        read_presets(profile, config)
    578578                                position = 1
    579579                                continue
Note: See TracChangeset for help on using the changeset viewer.