this allows true and false as alias for on and off.
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)
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)
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)
# (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
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):
"""
"""Simple colored logging classes"""
import sys
+import gbp.tristate
logger = None
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
# 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' ]
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
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,
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")
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",
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",