From b73480ba3dede8969f20443bc4b0a140d4b2e8d8 Mon Sep 17 00:00:00 2001 From: Roman Lacko Date: Tue, 31 Jul 2012 16:50:35 +0200 Subject: Introduced new command line options --version and --list-versions --- utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'utils.py') diff --git a/utils.py b/utils.py index 83af2e915..81deedd51 100644 --- a/utils.py +++ b/utils.py @@ -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: -- cgit v1.2.3