Changeset aca97582 in mainline for tools/config.py


Ignore:
Timestamp:
2019-06-30T11:12:32Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5a5269d
Parents:
d22be89
Message:

tools/config.py: Clean up argument handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config.py

    rd22be89 raca97582  
    4242import random
    4343
    44 RULES_FILE = sys.argv[1]
     44ARGPOS_RULES = 1
     45ARGPOS_CHOICE = 2
     46ARGPOS_PRESET = 3
     47
     48RULES_FILE = sys.argv[ARGPOS_RULES]
    4549MAKEFILE = 'Makefile.config'
    4650MACROS = 'config.h'
     
    676680        parse_rules(RULES_FILE, rules)
    677681
     682        if len(sys.argv) > ARGPOS_CHOICE:
     683                choice = sys.argv[ARGPOS_CHOICE]
     684        else:
     685                choice = None
     686
     687        if len(sys.argv) > ARGPOS_PRESET:
     688                preset = sys.argv[ARGPOS_PRESET]
     689        else:
     690                preset = None
     691
    678692        # Input configuration file can be specified on command line
    679693        # otherwise configuration from previous run is used.
    680         if len(sys.argv) >= 4:
    681                 profile = parse_profile_name(sys.argv[3])
     694        if preset is not None:
     695                profile = parse_profile_name(preset)
    682696                read_presets(profile, config)
    683697        elif os.path.exists(MAKEFILE):
     
    685699
    686700        # Default mode: check values and regenerate configuration files
    687         if (len(sys.argv) >= 3) and (sys.argv[2] == 'default'):
     701        if choice == 'default':
    688702                if (infer_verify_choices(config, rules)):
    689703                        preprocess_config(config, rules)
     
    693707        # Hands-off mode: check values and regenerate configuration files,
    694708        # but no interactive fallback
    695         if (len(sys.argv) >= 3) and (sys.argv[2] == 'hands-off'):
    696                 # We deliberately test sys.argv >= 4 because we do not want
     709        if choice == 'hands-off':
     710                # We deliberately test this because we do not want
    697711                # to read implicitly any possible previous run configuration
    698                 if len(sys.argv) < 4:
     712                if preset is None:
    699713                        sys.stderr.write("Configuration error: No presets specified\n")
    700714                        return 2
     
    709723
    710724        # Check mode: only check configuration
    711         if (len(sys.argv) >= 3) and (sys.argv[2] == 'check'):
     725        if choice == 'check':
    712726                if infer_verify_choices(config, rules):
    713727                        return 0
     
    715729
    716730        # Random mode
    717         if (len(sys.argv) == 3) and (sys.argv[2] == 'random'):
     731        if choice == 'random':
    718732                ok = random_choices(config, rules, 0)
    719733                if not ok:
Note: See TracChangeset for help on using the changeset viewer.