diff options
-rwxr-xr-x | gbp-clone | 2 | ||||
-rwxr-xr-x | gbp-pq | 3 | ||||
-rwxr-xr-x | gbp-pull | 2 | ||||
-rw-r--r-- | gbp/config.py | 15 | ||||
-rw-r--r-- | gbp/log.py | 5 | ||||
-rw-r--r-- | gbp/tristate.py | 22 | ||||
-rwxr-xr-x | git-buildpackage | 2 | ||||
-rwxr-xr-x | git-dch | 2 | ||||
-rwxr-xr-x | git-import-dsc | 2 | ||||
-rwxr-xr-x | git-import-orig | 2 |
10 files changed, 42 insertions, 15 deletions
@@ -45,7 +45,7 @@ def main(argv): parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color") + parser.add_config_file_option(option_name="color", dest="color", type='tristate') (options, args) = parser.parse_args(argv) gbp.log.setup(options.color, options.verbose) @@ -162,7 +162,8 @@ def main(argv): parser.add_boolean_config_file_option(option_name="patch-numbers", dest="patch_numbers") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color") + parser.add_config_file_option(option_name="color", dest="color", type='tristate') + (options, args) = parser.parse_args(argv) gbp.log.setup(options.color, options.verbose) @@ -80,7 +80,7 @@ def main(argv): branch_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color") + parser.add_config_file_option(option_name="color", dest="color", type='tristate') (options, args) = parser.parse_args(argv) diff --git a/gbp/config.py b/gbp/config.py index c989afe..e623c3b 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -3,7 +3,7 @@ # (C) 2006,2007,2010 Guido Guenther <agx@sigxcpu.org> """handles command line and config file option parsing for the gbp commands""" -from optparse import OptionParser, OptionGroup, Option +from optparse import OptionParser, OptionGroup, Option, OptionValueError from ConfigParser import SafeConfigParser from copy import copy import os.path @@ -11,15 +11,26 @@ try: from gbp.gbp_version import gbp_version except ImportError: gbp_version = "[Unknown version]" +import gbp.tristate def expand_path(option, opt, value): value = os.path.expandvars(value) return os.path.expanduser(value) +def check_tristate(option, opt, value): + try: + val = gbp.tristate.Tristate(value) + except TypeError: + raise OptionValueError( + "option %s: invalid value: %r" % (opt, value)) + else: + return val + class GbpOption(Option): - TYPES = Option.TYPES + ('path',) + TYPES = Option.TYPES + ('path', 'tristate') TYPE_CHECKER = copy(Option.TYPE_CHECKER) TYPE_CHECKER['path'] = expand_path + TYPE_CHECKER['tristate'] = check_tristate class GbpOptionParser(OptionParser): """ @@ -18,6 +18,7 @@ """Simple colored logging classes""" import sys +import gbp.tristate logger = None @@ -53,9 +54,9 @@ class Logger(object): if type(color) == type(True): self.color = color else: - if color.lower() == "on": + if color.is_on(): self.color = True - elif color.lower() == "auto": + elif color.is_auto(): if (sys.stderr.isatty() and sys.stdout.isatty()): self.color = True diff --git a/gbp/tristate.py b/gbp/tristate.py index ae47d03..95391b9 100644 --- a/gbp/tristate.py +++ b/gbp/tristate.py @@ -16,10 +16,11 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA class Tristate(object): - """Tri-state value: on, off or auto""" - AUTO = -1 - ON = True - OFF = False + """Tri-state value: on, off or auto """ + ON = True # state is on == do it + OFF = False # state is off == don't do it + AUTO = -1 # autodetect == do if possible + # We accept true as alias for on and false as alias for off _VALID_NAMES = [ 'on', 'off', 'true', 'false', 'auto' ] @@ -63,3 +64,16 @@ class Tristate(object): def is_off(self): return [False, True][self._state == self.OFF] + def do(self, function, *args, **kwargs): + """ + Run function if tristate is on or auto, only report a failure if + tristate is on since failing is o.k. for autodetect. + """ + if self.is_off(): + return True + + success = function(*args, **kwargs) + if not success: + return [True, False][self.is_on()] + + return True diff --git a/git-buildpackage b/git-buildpackage index 42049d3..a7a0cec 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -247,7 +247,7 @@ def main(argv): parser.add_boolean_config_file_option(option_name = "ignore-new", dest="ignore_new") parser.add_option("--git-verbose", action="store_true", dest="verbose", default=False, help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color") + parser.add_config_file_option(option_name="color", dest="color", type='tristate') tag_group.add_option("--git-tag", action="store_true", dest="tag", default=False, help="create a tag after a successful build") tag_group.add_option("--git-tag-only", action="store_true", dest="tag_only", default=False, @@ -340,7 +340,7 @@ def main(argv): help="options to pass to git-log, default is '%(git-log)s'") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color") + parser.add_config_file_option(option_name="color", dest="color", type='tristate') range_group.add_option("-s", "--since", dest="since", help="commit to start from (e.g. HEAD^^^, debian/0.4.3)") range_group.add_option("-a", "--auto", action="store_true", dest="auto", default=False, help="autocomplete changelog from last snapshot or tag") diff --git a/git-import-dsc b/git-import-dsc index ee7a72b..409e345 100755 --- a/git-import-dsc +++ b/git-import-dsc @@ -170,7 +170,7 @@ def main(argv): parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color") + parser.add_config_file_option(option_name="color", dest="color", type='tristate') parser.add_option("--download", action="store_true", dest="download", default=False, help="download source package") branch_group.add_config_file_option(option_name="debian-branch", diff --git a/git-import-orig b/git-import-orig index 10d85b1..9a09605 100755 --- a/git-import-orig +++ b/git-import-orig @@ -235,7 +235,7 @@ def main(argv): dest='interactive') parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color") + parser.add_config_file_option(option_name="color", dest="color", type='tristate') # Accepted for compatibility parser.add_option("--no-dch", dest='no_dch', action="store_true", |