diff options
author | Roman Lacko <backup.rlacko@gmail.com> | 2012-07-31 16:50:35 +0200 |
---|---|---|
committer | Roman Lacko <backup.rlacko@gmail.com> | 2012-07-31 16:50:35 +0200 |
commit | b73480ba3dede8969f20443bc4b0a140d4b2e8d8 (patch) | |
tree | 8c26d0f3f25eb3352fd9294c454cf8a2902624dc /utils.py | |
parent | fb0b8a3fec266077b5b686430bc3f973fafe06f8 (diff) |
Introduced new command line options --version and --list-versions
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -9,6 +9,32 @@ import popenasync import fnmatch +def has_option(name): + try: + sys.argv.remove('--%s' % name) + return True + except ValueError: + pass + return False + + +def option_value(name): + for index, option in enumerate(sys.argv): + if option == '--' + name: + if index+1 >= len(sys.argv): + raise DistutilsOptionError( + 'The option %s requires a value' % option) + value = sys.argv[index+1] + sys.argv[index:index+2] = [] + return value + if option.startswith('--' + name + '='): + value = option[len(name)+3:] + sys.argv[index:index+1] = [] + return value + env_val = os.getenv(name.upper().replace('-', '_')) + return env_val + + def filter_match(name, patterns): for pattern in patterns: if pattern is None: |