From b3a5ba1408320453f2902e3121d7587079eeb529 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 24 Feb 2015 13:58:43 +0200 Subject: [PATCH 1/6] config: convert to using argparse Utilize the newer and more flexible argparse module instead of optparse. Configuration file loading is handled in a separate class. This patch implements a gbp-specific argparser class for handling prefix and using the config as default values. The parser is actually a wrapper class around argument parser and argument groups in order to avoid inheriting private classes of the argparse module. All gbp commands are changed to use the newly added gbp-specific argparser. Signed-off-by: Markus Lehtonen --- gbp/config.py | 726 ++++++++++---------- gbp/scripts/buildpackage.py | 183 +++-- gbp/scripts/buildpackage_rpm.py | 247 ++++--- gbp/scripts/clone.py | 83 ++- gbp/scripts/config.py | 56 +- gbp/scripts/create_remote_repo.py | 111 +-- gbp/scripts/dch.py | 194 +++--- gbp/scripts/export_orig.py | 75 +- gbp/scripts/import_dsc.py | 155 ++--- gbp/scripts/import_dscs.py | 4 +- gbp/scripts/import_orig.py | 157 ++--- gbp/scripts/import_ref.py | 95 ++- gbp/scripts/import_srpm.py | 171 +++-- gbp/scripts/pq.py | 79 ++- gbp/scripts/pq_rpm.py | 82 ++- gbp/scripts/pristine_tar.py | 61 +- gbp/scripts/pull.py | 76 +- gbp/scripts/push.py | 60 +- gbp/scripts/rpm_ch.py | 136 ++-- gbp/scripts/tag.py | 50 +- tests/18_test_Config.py | 79 ++- tests/27_test_create_remote_repo.py | 4 +- tests/component/rpm/test_import_orig_rpm.py | 16 +- tests/component/rpm/test_import_srpm.py | 3 +- tests/component/rpm/test_pq_rpm.py | 8 +- tests/doctests/test_Config.py | 72 +- 26 files changed, 1441 insertions(+), 1542 deletions(-) diff --git a/gbp/config.py b/gbp/config.py index 76a850de..b5c61cd3 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -16,9 +16,9 @@ # """handles command line and config file option parsing for the gbp commands""" -from optparse import OptionParser, OptionGroup, Option, OptionValueError +from argparse import (ArgumentParser, ArgumentDefaultsHelpFormatter, + ArgumentTypeError) import configparser -from copy import copy import errno import os.path import sys @@ -40,67 +40,14 @@ """ -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 - - -def save_option(f): - """save options on the underlying parser""" - def _decorator(self, *args, **kwargs): - obj = self - option_name = kwargs.get('option_name') - if not option_name and len(args): - option_name = args[0] - - # We're decorating GbpOption but store valid_options on - # GbpOptionParser - if not hasattr(obj, 'valid_options'): - if not hasattr(obj, 'parser'): - raise ValueError("Can only decorete GbpOptionParser and GbpOptionGroup not %s" % obj) - else: - obj = obj.parser +class GbpConfig(object): + """Handles gbp config files""" + default_config_files = [('/etc/git-buildpackage/gbp.conf', 'system'), + ('~/.gbp.conf', 'global'), + ('%(top_dir)s/.gbp.conf', None), + ('%(top_dir)s/debian/gbp.conf', 'debian'), + ('%(git_dir)s/gbp.conf', None)] - if option_name and not option_name.startswith('no-'): - obj.valid_options.append(option_name) - return f(self, *args, **kwargs) - return _decorator - - -class GbpOption(Option): - TYPES = Option.TYPES + ('path', 'tristate') - TYPE_CHECKER = copy(Option.TYPE_CHECKER) - TYPE_CHECKER['path'] = expand_path - TYPE_CHECKER['tristate'] = check_tristate - - -class GbpOptionParser(OptionParser): - """ - Handles commandline options and parsing of config files - @ivar command: the gbp command we store the options for - @type command: string - @ivar prefix: prefix to prepend to all commandline options - @type prefix: string - @ivar config: current configuration parameters - @type config: dict - @cvar defaults: defaults value of an option if not in the config file or - given on the command line - @type defaults: dict - @cvar help: help messages - @type help: dict - @cvar def_config_files: config files we parse - @type def_config_files: dict (type, path) - """ defaults = {'abbrev': 7, 'allow-unauthenticated': 'False', 'arch': '', @@ -189,199 +136,157 @@ class GbpOptionParser(OptionParser): 'upstream-vcs-tag': '', 'urgency': 'medium', } - help = { + + default_helps = { 'debian-branch': - "Branch the Debian package is being developed on, " - "default is '%(debian-branch)s'", + "Branch the Debian package is being developed on", 'upstream-branch': - "Upstream branch, default is '%(upstream-branch)s'", + "Upstream branch", 'upstream-tree': - "Where to generate the upstream tarball from " - "(tag or branch), default is '%(upstream-tree)s'", + "Where to generate the upstream tarball from (tag or branch)", 'pq-from': - "How to find the patch queue base. DEBIAN or TAG, " - "the default is '%(pq-from)s'", + "How to find the patch queue base. DEBIAN or TAG", 'debian-tag': - "Format string for debian tags, " - "default is '%(debian-tag)s'", + "Format string for debian tags", 'debian-tag-msg': - "Format string for signed debian-tag messages, " - "default is '%(debian-tag-msg)s'", + "Format string for signed debian-tag messages", 'upstream-tag': - "Format string for upstream tags, " - "default is '%(upstream-tag)s'", + "Format string for upstream tags", 'sign-tags': - "Whether to sign tags, default is '%(sign-tags)s'", + "Whether to sign tags", 'keyid': - "GPG keyid to sign tags with, default is '%(keyid)s'", + "GPG keyid to sign tags with", 'import-msg': "Format string for commit message used to commit " - "the upstream tarball, default is '%(import-msg)s'", + "the upstream tarball", 'commit-msg': - "Format string for commit message used to commit, " - "the changelog, default is '%(commit-msg)s'", + "Format string for commit message used to commit the changelog", 'pristine-tar': - "Use pristine-tar to create orig tarball, " - "default is '%(pristine-tar)s'", + "Use pristine-tar to create orig tarball", 'pristine-tar-commit': - "When generating a tarball commit it to the pristine-tar branch '%(pristine-tar-commit)s' " - "default is '%(pristine-tar-commit)s'", + "When generating a tarball commit it to the pristine-tar branch", 'filter-pristine-tar': - "Filter pristine-tar when filter option is used, default is '%(filter-pristine-tar)s'", + "Filter pristine-tar when filter option is used", 'filter': - "Files to filter out during import (can be given multiple times), default is %(filter)s", + "Files to filter out during import (can be given multiple times)", 'git-author': - "Use name and email from git-config for changelog trailer, default is '%(git-author)s'", + "Use name and email from git-config for changelog trailer", 'full': - "Include the full commit message instead of only the first line, default is '%(full)s'", + "Include the full commit message instead of only the first line", 'meta': - "Parse meta tags in commit messages, default is '%(meta)s'", + "Parse meta tags in commit messages", 'meta-closes': - "Meta tags for the bts close commands, default is '%(meta-closes)s'", + "Meta tags for the bts close commands", 'meta-closes-bugnum': - "Meta bug number format, default is '%(meta-closes-bugnum)s'", + "Meta bug number format", 'ignore-new': - "Build with uncommitted changes in the source tree, default is '%(ignore-new)s'", + "Build with uncommitted changes in the source tree", 'ignore-branch': - "Build although debian-branch != current branch, " - "default is '%(ignore-branch)s'", + "Build although debian-branch != current branch", 'overlay': - "extract orig tarball when using export-dir option, " - "default is '%(overlay)s'", + "extract orig tarball when using export-dir option", 'remote-url-pattern': - "Remote url pattern to create the repo at, " - "default is '%(remote-url-pattern)s'", + "Remote url pattern to create the repo at", 'multimaint': - "Note multiple maintainers, default is '%(multimaint)s'", + "Note multiple maintainers", 'multimaint-merge': - "Merge commits by maintainer, " - "default is '%(multimaint-merge)s'", + "Merge commits by maintainer", 'pbuilder': - "Invoke git-pbuilder for building, " - "default is '%(pbuilder)s'", + "Invoke git-pbuilder for building", 'dist': - "Build for this distribution when using git-pbuilder, " - "default is '%(dist)s'", + "Build for this distribution when using git-pbuilder", 'arch': - "Build for this architecture when using git-pbuilder, " - "default is '%(arch)s'", + "Build for this architecture when using git-pbuilder", 'qemubuilder': - "Invoke git-pbuilder with qemubuilder for building, " - "default is '%(qemubuilder)s'", + "Invoke git-pbuilder with qemubuilder for building", 'interactive': - "Run command interactively, default is '%(interactive)s'", + "Run command interactively", 'color': - "Whether to use colored output, default is '%(color)s'", + "Whether to use colored output", 'color-scheme': "Colors to use in output (when color is enabled), format " "is ':::', e.g. " "'cyan:34::'. Numerical values and color names are " "accepted, empty fields indicate using the default.", 'spawn-editor': - "Whether to spawn an editor after adding the " - "changelog entry, default is '%(spawn-editor)s'", + "Whether to spawn an editor after adding the changelog entry", 'patch-numbers': - "Whether to number patch files, " - "default is %(patch-numbers)s", + "Whether to number patch files", 'patch-num-format': - "The format specifier for patch number prefixes, " - "default is %(patch-num-format)s", + "The format specifier for patch number prefixes", 'renumber': "Whether to renumber patches exported from patch queues, " - "instead of preserving the number specified in " - "'Gbp-Pq: Name' tags, default is %(renumber)s", + "instead of preserving the number specified in 'Gbp-Pq: Name' tags", 'notify': - "Whether to send a desktop notification after the build, " - "default is '%(notify)s'", + "Whether to send a desktop notification after the build", 'merge': - "After the import merge the result to the debian branch, " - "default is '%(merge)s'", + "After the import merge the result to the debian branch", 'merge-mode': - "Howto merge the new upstream sources onto the debian branch, " - "default is '%(merge-mode)s'", + "Howto merge the new upstream sources onto the debian branch", 'track': - "Set up tracking for remote branches, " - "default is '%(track)s'", + "Set up tracking for remote branches", 'track-missing': - "Track missing remote branches, " - "default is '%(track-missing)s'", + "Track missing remote branches", 'author-is-committer': - "Use the authors's name also as the committer's name, " - "default is '%(author-is-committer)s'", + "Use the authors's name also as the committer's name", 'author-date-is-committer-date': - "Use the authors's date as the committer's date, " - "default is '%(author-date-is-committer-date)s'", + "Use the authors's date as the committer's date", 'create-missing-branches': - "Create missing branches automatically, " - "default is '%(create-missing-branches)s'", + "Create missing branches automatically", 'submodules': - "Transparently handle submodules in the upstream tree, " - "default is '%(submodules)s'", + "Transparently handle submodules in the upstream tree", 'postimport': - "hook run after a successful import, " - "default is '%(postimport)s'", + "hook run after a successful import", 'hooks': - "Enable running all hooks, default is %(hooks)s", + "Enable running all hooks", 'time-machine': "don't try to apply patch queue to head commit only. " - "Try at most TIME_MACHINE commits back, " - "default is '%(time-machine)d'", + "Try at most TIME_MACHINE commits back", 'pbuilder-autoconf': - "Whether to configure pbuilder automatically, " - "default is '%(pbuilder-autoconf)s'", + "Whether to configure pbuilder automatically", 'pbuilder-options': - "Options to pass to pbuilder, " - "default is '%(pbuilder-options)s'", + "Options to pass to pbuilder", 'template-dir': - "Template directory used by git init, " - "default is '%(template-dir)s'", + "Template directory used by git init", 'remote-config': "Remote definition in gbp.conf used to create the remote " - "repository, default is '%(remote-config)s'", + "repository", 'allow-unauthenticated': - "Don't verify integrity of downloaded source, " - "default is '%(allow-unauthenticated)s'", + "Don't verify integrity of downloaded source", 'symlink-orig': "Whether to create a symlink from the upstream tarball " - "to the orig.tar.gz if needed, default is " - "'%(symlink-orig)s'", + "to the orig.tar.gz if needed", 'purge': - "Purge exported package build directory. Default is '%(purge)s'", + "Purge exported package build directory.", 'drop': - "In case of 'export' drop the patch-queue branch " - "after export. Default is '%(drop)s'", + "In case of 'export' drop the patch-queue branch after export", 'abbrev': - "abbreviate commits to this length. default is '%(abbrev)s'", + "abbreviate commits to this length", 'commit': - "commit changes after export, Default is '%(commit)s'", + "commit changes after export", 'rollback': "Rollback repository changes when encountering an error", 'component': 'component name for additional tarballs', 'bare': - "wether to create a bare repository on the remote side. " - "'Default is '%(bare)s'.", + "wether to create a bare repository on the remote side.", 'urgency': - "Set urgency level, default is '%(urgency)s'", + "Set urgency level", 'repo-user': "Set repo username from the DEBFULLNAME and DEBEMAIL " "environment variables ('DEBIAN') or fallback to the " - "git configuration ('GIT'), default is '%(repo-user)s'", + "git configuration ('GIT')", 'repo-email': "Set repo email from the DEBFULLNAME and DEBEMAIL " "environment variables ('DEBIAN') or fallback to the " - "git configuration ('GIT'), default is '%(repo-email)s'" + "git configuration ('GIT')", } - short_opts = { - 'urgency': '-U', - } - - def_config_files = [('/etc/git-buildpackage/gbp.conf', 'system'), - ('~/.gbp.conf', 'global'), - ('%(top_dir)s/.gbp.conf', None), - ('%(top_dir)s/debian/gbp.conf', 'debian'), - ('%(git_dir)s/gbp.conf', None)] + default_config_files = [('/etc/git-buildpackage/gbp.conf', 'system'), + ('~/.gbp.conf', 'global'), + ('%(top_dir)s/.gbp.conf', None), + ('%(top_dir)s/debian/gbp.conf', 'debian'), + ('%(git_dir)s/gbp.conf', None)] list_opts = ['filter', 'component', 'dch-opt'] @@ -400,22 +305,22 @@ def get_config_files(cls, no_local=False): >>> conf_backup = os.getenv('GBP_CONF_FILES') >>> if conf_backup is not None: del os.environ['GBP_CONF_FILES'] >>> homedir = os.path.expanduser("~") - >>> files = GbpOptionParser.get_config_files() + >>> files = GbpConfig('prog').get_config_files() >>> files_mangled = [re.sub("^%s" % homedir, 'HOME', file) for file in files] >>> sorted(files_mangled) ['%(git_dir)s/gbp.conf', '%(top_dir)s/.gbp.conf', '%(top_dir)s/debian/gbp.conf', '/etc/git-buildpackage/gbp.conf', 'HOME/.gbp.conf'] - >>> files = GbpOptionParser.get_config_files(no_local=True) + >>> files = GbpConfig('prog').get_config_files(no_local=True) >>> files_mangled = [re.sub("^%s" % homedir, 'HOME', file) for file in files] >>> sorted(files_mangled) ['/etc/git-buildpackage/gbp.conf', 'HOME/.gbp.conf'] >>> os.environ['GBP_CONF_FILES'] = 'test1:test2' - >>> GbpOptionParser.get_config_files() + >>> GbpConfig('prog').get_config_files() ['test1', 'test2'] >>> del os.environ['GBP_CONF_FILES'] >>> if conf_backup is not None: os.environ['GBP_CONF_FILES'] = conf_backup """ envvar = os.environ.get('GBP_CONF_FILES') - files = envvar.split(':') if envvar else [f for (f, _) in cls.def_config_files] + files = envvar.split(':') if envvar else [f for (f, _) in cls.default_config_files] files = [os.path.expanduser(fname) for fname in files] if no_local: files = [fname for fname in files if fname.startswith('/')] @@ -439,6 +344,19 @@ def _read_config_file(self, repo, filename): self._warn_old_gbp_conf(filename) self.config_parser.read(filename) + def __init__(self, command, extra_sections=None, config_files=None): + self.command = os.path.basename(command[:-3] if command.endswith('.py') else command) + self.config = {} + self.config_parser = configparser.SafeConfigParser() + self._warned_old_gbp_conf = False + + if not config_files: + config_files = self.get_config_files() + try: + self._parse_config_files(config_files, extra_sections) + except configparser.ParsingError as err: + raise GbpError(str(err) + "\nSee 'man gbp.conf' for the format.") + def _warn_old_config_section(self, oldcmd, cmd): if not os.getenv("GBP_DISABLE_SECTION_DEPRECATION"): gbp.log.warn("Old style config section [%s] found " @@ -459,13 +377,13 @@ def config_file_sections(self): @staticmethod def _listify(value): """ - >>> GbpOptionParser._listify(None) + >>> GbpConfig._listify(None) [] - >>> GbpOptionParser._listify('string') + >>> GbpConfig._listify('string') ['string'] - >>> GbpOptionParser._listify('["q", "e", "d"] ') + >>> GbpConfig._listify('["q", "e", "d"] ') ['q', 'e', 'd'] - >>> GbpOptionParser._listify('[') + >>> GbpConfig._listify('[') Traceback (most recent call last): ... configparser.Error: [ is not a proper list @@ -500,15 +418,14 @@ def parse_lists(self): except ValueError: raise configparser.Error("Failed to parse %s: %s" % (opt, self.config[opt])) - def parse_config_files(self): - """ - Parse the possible config files and set appropriate values - default values - """ + def _parse_config_files(self, config_files, extra_sections=None): + """Parse the possible config files and take values from appropriate + sections.""" parser = self.config_parser # Fill in the built in values - self.config = dict(self.__class__.defaults) - config_files = self.get_config_files() + self.config = dict(self.defaults) + # Update with the values from the defaults section. This is needed + # in case the config file doesn't have a [] section at all try: repo = GitRepository(".", toplevel=False) except GitRepositoryError: @@ -543,132 +460,41 @@ def parse_config_files(self): # since this pulls in the defaults again self.config.update(dict(parser._sections[cmd].items())) - for section in self.sections: - if parser.has_section(section): - self.config.update(dict(parser._sections[section].items())) - else: - raise configparser.NoSectionError( - "Mandatory section [%s] does not exist." % section) + if extra_sections: + for section in extra_sections: + if parser.has_section(section): + self.config.update(dict(parser._sections[section].items())) + else: + raise configparser.NoSectionError( + "Mandatory section [%s] does not exist." % section) self.parse_lists() - def __init__(self, command, prefix='', usage=None, sections=[]): - """ - @param command: the command to build the config parser for - @type command: C{str} - @param prefix: A prefix to add to all command line options - @type prefix: C{str} - @param usage: a usage description - @type usage: C{str} - @param sections: additional (non optional) config file sections - to parse - @type sections: C{list} of C{str} - """ - self.command = command[:-3] if command.endswith('.py') else command - self.sections = sections - self.prefix = prefix - self.config = {} - self.valid_options = [] - self.config_parser = configparser.SafeConfigParser() - self._warned_old_gbp_conf = False - - try: - self.parse_config_files() - except configparser.ParsingError as err: - raise GbpError(str(err) + "\nSee 'man gbp.conf' for the format.") - - OptionParser.__init__(self, option_class=GbpOption, - prog="gbp %s" % self.command, - usage=usage, version='%s %s' % (self.command, - gbp_version)) - - def _is_boolean(self, dummy, *unused, **kwargs): - """is option_name a boolean option""" - ret = False - try: - if kwargs['action'] in ['store_true', 'store_false']: - ret = True - except KeyError: - ret = False - return ret - - def _get_bool_default(self, option_name): - """ - get default for boolean options - this way we can handle no-foo=True and foo=False - """ - if option_name.startswith('no-'): - pos = option_name[3:] - neg = option_name - else: - pos = option_name - neg = "no-%s" % option_name - - try: - default = self.config[pos] - except KeyError: - default = self.config[neg] - - if default.lower() in ["true", "1"]: - val = 'True' - elif default.lower() in ["false", "0"]: - val = 'False' + def get_value(self, name): + """Get a value from configuration""" + return self.config[name] + + def get_bool_value(self, name): + """Get a boolean value from configuration""" + value_str = self.config[name] + if value_str.lower() in ["true", "1"]: + value = True + elif value_str.lower() in ["false", "0"]: + value = False else: raise ValueError("Boolean options must be True or False") - return eval(val) + return value - def get_default(self, option_name, **kwargs): - """get the default value""" - if self._is_boolean(self, option_name, **kwargs): - default = self._get_bool_default(option_name) - else: - default = self.config[option_name] - return default - - def get_opt_names(self, option_name): - names = ["--%s%s" % (self.prefix, option_name)] - if option_name in self.short_opts: - if self.prefix: - raise ValueError("Options with prefix cannot have a short option") - names.insert(0, self.short_opts[option_name]) - return names - - @save_option - def add_config_file_option(self, option_name, dest, help=None, **kwargs): + def get_dual_bool_value(self, name): """ - set a option for the command line parser, the default is read from the config file - param option_name: name of the option - type option_name: string - param dest: where to store this option - type dest: string - param help: help text - type help: string + Get configuration file value for dual-boolean arguments. + Handles no-foo=True and foo=False correctly. """ - if not help: - help = self.help[option_name] - opt_names = self.get_opt_names(option_name) - default = kwargs.pop('default', None) - if default is None: - default = self.get_default(option_name, **kwargs) - OptionParser.add_option(self, *opt_names, dest=dest, - default=default, - help=help % self.config, **kwargs) - - def add_boolean_config_file_option(self, option_name, dest): - self.add_config_file_option(option_name=option_name, dest=dest, action="store_true") - neg_help = "negates '--%s%s'" % (self.prefix, option_name) - self.add_config_file_option(option_name="no-%s" % option_name, dest=dest, help=neg_help, action="store_false") - - def get_config_file_value(self, option_name): - """ - Query a single interpolated config file value. - - @param option_name: the config file option to look up - @type option_name: string - @returns: The config file option value or C{None} if it doesn't exist - @rtype: C{str} or C{None} - """ - return self.config.get(option_name) + try: + value = self.get_bool_value(name) + except KeyError: + value = self.get_bool_value("no-%s" % name) + return value def print_help(self, file=None): """ @@ -693,15 +519,15 @@ def _name_to_filename(cls, name): """ Translate a name like 'system' to a config file name - >>> GbpOptionParser._name_to_filename('foo') - >>> GbpOptionParser._name_to_filename('system') + >>> GbpConfig._name_to_filename('foo') + >>> GbpConfig._name_to_filename('system') '/etc/git-buildpackage/gbp.conf' - >>> GbpOptionParser._name_to_filename('global') + >>> GbpConfig._name_to_filename('global') '~/.gbp.conf' - >>> GbpOptionParser._name_to_filename('debian') + >>> GbpConfig._name_to_filename('debian') '%(top_dir)s/debian/gbp.conf' """ - for k, v in cls.def_config_files: + for k, v in cls.default_config_files: if name == v: return k else: @@ -729,53 +555,191 @@ def _set_config_file_value(cls, section, option, value, name=None, filename=None cfg.write(fp) -class GbpOptionGroup(OptionGroup): - @save_option - def add_config_file_option(self, option_name, dest, help=None, **kwargs): - """ - set a option for the command line parser, the default is read from the config file - param option_name: name of the option - type option_name: string - param dest: where to store this option - type dest: string - param help: help text - type help: string - """ - if not help: - help = self.parser.help[option_name] - opt_names = self.parser.get_opt_names(option_name) - default = kwargs.pop('default', None) - if default is None: - default = self.parser.get_default(option_name, **kwargs) - OptionGroup.add_option(self, *opt_names, dest=dest, - default=default, - help=help % self.parser.config, **kwargs) - - def add_boolean_config_file_option(self, option_name, dest): - self.add_config_file_option(option_name=option_name, dest=dest, action="store_true") - neg_help = "negates '--%s%s'" % (self.parser.prefix, option_name) - self.add_config_file_option(option_name="no-%s" % option_name, dest=dest, help=neg_help, action="store_false") - - -class GbpOptionParserDebian(GbpOptionParser): +def path_type(arg_str): + """Argument type for directory path strings""" + value = os.path.expandvars(arg_str) + return os.path.expanduser(value) + + +def tristate_type(arg_str): + """Type for tristate arguments""" + try: + value = gbp.tristate.Tristate(arg_str) + except TypeError: + raise ArgumentTypeError("invalid value: %r" % arg_str) + else: + return value + + +class GbpConfArgParser(object): """ - Handles commandline options and parsing of config files for Debian tools + This class adds GBP-specific feature of argument parser and argument + groups, i.e. config file options and argument prefixing. The class is + basiclly a wrapper around argument parser and argument groups and adds the + possibility to read defaults from a config file. """ - defaults = dict(GbpOptionParser.defaults) + short_opts = { + 'urgency': '-U', + } + + class _GbpArgParser(ArgumentParser): + """The "real" argument parser""" + def __init__(self, **kwargs): + """The "real" argument parser""" + prog = kwargs.get('prog') + if (prog and not + (prog.startswith('git-') or prog.startswith('gbp-'))): + kwargs['prog'] = "gbp %s" % prog + if 'formatter_class' not in kwargs: + kwargs['formatter_class'] = ArgumentDefaultsHelpFormatter + ArgumentParser.__init__(self, **kwargs) + self.command = prog if prog else self.prog + self.register('type', 'tristate', tristate_type) + self.register('type', 'path', path_type) + + def __init__(self, wrapped_instance, prefix, config=None, + conf_file_args=None): + self.wrapped = wrapped_instance + self.prefix = prefix + if config: + self.config = config + else: + self.config = GbpConfig(wrapped_instance.command) + if conf_file_args is None: + self.conf_file_args = set() + else: + self.conf_file_args = conf_file_args + + @classmethod + def create_parser(cls, prefix='', config=None, **kwargs): + """Create new GbpConfArgParser""" + parser = cls._GbpArgParser(**kwargs) + parser.add_argument('--version', action='version', + version='%s %s' % (parser.prog, gbp_version)) + return cls(parser, prefix=prefix, config=config) + + def _get_conf_key(self, *args): + """Get name of the config file key for an argument""" + # Use the first arg string by default + key = args[0] + # Search for the first "long argument name" + for arg in args: + if (len(arg) > 2 and + arg[0:2] in [c * 2 for c in self.wrapped.prefix_chars]): + key = arg + break + return key.lstrip(self.wrapped.prefix_chars) + + @staticmethod + def _is_boolean(**kwargs): + """Is the to-be-added arg a boolean option""" + if ('action' in kwargs and + kwargs['action'] in ('store_true', 'store_false')): + return True + return False + + def add_arg(self, *args, **kwargs): + """Add argument. Handles argument prefixing.""" + if self.prefix and len(args) > 1: + raise ValueError("Options with prefix cannot have a short option") + + if 'dest' not in kwargs: + kwargs['dest'] = self._get_conf_key(*args).replace('-', '_') + args = [arg.replace('--', '--%s' % self.prefix, 1) for arg in args] + return self.wrapped.add_argument(*args, **kwargs) + + def add_conf_file_arg(self, *args, **kwargs): + """Add config file argument""" + name = self._get_conf_key(*args) + if name in self.short_opts and self.short_opts[name] not in args: + args += (self.short_opts[name],) + + is_boolean = self._is_boolean(**kwargs) + if 'default' not in kwargs: + if is_boolean: + kwargs['default'] = self.config.get_dual_bool_value(name) + else: + kwargs['default'] = self.config.get_value(name) + self.conf_file_args.add(name) + if 'help' not in kwargs: + kwargs['help'] = self.config.default_helps[name] + new_arg = self.add_arg(*args, **kwargs) + + # Automatically add the inverse argument, with inverted default + if is_boolean: + kwargs['dest'] = new_arg.dest + kwargs['help'] = "negates '--%s%s'" % (self.prefix, name) + kwargs['action'] = 'store_false' \ + if kwargs['action'] == 'store_true' else 'store_true' + kwargs['default'] = not kwargs['default'] + self.add_arg('--no-%s' % name, **kwargs) + + def add_bool_conf_file_arg(self, *args, **kwargs): + """Shortcut to adding boolean args""" + kwargs['action'] = 'store_true' + self.add_conf_file_arg(*args, **kwargs) + + def _wrap_generator(self, method, *args, **kwargs): + """Helper for methods returning a new instance""" + wrapped = self.wrapped.__getattribute__(method)(*args, **kwargs) + return GbpConfArgParser(wrapped_instance=wrapped, + prefix=self.prefix, + config=self.config, + conf_file_args=self.conf_file_args) + + def add_argument_group(self, *args, **kwargs): + """Add argument group""" + return self._wrap_generator('add_argument_group', *args, **kwargs) + + def add_mutually_exclusive_group(self, *args, **kwargs): + """Add group of mutually exclusive arguments""" + return self._wrap_generator('add_mutually_exclusive_group', + *args, **kwargs) + + def __getattr__(self, name): + return self.wrapped.__getattribute__(name) + + def get_conf_file_value(self, option_name): + """ + Query a single interpolated config file value. + + @param option_name: the config file option to look up + @type option_name: string + @returns: The config file option value or C{None} if it doesn't exist + @rtype: C{str} or C{None} + """ + try: + return self.config.get_value(option_name) + except KeyError: + return None + + +class GbpConfigDebian(GbpConfig): + """Config file parser for Debian tools""" + defaults = dict(GbpConfig.defaults) defaults.update({ 'builder': 'debuild -i -I', }) def _warn_old_gbp_conf(self, gbp_conf): if os.path.exists("debian/control"): - GbpOptionParser._warn_old_gbp_conf(self, gbp_conf) + GbpConfig._warn_old_gbp_conf(self, gbp_conf) -class GbpOptionParserRpm(GbpOptionParser): - """ - Handles commandline options and parsing of config files for rpm tools - """ - defaults = dict(GbpOptionParser.defaults) +class GbpConfArgParserDebian(GbpConfArgParser): + """Joint config and arg parser for Debian tools""" + + def __init__(self, wrapped_instance, prefix, config=None, + conf_file_args=None): + if not config: + config = GbpConfigDebian(wrapped_instance.command) + super(GbpConfArgParserDebian, self).__init__(wrapped_instance, prefix, + config, conf_file_args) + + +class GbpConfigRpm(GbpConfig): + """Config file parser for the RPM tools""" + defaults = dict(GbpConfig.defaults) defaults.update({ 'tmp-dir': '/var/tmp/gbp/', 'vendor': 'Downstream', @@ -800,57 +764,45 @@ class GbpOptionParserRpm(GbpOptionParser): 'editor-cmd': 'vim', 'spec-vcs-tag': '', }) - - help = dict(GbpOptionParser.help) - help.update( + default_helps = dict(GbpConfig.default_helps) + default_helps.update( { 'tmp-dir': - "Base directory under which temporary directories are " - "created, default is '%(tmp-dir)s'", + "Base directory under which temporary directories are created", 'vendor': - "Distribution vendor name, default is '%(vendor)s'", + "Distribution vendor name", 'packaging-branch': "Branch the packaging is being maintained on, rpm counterpart " - "of the 'debian-branch' option, default is " - "'%(packaging-branch)s'", + "of the 'debian-branch' option", 'packaging-dir': - "Subdir for RPM packaging files, default is " - "'%(packaging-dir)s'", + "Subdir for RPM packaging files", 'packaging-tag': "Format string for packaging tags, RPM counterpart of the " - "'debian-tag' option, default is '%(packaging-tag)s'", + "'debian-tag' option", 'packaging-tag-msg': - "Format string for packaging tag messages, " - "default is '%(packaging-tag-msg)s'", + "Format string for packaging tag messages", 'spec-file': "Spec file to use, causes the packaging-dir option to be " - "ignored, default is '%(spec-file)s'", + "ignored", 'export-sourcedir': - "Subdir (under EXPORT_DIR) where packaging sources (other than " - "the spec file) are exported, default is " - "'%(export-sourcedir)s'", + "Subdir (under EXPORT_DIR) where packaging sources (other " + "than the spec file) are exported", 'export-specdir': - "Subdir (under EXPORT_DIR) where package spec file is " - "exported default is '%(export-specdir)s'", + "Subdir (under EXPORT_DIR) where package spec file is exported", 'mock': - "Invoke mock for building using gbp-builder-mock, " - "default is '%(mock)s'", + "Invoke mock for building using gbp-builder-mock", 'dist': - "Build for this distribution when using mock. E.g.: epel-6, " - "default is '%(dist)s'", + "Build for this distribution when using mock. E.g.: epel-6", 'arch': - "Build for this architecture when using mock, " - "default is '%(arch)s'", + "Build for this architecture when using mock", 'mock-root': - "The mock root (-r) name for building with mock: -, " - "default is '%(mock-root)s'", + "The mock root (-r) name for building with mock: -", 'mock-options': - "Options to pass to mock, " - "default is '%(mock-options)s'", + "Options to pass to mock", 'native': - "Treat this package as native, default is '%(native)s'", + "Treat this package as native", 'changelog-file': - "Changelog file to be used, default is '%(changelog-file)s'", + "Changelog file to be used", 'changelog-revision': "Format string for the revision field in the changelog header. " "If empty or not defined the default from packaging policy is " @@ -858,11 +810,10 @@ class GbpOptionParserRpm(GbpOptionParser): 'editor-cmd': "Editor command to use", 'git-author': - "Use name and email from git-config for the changelog header, " - "default is '%(git-author)s'", + "Use name and email from git-config for the changelog header", 'spec-vcs-tag': "Set/update the 'VCS:' tag in the spec file, empty value " - "removes the tag entirely, default is '%(spec-vcs-tag)s'", + "removes the tag entirely", }) def _warn_old_gbp_conf(self, gbp_conf): @@ -870,4 +821,15 @@ def _warn_old_gbp_conf(self, gbp_conf): # warn there yet pass + +class GbpConfArgParserRpm(GbpConfArgParser): + """Joint config and arg parser for the RPM tools""" + + def __init__(self, wrapped_instance, prefix, config=None, + conf_file_args=None): + if not config: + config = GbpConfigRpm(wrapped_instance.command) + super(GbpConfArgParserRpm, self).__init__(wrapped_instance, prefix, + config, conf_file_args) + # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index b055f8d5..e2e4e163 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -28,7 +28,7 @@ from gbp.command_wrappers import (Command, RunAtCommand, CommandExecFailed, RemoveTree) -from gbp.config import (GbpOptionParserDebian, GbpOptionGroup) +from gbp.config import GbpConfArgParserDebian from gbp.deb.git import (GitRepositoryError, DebianGitRepository) from gbp.deb.source import DebianSource, DebianSourceError, FileVfs from gbp.deb.format import DebianSourceFormat @@ -336,101 +336,88 @@ def check_branch(repo, options): def build_parser(name, prefix=None): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), prefix=prefix) + parser = GbpConfArgParserDebian.create_parser(prefix=prefix, prog=name) except GbpError as err: gbp.log.err(err) return None - tag_group = GbpOptionGroup(parser, - "tag options", - "options related to git tag creation") - orig_group = GbpOptionGroup(parser, - "orig tarball options", - "options related to the creation of the orig tarball") - branch_group = GbpOptionGroup(parser, - "branch options", - "branch layout options") - cmd_group = GbpOptionGroup(parser, - "external command options", - "how and when to invoke external commands and hooks") - export_group = GbpOptionGroup(parser, - "export build-tree options", - "alternative build tree related options") - for group in [tag_group, orig_group, branch_group, cmd_group, export_group]: - parser.add_option_group(group) - - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_config_file_option(option_name="notify", dest="notify", 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="don't build, only tag and run the posttag hook") - tag_group.add_option("--git-retag", action="store_true", dest="retag", default=False, - help="don't fail if the tag already exists") - tag_group.add_boolean_config_file_option(option_name="sign-tags", dest="sign_tags") - tag_group.add_config_file_option(option_name="keyid", dest="keyid") - tag_group.add_config_file_option(option_name="debian-tag", dest="debian_tag") - tag_group.add_config_file_option(option_name="debian-tag-msg", dest="debian_tag_msg") - tag_group.add_config_file_option(option_name="upstream-tag", dest="upstream_tag") - orig_group.add_config_file_option(option_name="upstream-tree", dest="upstream_tree") - orig_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar") - orig_group.add_boolean_config_file_option(option_name="pristine-tar-commit", - dest="pristine_tar_commit") - orig_group.add_config_file_option(option_name="force-create", dest="force_create", - help="force creation of orig tarball", action="store_true") - orig_group.add_config_file_option(option_name="no-create-orig", dest="no_create_orig", - help="don't create orig tarball", action="store_true") - orig_group.add_config_file_option(option_name="tarball-dir", dest="tarball_dir", type="path", - help="location to look for external tarballs") - orig_group.add_config_file_option(option_name="compression", dest="comp_type", - help="Compression type, default is '%(compression)s'") - orig_group.add_config_file_option(option_name="compression-level", dest="comp_level", - help="Compression level, default is '%(compression-level)s'") - orig_group.add_config_file_option("component", action="append", metavar='COMPONENT', - dest="components") - branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") - branch_group.add_config_file_option(option_name="debian-branch", dest="debian_branch") - branch_group.add_boolean_config_file_option(option_name="ignore-branch", dest="ignore_branch") - branch_group.add_boolean_config_file_option(option_name="submodules", dest="with_submodules") - cmd_group.add_config_file_option(option_name="builder", dest="builder", - help="command to build the Debian package, " - "default is '%(builder)s'") - cmd_group.add_config_file_option(option_name="cleaner", dest="cleaner", - help="command to clean the working copy, " - "default is '%(cleaner)s'") - cmd_group.add_config_file_option(option_name="prebuild", dest="prebuild", - help="hook to run before a build, " - "default is '%(prebuild)s'") - cmd_group.add_config_file_option(option_name="postexport", dest="postexport", - help="hook to run after exporting the source tree, " - "default is '%(postexport)s'") - cmd_group.add_config_file_option(option_name="postbuild", dest="postbuild", - help="hook run after a successful build, " - "default is '%(postbuild)s'") - cmd_group.add_config_file_option(option_name="posttag", dest="posttag", - help="hook run after a successful tag operation, " - "default is '%(posttag)s'") - cmd_group.add_boolean_config_file_option(option_name="pbuilder", dest="use_pbuilder") - cmd_group.add_boolean_config_file_option(option_name="qemubuilder", dest="use_qemubuilder") - cmd_group.add_config_file_option(option_name="dist", dest="pbuilder_dist") - cmd_group.add_config_file_option(option_name="arch", dest="pbuilder_arch") - cmd_group.add_boolean_config_file_option(option_name="pbuilder-autoconf", - dest="pbuilder_autoconf") - cmd_group.add_config_file_option(option_name="pbuilder-options", dest="pbuilder_options") - cmd_group.add_boolean_config_file_option(option_name="hooks", dest="hooks") - export_group.add_config_file_option(option_name="export-dir", dest="export_dir", type="path", - help="before building the package export the source into EXPORT_DIR, " - "default is '%(export-dir)s'") - export_group.add_config_file_option("export", dest="export", - help="export treeish object TREEISH, " - "default is '%(export)s'", metavar="TREEISH") - export_group.add_boolean_config_file_option(option_name="purge", dest="purge") - export_group.add_boolean_config_file_option(option_name="overlay", dest="overlay") + tag_group = parser.add_argument_group("tag options", + "options related to git tag creation") + orig_group = parser.add_argument_group("orig tarball options", + "options related to the creation of the orig tarball") + branch_group = parser.add_argument_group("branch options", + "branch layout options") + cmd_group = parser.add_argument_group("external command options", + "how and when to invoke external commands and hooks") + export_group = parser.add_argument_group("export build-tree options", + "alternative build tree related options") + + parser.add_bool_conf_file_arg("--ignore-new", dest="ignore_new") + parser.add_arg("--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_conf_file_arg("--notify", dest="notify", type='tristate') + tag_group.add_arg("--tag", action="store_true", dest="tag", default=False, + help="create a tag after a successful build") + tag_group.add_arg("--tag-only", action="store_true", dest="tag_only", default=False, + help="don't build, only tag and run the posttag hook") + tag_group.add_arg("--retag", action="store_true", dest="retag", default=False, + help="don't fail if the tag already exists") + tag_group.add_bool_conf_file_arg("--sign-tags", dest="sign_tags") + tag_group.add_conf_file_arg("--keyid", dest="keyid") + tag_group.add_conf_file_arg("--debian-tag", dest="debian_tag") + tag_group.add_conf_file_arg("--debian-tag-msg", dest="debian_tag_msg") + tag_group.add_conf_file_arg("--upstream-tag", dest="upstream_tag") + orig_group.add_conf_file_arg("--upstream-tree", dest="upstream_tree") + orig_group.add_bool_conf_file_arg("--pristine-tar", dest="pristine_tar") + orig_group.add_bool_conf_file_arg("--pristine-tar-commit", + dest="pristine_tar_commit") + orig_group.add_conf_file_arg("--force-create", dest="force_create", + help="force creation of orig tarball", action="store_true") + orig_group.add_conf_file_arg("--no-create-orig", dest="no_create_orig", + help="don't create orig tarball", action="store_true") + orig_group.add_conf_file_arg("--tarball-dir", dest="tarball_dir", type="path", + help="location to look for external tarballs") + orig_group.add_conf_file_arg("--compression", dest="comp_type", + help="Compression type") + orig_group.add_conf_file_arg("--compression-level", dest="comp_level", + help="Compression level") + orig_group.add_conf_file_arg("--component", action="append", metavar='COMPONENT', + dest="components") + branch_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") + branch_group.add_conf_file_arg("--debian-branch", dest="debian_branch") + branch_group.add_bool_conf_file_arg("--ignore-branch", dest="ignore_branch") + branch_group.add_bool_conf_file_arg("--submodules", dest="with_submodules") + cmd_group.add_conf_file_arg("--builder", dest="builder", + help="command to build the Debian package") + cmd_group.add_conf_file_arg("--cleaner", dest="cleaner", + help="command to clean the working copy") + cmd_group.add_conf_file_arg("--prebuild", dest="prebuild", + help="hook to run before a build") + cmd_group.add_conf_file_arg("--postexport", dest="postexport", + help="hook to run after exporting the source tree") + cmd_group.add_conf_file_arg("--postbuild", dest="postbuild", + help="hook run after a successful build") + cmd_group.add_conf_file_arg("--posttag", dest="posttag", + help="hook run after a successful tag operation") + cmd_group.add_bool_conf_file_arg("--pbuilder", dest="use_pbuilder") + cmd_group.add_bool_conf_file_arg("--qemubuilder", dest="use_qemubuilder") + cmd_group.add_conf_file_arg("--dist", dest="pbuilder_dist") + cmd_group.add_conf_file_arg("--arch", dest="pbuilder_arch") + cmd_group.add_bool_conf_file_arg("--pbuilder-autoconf", + dest="pbuilder_autoconf") + cmd_group.add_conf_file_arg("--pbuilder-options", dest="pbuilder_options") + cmd_group.add_bool_conf_file_arg("--hooks", dest="hooks") + export_group.add_conf_file_arg("--export-dir", dest="export_dir", type="path", + help="before building the package export " + "the source into EXPORT_DIR") + export_group.add_conf_file_arg("--export", dest="export", + help="export treeish object TREEISH", + metavar="TREEISH") + export_group.add_bool_conf_file_arg("--purge", dest="purge") + export_group.add_bool_conf_file_arg("--overlay", dest="overlay") return parser @@ -445,8 +432,8 @@ def parse_args(argv, prefix): parser = build_parser(argv[0], prefix=prefix) if not parser: - return None, None, None - options, args = parser.parse_args(args) + return None, None + options = parser.parse_args(args) gbp.log.setup(options.color, options.verbose, options.color_scheme) if not options.hooks: @@ -455,18 +442,18 @@ def parse_args(argv, prefix): if not options.tag and not options.tag_only: gbp.log.err("'--%sretag' needs either '--%stag' or '--%stag-only'" % (prefix, prefix, prefix)) - return None, None, None + return None, None if options.overlay and not options.export_dir: gbp.log.err("Overlay must be used with --git-export-dir") - return None, None, None + return None, None if options.components and options.pristine_tar_commit: gbp.log.warn("Components specified, pristine-tar-commit not yet supported - disabling it.") options.pristine_tar_commit = False mangle_export_wc_opts(options) - return options, args, dpkg_args + return options, dpkg_args def main(argv): @@ -475,7 +462,7 @@ def main(argv): source = None hook_env = {} - options, gbp_args, dpkg_args = parse_args(argv, prefix) + options, dpkg_args = parse_args(argv, prefix) if not options: return ExitCodes.parse_error diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index 16b5eb56..06fcd84d 100644 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -27,7 +27,7 @@ import gbp.notifications import gbp.rpm as rpm from gbp.command_wrappers import Command, RunAtCommand, CommandExecFailed -from gbp.config import GbpOptionParserRpm, GbpOptionGroup +from gbp.config import GbpConfArgParserRpm from gbp.errors import GbpError from gbp.format import format_str from gbp.pkg import Compressor @@ -305,132 +305,118 @@ def disable_hooks(options): def build_parser(name, prefix=None, git_treeish=None): """Construct config/option parser""" try: - parser = GbpOptionParserRpm(command=os.path.basename(name), - prefix=prefix) + parser = GbpConfArgParserRpm.create_parser(prefix=prefix, prog=name) except GbpError as err: gbp.log.err(err) return None - tag_group = GbpOptionGroup(parser, "tag options", - "options related to git tag creation") - branch_group = GbpOptionGroup(parser, "branch options", - "branch layout options") - cmd_group = GbpOptionGroup(parser, "external command options", - "how and when to invoke external commands and hooks") - orig_group = GbpOptionGroup(parser, "orig tarball options", - "options related to the creation of the orig tarball") - export_group = GbpOptionGroup(parser, "export build-tree options", - "alternative build tree related options") - parser.add_option_group(tag_group) - parser.add_option_group(orig_group) - parser.add_option_group(branch_group) - parser.add_option_group(cmd_group) - parser.add_option_group(export_group) - - 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="tmp-dir", dest="tmp_dir") - parser.add_config_file_option(option_name="color", dest="color", - type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_config_file_option(option_name="notify", dest="notify", - type='tristate') - parser.add_config_file_option(option_name="vendor", action="store", - dest="vendor") - parser.add_config_file_option(option_name="native", dest="native", - 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="don't build, only tag and run the posttag hook") - tag_group.add_option("--git-retag", action="store_true", dest="retag", - default=False, help="don't fail if the tag already exists") - tag_group.add_boolean_config_file_option(option_name="sign-tags", - dest="sign_tags") - tag_group.add_config_file_option(option_name="keyid", dest="keyid") - tag_group.add_config_file_option(option_name="packaging-tag", - dest="packaging_tag") - tag_group.add_config_file_option(option_name="packaging-tag-msg", - dest="packaging_tag_msg") - tag_group.add_config_file_option(option_name="upstream-tag", - dest="upstream_tag") - orig_group.add_config_file_option(option_name="upstream-tree", - dest="upstream_tree") - orig_group.add_boolean_config_file_option(option_name="pristine-tar", - dest="pristine_tar") - orig_group.add_boolean_config_file_option(option_name="pristine-tar-commit", - dest="pristine_tar_commit") - orig_group.add_config_file_option(option_name="force-create", - dest="force_create", action="store_true", - help="force creation of upstream source tarball") - orig_group.add_config_file_option(option_name="no-create-orig", - dest="no_create_orig", action="store_true", - help="don't create upstream source tarball") - orig_group.add_config_file_option(option_name="tarball-dir", - dest="tarball_dir", type="path", - help="location to look for external tarballs") - orig_group.add_config_file_option(option_name="compression-level", - dest="comp_level", - help="Compression level, default is " - "'%(compression-level)s'") - branch_group.add_config_file_option(option_name="upstream-branch", - dest="upstream_branch") - branch_group.add_config_file_option(option_name="packaging-branch", - dest="packaging_branch") - branch_group.add_boolean_config_file_option(option_name="ignore-branch", - dest="ignore_branch") - branch_group.add_boolean_config_file_option(option_name="submodules", - dest="with_submodules") - cmd_group.add_config_file_option(option_name="builder", dest="builder", - help="command to build the package, default is " - "'%(builder)s'") - cmd_group.add_config_file_option(option_name="cleaner", dest="cleaner", - help="command to clean the working copy, default is " - "'%(cleaner)s'") - cmd_group.add_config_file_option(option_name="prebuild", dest="prebuild", - help="command to run before a build, default is " - "'%(prebuild)s'") - cmd_group.add_config_file_option(option_name="postexport", - dest="postexport", - help="command to run after exporting the source tree, " - "default is '%(postexport)s'") - cmd_group.add_config_file_option(option_name="postbuild", dest="postbuild", - help="hook run after a successful build, default is " - "'%(postbuild)s'") - cmd_group.add_config_file_option(option_name="posttag", dest="posttag", - help="hook run after a successful tag operation, default " - "is '%(posttag)s'") - cmd_group.add_boolean_config_file_option(option_name="mock", dest="use_mock") - cmd_group.add_config_file_option(option_name="dist", dest="mock_dist") - cmd_group.add_config_file_option(option_name="arch", dest="mock_arch") - cmd_group.add_config_file_option(option_name="mock-root", dest="mock_root") - cmd_group.add_config_file_option(option_name="mock-options", dest="mock_options") - cmd_group.add_boolean_config_file_option(option_name="hooks", dest="hooks") - export_group.add_option("--git-no-build", action="store_true", - dest="no_build", - help="Don't run builder or the associated hooks") - export_group.add_config_file_option(option_name="export-dir", - dest="export_dir", type="path", - help="Build topdir, also export the sources under " - "EXPORT_DIR, default is '%(export-dir)s'") - export_group.add_config_file_option(option_name="export-specdir", - dest="export_specdir", type="path") - export_group.add_config_file_option(option_name="export-sourcedir", - dest="export_sourcedir", type="path") - export_group.add_config_file_option("export", dest="export", - metavar="TREEISH", - help="export treeish object TREEISH, default is " - "'%(export)s'") - export_group.add_config_file_option(option_name="packaging-dir", - dest="packaging_dir") - export_group.add_config_file_option(option_name="spec-file", - dest="spec_file") - export_group.add_config_file_option("spec-vcs-tag", dest="spec_vcs_tag") + tag_group = parser.add_argument_group("tag options", + "options related to git tag creation") + branch_group = parser.add_argument_group("branch options", + "branch layout options") + cmd_group = parser.add_argument_group("external command options", + "how and when to invoke external commands and hooks") + orig_group = parser.add_argument_group("orig tarball options", + "options related to the creation of the orig tarball") + export_group = parser.add_argument_group("export build-tree options", + "alternative build tree related options") + + parser.add_bool_conf_file_arg("--ignore-new", + dest="ignore_new") + parser.add_arg("--verbose", action="store_true", dest="verbose", + default=False, help="verbose command execution") + parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") + parser.add_conf_file_arg("--color", dest="color", + type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_conf_file_arg("--notify", dest="notify", + type='tristate') + parser.add_conf_file_arg("--vendor", action="store", + dest="vendor") + parser.add_conf_file_arg("--native", dest="native", + type='tristate') + tag_group.add_arg("--tag", action="store_true", dest="tag", + default=False, + help="create a tag after a successful build") + tag_group.add_arg("--tag-only", action="store_true", dest="tag_only", + default=False, + help="don't build, only tag and run the posttag hook") + tag_group.add_arg("--retag", action="store_true", dest="retag", + default=False, help="don't fail if the tag already exists") + tag_group.add_bool_conf_file_arg("--sign-tags", + dest="sign_tags") + tag_group.add_conf_file_arg("--keyid", dest="keyid") + tag_group.add_conf_file_arg("--packaging-tag", + dest="packaging_tag") + tag_group.add_conf_file_arg("--packaging-tag-msg", + dest="packaging_tag_msg") + tag_group.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + orig_group.add_conf_file_arg("--upstream-tree", + dest="upstream_tree") + orig_group.add_bool_conf_file_arg("--pristine-tar", + dest="pristine_tar") + orig_group.add_bool_conf_file_arg("--pristine-tar-commit", + dest="pristine_tar_commit") + orig_group.add_conf_file_arg("--force-create", + dest="force_create", action="store_true", + help="force creation of upstream source tarball") + orig_group.add_conf_file_arg("--no-create-orig", + dest="no_create_orig", action="store_true", + help="don't create upstream source tarball") + orig_group.add_conf_file_arg("--tarball-dir", + dest="tarball_dir", type="path", + help="location to look for external tarballs") + orig_group.add_conf_file_arg("--compression-level", + dest="comp_level", + help="Compression level") + branch_group.add_conf_file_arg("--upstream-branch", + dest="upstream_branch") + branch_group.add_conf_file_arg("--packaging-branch", + dest="packaging_branch") + branch_group.add_bool_conf_file_arg("--ignore-branch", + dest="ignore_branch") + branch_group.add_bool_conf_file_arg("--submodules", + dest="with_submodules") + cmd_group.add_conf_file_arg("--builder", dest="builder", + help="command to build the package") + cmd_group.add_conf_file_arg("--cleaner", dest="cleaner", + help="command to clean the working copy") + cmd_group.add_conf_file_arg("--prebuild", dest="prebuild", + help="command to run before a build") + cmd_group.add_conf_file_arg("--postexport", + dest="postexport", + help="command to run after exporting the source tree") + cmd_group.add_conf_file_arg("--postbuild", dest="postbuild", + help="hook run after a successful build") + cmd_group.add_conf_file_arg("--posttag", dest="posttag", + help="hook run after a successful tag operation") + cmd_group.add_bool_conf_file_arg("--mock", dest="use_mock") + cmd_group.add_conf_file_arg("--dist", dest="mock_dist") + cmd_group.add_conf_file_arg("--arch", dest="mock_arch") + cmd_group.add_conf_file_arg("--mock-root", dest="mock_root") + cmd_group.add_conf_file_arg("--mock-options", dest="mock_options") + cmd_group.add_bool_conf_file_arg("--hooks", dest="hooks") + export_group.add_arg("--no-build", action="store_true", + dest="no_build", + help="Don't run builder or the associated hooks") + export_group.add_conf_file_arg("--export-dir", + dest="export_dir", type="path", + help="Build topdir, also export the sources under " + "EXPORT_DIR") + export_group.add_conf_file_arg("--export-specdir", + dest="export_specdir", type="path") + export_group.add_conf_file_arg("--export-sourcedir", + dest="export_sourcedir", type="path") + export_group.add_conf_file_arg("--export", dest="export", + metavar="TREEISH", + help="export treeish object TREEISH") + export_group.add_conf_file_arg("--packaging-dir", + dest="packaging_dir") + export_group.add_conf_file_arg("--spec-file", + dest="spec_file") + export_group.add_conf_file_arg("--spec-vcs-tag", dest="spec_vcs_tag") return parser @@ -444,10 +430,11 @@ def parse_args(argv, prefix, git_treeish=None): if arg in builder_args: args.append(arg) - parser = build_parser(argv[0], prefix=prefix, git_treeish=git_treeish) + parser = build_parser(os.path.basename(argv[0]), prefix=prefix, + git_treeish=git_treeish) if not parser: - return None, None, None - options, args = parser.parse_args(args) + return None, None + options = parser.parse_args(args) gbp.log.setup(options.color, options.verbose, options.color_scheme) if not options.hooks: @@ -456,9 +443,9 @@ def parse_args(argv, prefix, git_treeish=None): if not options.tag and not options.tag_only: gbp.log.err("'--%sretag' needs either '--%stag' or '--%stag-only'" % (prefix, prefix, prefix)) - return None, None, None + return None, None - return options, args, builder_args + return options, builder_args def main(argv): @@ -467,7 +454,7 @@ def main(argv): prefix = "git-" spec = None - options, gbp_args, builder_args = parse_args(argv, prefix) + options, builder_args = parse_args(argv, prefix) if not options: return ExitCodes.parse_error @@ -486,7 +473,7 @@ def main(argv): return 1 # Re-parse config options with using the per-tree config file(s) from the # exported tree-ish - options, gbp_args, builder_args = parse_args(argv, prefix, tree) + options, builder_args = parse_args(argv, prefix, tree) branch = get_current_branch(repo) diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py index edc991ed..287129e4 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -22,7 +22,7 @@ import re import sys import os -from gbp.config import (GbpOptionParser, GbpOptionGroup) +from gbp.config import GbpConfArgParser from gbp.deb.git import DebianGitRepository from gbp.git import (GitRepository, GitRepositoryError) from gbp.errors import GbpError @@ -100,69 +100,66 @@ def repo_to_url(repo): def build_parser(name): try: - parser = GbpOptionParser(command=os.path.basename(name), prefix='', - usage='%prog [options] repository - clone a remote repository') + parser = GbpConfArgParser.create_parser(prog=name, + description='clone a remote repository') except GbpError as err: gbp.log.err(err) return None - branch_group = GbpOptionGroup(parser, "branch options", "branch tracking and layout options") - cmd_group = GbpOptionGroup(parser, "external command options", "how and when to invoke hooks") - parser.add_option_group(branch_group) - parser.add_option_group(cmd_group) - - branch_group.add_option("--all", action="store_true", dest="all", default=False, - help="track all branches, not only debian and upstream") - branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") - branch_group.add_config_file_option(option_name="debian-branch", dest="debian_branch") - branch_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar") - branch_group.add_option("--depth", action="store", dest="depth", default=0, - help="git history depth (for creating shallow clones)") - branch_group.add_option("--reference", action="store", dest="reference", default=None, - help="git reference repository (use local copies where possible)") - cmd_group.add_config_file_option(option_name="postclone", dest="postclone", - help="hook to run after cloning the source tree, " - "default is '%(postclone)s'") - cmd_group.add_boolean_config_file_option(option_name="hooks", dest="hooks") - - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_config_file_option(option_name="repo-user", dest="repo_user", - choices=['DEBIAN', 'GIT']) - parser.add_config_file_option(option_name="repo-email", dest="repo_email", - choices=['DEBIAN', 'GIT']) + branch_group = parser.add_argument_group("branch options", "branch tracking and layout options") + cmd_group = parser.add_argument_group("external command options", "how and when to invoke hooks") + + branch_group.add_arg("--all", action="store_true", dest="all", default=False, + help="track all branches, not only debian and upstream") + branch_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") + branch_group.add_conf_file_arg("--debian-branch", dest="debian_branch") + branch_group.add_bool_conf_file_arg("--pristine-tar", dest="pristine_tar") + branch_group.add_arg("--depth", action="store", dest="depth", default=0, + help="git history depth (for creating shallow clones)") + branch_group.add_arg("--reference", action="store", dest="reference", default=None, + help="git reference repository (use local copies where possible)") + cmd_group.add_conf_file_arg("--postclone", dest="postclone", + help="hook to run after cloning the source tree") + cmd_group.add_bool_conf_file_arg("--hooks", dest="hooks") + + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", dest="color_scheme") + parser.add_conf_file_arg("--repo-user", dest="repo_user", + choices=['DEBIAN', 'GIT']) + parser.add_conf_file_arg("--repo-email", dest="repo_email", + choices=['DEBIAN', 'GIT']) + parser.add_argument("repository", metavar="REPOSITORY", + help="repository to clone") + parser.add_argument("directory", metavar="DIRECTORY", nargs="?", + help="local directory to clone into") return parser def parse_args(argv): parser = build_parser(argv[0]) if not parser: - return None, None + return None - (options, args) = parser.parse_args(argv) + options = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose, options.color_scheme) - return (options, args) + return options def main(argv): retval = 0 - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error - if len(args) < 2: - gbp.log.err("Need a repository to clone.") + source = repo_to_url(options.repository) + if not source: return 1 - else: - source = repo_to_url(args[1]) - if not source: - return 1 - clone_to, auto_name = (os.path.curdir, True) if len(args) < 3 else (args[2], False) + clone_to, auto_name = (os.path.curdir, True) if not options.directory \ + else (options.directory, False) try: GitRepository(clone_to) gbp.log.err("Can't run inside a git repository.") @@ -179,7 +176,7 @@ def main(argv): # Reparse the config files of the cloned repository so we pick up the # branch information from there but don't overwrite hooks: postclone = options.postclone - (options, args) = parse_args(argv) + options = parse_args(argv) # Track all branches: if options.all: diff --git a/gbp/scripts/config.py b/gbp/scripts/config.py index e988748c..95ff92c9 100755 --- a/gbp/scripts/config.py +++ b/gbp/scripts/config.py @@ -18,8 +18,7 @@ """Query and display config file values""" import sys -import os -from gbp.config import GbpOptionParser +from gbp.config import GbpConfArgParser from gbp.errors import GbpError from gbp.scripts.supercommand import import_command from gbp.scripts.common import ExitCodes @@ -27,26 +26,28 @@ def build_parser(name): + description = 'display configuration settings' try: - parser = GbpOptionParser(command=os.path.basename(name), prefix='', - usage='%prog [options] command[.optionname] - display configuration settings') + parser = GbpConfArgParser.create_parser(prog=name, + description=description) except GbpError as err: gbp.log.err(err) return None - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") + parser.add_arg("-v", "--verbose", action="store_true", + help="verbose command execution") + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + parser.add_argument("query", metavar="QUERY", + help="command[.optionname] to show") return parser def parse_args(argv): parser = build_parser(argv[0]) if not parser: - return None, None - return parser.parse_args(argv) + return None + return parser.parse_args(argv[1:]) def build_cmd_parser(section): @@ -61,25 +62,24 @@ def build_cmd_parser(section): except (AttributeError, ImportError): # Use the default parser for section that don't # map to a command - parser = GbpOptionParser(section) - parser.parse_config_files() + parser = GbpConfArgParser.create_parser(prog=section) return parser def print_single_option(parser, option, printer): - value = parser.get_config_file_value(option) - if value is not None: + try: + value = parser.get_conf_file_value(option) printer("%s" % value) - else: + return 0 + except KeyError: return 2 - return 0 def print_all_options(parser, printer): - if not parser.valid_options: + if not parser.conf_file_args: return 2 - for opt in parser.valid_options: - value = parser.get_config_file_value(opt) + for opt in parser.conf_file_args: + value = parser.get_conf_file_value(opt) printer("%s.%s=%s" % (parser.command, opt, value)) return 0 @@ -114,26 +114,14 @@ def value_printer(output): def main(argv): - retval = 1 - - (options, args) = parse_args(argv) + options = parse_args(argv) if options is None: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) - if not args: - gbp.log.err("No command given") - return 2 - elif len(args) != 2: - gbp.log.err("Can only take a command or command.optionname, check --help") - return 2 - else: - query = args[1] - - retval = print_cmd_values(query, value_printer) - return retval + return print_cmd_values(options.query, value_printer) if __name__ == '__main__': diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py index 6c1ff7a0..7a41eff3 100644 --- a/gbp/scripts/create_remote_repo.py +++ b/gbp/scripts/create_remote_repo.py @@ -25,11 +25,12 @@ import tty import termios import re +from argparse import ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter import configparser from gbp.deb.changelog import ChangeLog, NoChangeLogError from gbp.command_wrappers import (CommandExecFailed, GitCommand) -from gbp.config import (GbpOptionParserDebian, GbpOptionGroup) +from gbp.config import GbpConfArgParserDebian, GbpConfig from gbp.errors import GbpError from gbp.git import GitRepositoryError from gbp.deb.git import DebianGitRepository @@ -202,8 +203,13 @@ def push_branches(remote, branches): gitPush([remote['url'], '--tags']) -def usage_msg(): - return """%prog [options] - create a remote git repository +class GbpHelpFormatter(RawDescriptionHelpFormatter, + ArgumentDefaultsHelpFormatter): + pass + + +def descr_msg(): + return """create a remote git repository Actions: create create the repository. This is the default when no action is given. @@ -212,47 +218,51 @@ def usage_msg(): def build_parser(name, sections=[]): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', - usage=usage_msg(), - sections=sections) + config = GbpConfig(name, extra_sections=sections) except (GbpError, configparser.NoSectionError) as err: gbp.log.err(err) return None - branch_group = GbpOptionGroup(parser, - "branch options", - "branch layout and tracking options") - branch_group.add_config_file_option(option_name="remote-url-pattern", - dest="remote_url") - parser.add_option_group(branch_group) - branch_group.add_config_file_option(option_name="upstream-branch", - dest="upstream_branch") - branch_group.add_config_file_option(option_name="debian-branch", - dest="debian_branch") - branch_group.add_boolean_config_file_option(option_name="pristine-tar", - dest="pristine_tar") - branch_group.add_boolean_config_file_option(option_name="track", - dest='track') - branch_group.add_boolean_config_file_option(option_name="bare", - dest='bare') - 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", - type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_option("--remote-name", - dest="name", - default="origin", - help="The name of the remote, default is 'origin'") - parser.add_config_file_option(option_name="template-dir", - dest="template_dir") - parser.add_config_file_option(option_name="remote-config", - dest="remote_config") + parser = GbpConfArgParserDebian.create_parser(prog=name, + description=descr_msg(), + config=config, + formatter_class=GbpHelpFormatter) + + branch_group = parser.add_argument_group("branch options", + "branch layout and tracking options") + branch_group.add_conf_file_arg("--remote-url-pattern", + dest="remote_url") + branch_group.add_conf_file_arg("--upstream-branch", + dest="upstream_branch") + branch_group.add_conf_file_arg("--debian-branch", + dest="debian_branch") + branch_group.add_bool_conf_file_arg("--pristine-tar", + dest="pristine_tar") + branch_group.add_bool_conf_file_arg("--track", + dest='track') + branch_group.add_bool_conf_file_arg("--bare", + dest='bare') + parser.add_arg("-v", "--verbose", + action="store_true", + dest="verbose", + default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", + dest="color", + type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_arg("--remote-name", + dest="name", + default="origin", + help="The name of the remote, default is 'origin'") + parser.add_conf_file_arg("--template-dir", + dest="template_dir") + parser.add_conf_file_arg("--remote-config", + dest="remote_config") + parser.add_argument("action", metavar="ACTION", nargs="?", + default="create", choices=('create', 'list'), + help="action to take") return parser @@ -271,11 +281,11 @@ def parse_args(argv): sections = ['remote-config %s' % arg.split('=', 1)[1]] break - parser = build_parser(argv[0], sections) + parser = build_parser(os.path.basename(argv[0]), sections) if not parser: - return None, None, None + return None, None - return list(parser.parse_args(argv)) + [parser.config_file_sections] + return parser.parse_args(argv[1:]), parser.config.config_file_sections def do_create(options): @@ -378,25 +388,18 @@ def do_list(sections): def main(argv): retval = 1 - options, args, sections = parse_args(argv) + options, sections = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) - if len(args) == 1: - args.append('create') # the default - elif len(args) > 2: - gbp.log.err("Only one action allowed") - return 1 - - action = args[1] - if action == 'create': + if options.action == 'create': retval = do_create(options) - elif action == 'list': + elif options.action == 'list': retval = do_list(sections) else: - gbp.log.err("Unknown action '%s'" % action) + gbp.log.err("Unknown action '%s'" % options.action) return retval diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index 6297d2d7..a6876965 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -24,7 +24,7 @@ import gbp.command_wrappers as gbpc import gbp.dch as dch import gbp.log -from gbp.config import GbpOptionParserDebian, GbpOptionGroup +from gbp.config import GbpConfArgParserDebian from gbp.errors import GbpError from gbp.deb import compare_versions from gbp.deb.source import DebianSource, DebianSourceError @@ -327,119 +327,110 @@ def maybe_create_changelog(repo, source, options): def build_parser(name): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), - usage='%prog [options] paths') + parser = GbpConfArgParserDebian.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - range_group = GbpOptionGroup(parser, "commit range options", - "which commits to add to the changelog") - version_group = GbpOptionGroup(parser, "release & version number options", - "what version number and release to use") - commit_group = GbpOptionGroup(parser, "commit message formatting", - "howto format the changelog entries") - naming_group = GbpOptionGroup(parser, "branch and tag naming", - "branch names and tag formats") - custom_group = GbpOptionGroup(parser, "customization", - "options for customization") - parser.add_option_group(range_group) - parser.add_option_group(version_group) - parser.add_option_group(commit_group) - parser.add_option_group(naming_group) - parser.add_option_group(custom_group) - - parser.add_boolean_config_file_option(option_name="ignore-branch", dest="ignore_branch") - naming_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") - naming_group.add_config_file_option(option_name="debian-branch", dest="debian_branch") - naming_group.add_config_file_option(option_name="upstream-tag", dest="upstream_tag") - naming_group.add_config_file_option(option_name="debian-tag", dest="debian_tag") - naming_group.add_config_file_option(option_name="snapshot-number", dest="snapshot_number", - help="expression to determine the next snapshot number, " - "default is '%(snapshot-number)s'") - parser.add_config_file_option(option_name="git-log", dest="git_log", - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - 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") - version_group.add_option("-R", "--release", action="store_true", dest="release", default=False, - help="mark as release") - version_group.add_option("-S", "--snapshot", action="store_true", dest="snapshot", default=False, - help="mark as snapshot build") - version_group.add_option("-D", "--distribution", dest="distribution", help="Set distribution") - version_group.add_option("--force-distribution", action="store_true", dest="force_distribution", default=False, - help="Force the provided distribution to be used, " - "even if it doesn't match the list of known distributions") - version_group.add_option("-N", "--new-version", dest="new_version", - help="use this as base for the new version number") - version_group.add_config_file_option("urgency", dest="urgency") - version_group.add_option("--bpo", dest="bpo", action="store_true", default=False, - help="Increment the Debian release number for an upload to backports, " - "and add a backport upload changelog comment.") - version_group.add_option("--nmu", dest="nmu", action="store_true", default=False, - help="Increment the Debian release number for a non-maintainer upload") - version_group.add_option("--qa", dest="qa", action="store_true", default=False, - help="Increment the Debian release number for a Debian QA Team upload, " - "and add a QA upload changelog comment.") - version_group.add_option("--team", dest="team", action="store_true", default=False, - help="Increment the Debian release number for a Debian Team upload, " - "and add a Team upload changelog comment.") - version_group.add_option("--security", dest="security", action="store_true", default=False, - help="Increment the Debian release number for a security upload and " - "add a security upload changelog comment.") - version_group.add_boolean_config_file_option(option_name="git-author", dest="use_git_author") - commit_group.add_boolean_config_file_option(option_name="meta", dest="meta") - commit_group.add_config_file_option(option_name="meta-closes", dest="meta_closes") - commit_group.add_config_file_option(option_name="meta-closes-bugnum", dest="meta_closes_bugnum") - commit_group.add_boolean_config_file_option(option_name="full", dest="full") - commit_group.add_config_file_option(option_name="id-length", dest="idlen", - help="include N digits of the commit id in the changelog entry, " - "default is '%(id-length)s'", - type="int", metavar="N") - commit_group.add_config_file_option(option_name="ignore-regex", dest="ignore_regex", - help="Ignore commit lines matching regex, " - "default is '%(ignore-regex)s'") - commit_group.add_boolean_config_file_option(option_name="multimaint", dest="multimaint") - commit_group.add_boolean_config_file_option(option_name="multimaint-merge", dest="multimaint_merge") - commit_group.add_config_file_option(option_name="spawn-editor", dest="spawn_editor") - parser.add_config_file_option(option_name="commit-msg", - dest="commit_msg") - parser.add_option("-c", "--commit", action="store_true", dest="commit", default=False, - help="commit changelog file after generating") - parser.add_config_file_option(option_name="dch-opt", - dest="dch_opts", action="append", - help="option to pass to dch verbatim, " - "can be given multiple times", - metavar="DCH_OPT") + range_group = parser.add_argument_group("commit range options", + "which commits to add to the changelog") + version_group = parser.add_argument_group("release & version number options", + "what version number and release to use") + commit_group = parser.add_argument_group("commit message formatting", + "howto format the changelog entries") + naming_group = parser.add_argument_group("branch and tag naming", + "branch names and tag formats") + custom_group = parser.add_argument_group("customization", + "options for customization") + + parser.add_bool_conf_file_arg("--ignore-branch", dest="ignore_branch") + naming_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") + naming_group.add_conf_file_arg("--debian-branch", dest="debian_branch") + naming_group.add_conf_file_arg("--upstream-tag", dest="upstream_tag") + naming_group.add_conf_file_arg("--debian-tag", dest="debian_tag") + naming_group.add_conf_file_arg("--snapshot-number", dest="snapshot_number", + help="expression to determine the next snapshot number") + parser.add_conf_file_arg("--git-log", dest="git_log", + help="options to pass to git-log") + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", dest="color_scheme") + range_group.add_arg("-s", "--since", dest="since", help="commit to start from (e.g. HEAD^^^, debian/0.4.3)") + range_group.add_arg("-a", "--auto", action="store_true", dest="auto", default=False, + help="autocomplete changelog from last snapshot or tag") + version_group.add_arg("-R", "--release", action="store_true", dest="release", default=False, + help="mark as release") + version_group.add_arg("-S", "--snapshot", action="store_true", dest="snapshot", default=False, + help="mark as snapshot build") + version_group.add_arg("-D", "--distribution", dest="distribution", help="Set distribution") + version_group.add_arg("--force-distribution", action="store_true", dest="force_distribution", default=False, + help="Force the provided distribution to be used, " + "even if it doesn't match the list of known distributions") + version_group.add_arg("-N", "--new-version", dest="new_version", + help="use this as base for the new version number") + version_group.add_conf_file_arg("--urgency", dest="urgency") + version_group.add_arg("--bpo", dest="bpo", action="store_true", default=False, + help="Increment the Debian release number for an upload to backports, " + "and add a backport upload changelog comment.") + version_group.add_arg("--nmu", dest="nmu", action="store_true", default=False, + help="Increment the Debian release number for a non-maintainer upload") + version_group.add_arg("--qa", dest="qa", action="store_true", default=False, + help="Increment the Debian release number for a Debian QA Team upload, " + "and add a QA upload changelog comment.") + version_group.add_arg("--team", dest="team", action="store_true", default=False, + help="Increment the Debian release number for a Debian Team upload, " + "and add a Team upload changelog comment.") + version_group.add_arg("--security", dest="security", action="store_true", default=False, + help="Increment the Debian release number for a security upload and " + "add a security upload changelog comment.") + version_group.add_bool_conf_file_arg("--git-author", dest="use_git_author") + commit_group.add_bool_conf_file_arg("--meta", dest="meta") + commit_group.add_conf_file_arg("--meta-closes", dest="meta_closes") + commit_group.add_conf_file_arg("--meta-closes-bugnum", dest="meta_closes_bugnum") + commit_group.add_bool_conf_file_arg("--full", dest="full") + commit_group.add_conf_file_arg("--id-length", dest="idlen", + help="include N digits of the commit id in the changelog entry", + type=int, metavar="N") + commit_group.add_conf_file_arg("--ignore-regex", dest="ignore_regex", + help="Ignore commit lines matching regex") + commit_group.add_bool_conf_file_arg("--multimaint", dest="multimaint") + commit_group.add_bool_conf_file_arg("--multimaint-merge", dest="multimaint_merge") + commit_group.add_conf_file_arg("--spawn-editor", dest="spawn_editor") + parser.add_conf_file_arg("--commit-msg", + dest="commit_msg") + parser.add_arg("-c", "--commit", action="store_true", dest="commit", default=False, + help="commit changelog file after generating") + parser.add_conf_file_arg("--dch-opt", dest="dch_opts", action="append", + help="option to pass to dch verbatim, " + "can be given multiple times", + metavar="DCH_OPT") help_msg = ('Load Python code from CUSTOMIZATION_FILE. At the moment,' ' the only useful thing the code can do is define a custom' ' format_changelog_entry() function.') - custom_group.add_config_file_option(option_name="customizations", - dest="customization_file", - help=help_msg) - custom_group.add_config_file_option(option_name="postedit", dest="postedit", - help="Hook to run after changes to the changelog file" - "have been finalized default is '%(postedit)s'") + custom_group.add_conf_file_arg("--customizations", + dest="customization_file", + help=help_msg) + custom_group.add_conf_file_arg("--postedit", dest="postedit", + help="Hook to run after changes to the changelog file" + "have been finalized") + parser.add_argument("paths", metavar="PATHS", nargs='*', + help="only look at changes to PATHS") + return parser def parse_args(argv): - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return [None] * 4 + return [None] * 3 - (options, args) = parser.parse_args(argv[1:]) + options = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose, options.color_scheme) dch_options = process_options(options, parser) editor_cmd = process_editor_option(options) - return options, args, dch_options, editor_cmd + return options, dch_options, editor_cmd def main(argv): @@ -450,7 +441,7 @@ def main(argv): version_change = {} branch = None - options, args, dch_options, editor_cmd = parse_args(argv) + options, dch_options, editor_cmd = parse_args(argv) if not options: return ExitCodes.parse_error @@ -489,9 +480,10 @@ def main(argv): gbp.log.info(msg) found_snapshot_banner = has_snapshot_banner(cp) - if args: - gbp.log.info("Only looking for changes on '%s'" % " ".join(args)) - commits = repo.get_commits(since=since, until=until, paths=args, + if options.paths: + gbp.log.info("Only looking for changes on '%s'" % + " ".join(options.paths)) + commits = repo.get_commits(since=since, until=until, paths=options.paths, options=options.git_log.split(" ")) commits.reverse() diff --git a/gbp/scripts/export_orig.py b/gbp/scripts/export_orig.py index ea6c8870..2676b37b 100755 --- a/gbp/scripts/export_orig.py +++ b/gbp/scripts/export_orig.py @@ -21,7 +21,7 @@ import sys import gbp.deb as du from gbp.command_wrappers import CommandExecFailed -from gbp.config import (GbpOptionParserDebian, GbpOptionGroup) +from gbp.config import GbpConfArgParserDebian from gbp.deb.git import (GitRepositoryError, DebianGitRepository) from gbp.deb.source import DebianSource, DebianSourceError from gbp.errors import GbpError @@ -263,63 +263,58 @@ def guess_comp_type(comp_type, source, repo, tarball_dir): def build_parser(name): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='') + parser = GbpConfArgParserDebian.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - tag_group = GbpOptionGroup(parser, - "tag options", - "options related to git tag creation") - orig_group = GbpOptionGroup(parser, - "orig tarball options", - "options related to the creation of the orig tarball") - branch_group = GbpOptionGroup(parser, - "branch options", - "branch layout options") - for group in [tag_group, orig_group, branch_group]: - parser.add_option_group(group) - - parser.add_option("--verbose", action="store_true", dest="verbose", default=False, - help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - tag_group.add_config_file_option(option_name="upstream-tag", dest="upstream_tag") - orig_group.add_config_file_option(option_name="upstream-tree", dest="upstream_tree") - orig_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar") - orig_group.add_config_file_option(option_name="force-create", dest="force_create", - help="force creation of orig tarball", action="store_true") - orig_group.add_config_file_option(option_name="tarball-dir", dest="tarball_dir", type="path", - help="location to look for external tarballs") - orig_group.add_config_file_option(option_name="compression", dest="comp_type", - help="Compression type, default is '%(compression)s'") - orig_group.add_config_file_option(option_name="compression-level", dest="comp_level", - help="Compression level, default is '%(compression-level)s'") - orig_group.add_config_file_option("component", action="append", metavar='COMPONENT', - dest="components") - branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") - branch_group.add_boolean_config_file_option(option_name="submodules", dest="with_submodules") + tag_group = parser.add_argument_group("tag options", + "options related to git tag creation") + orig_group = parser.add_argument_group("orig tarball options", + "options related to the creation of the orig tarball") + branch_group = parser.add_argument_group("branch options", + "branch layout options") + + parser.add_arg("--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + tag_group.add_conf_file_arg("--upstream-tag", dest="upstream_tag") + orig_group.add_conf_file_arg("--upstream-tree", dest="upstream_tree") + orig_group.add_bool_conf_file_arg("--pristine-tar", dest="pristine_tar") + orig_group.add_conf_file_arg("--force-create", dest="force_create", + help="force creation of orig tarball", action="store_true") + orig_group.add_conf_file_arg("--tarball-dir", dest="tarball_dir", type="path", + help="location to look for external tarballs") + orig_group.add_conf_file_arg("--compression", dest="comp_type", + help="Compression type") + orig_group.add_conf_file_arg("--compression-level", dest="comp_level", + help="Compression level") + orig_group.add_conf_file_arg("--component", action="append", metavar='COMPONENT', + dest="components") + branch_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") + branch_group.add_bool_conf_file_arg("--submodules", dest="with_submodules") return parser def parse_args(argv, prefix): - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None - options, args = parser.parse_args(argv[1:]) + return None + options = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose, options.color_scheme) - return options, args + return options def main(argv): retval = 0 source = None - options, args = parse_args(argv, '') + options = parse_args(argv, '') - if args or not options: + if not options: return ExitCodes.parse_error try: diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py index 8cd22c05..e1c12db2 100644 --- a/gbp/scripts/import_dsc.py +++ b/gbp/scripts/import_dsc.py @@ -32,8 +32,7 @@ from gbp.git import rfc822_date_to_git from gbp.git.modifier import GitModifier from gbp.git.vfs import GitVfs -from gbp.config import (GbpOptionParserDebian, GbpOptionGroup, - no_upstream_branch_msg) +from gbp.config import GbpConfArgParserDebian, no_upstream_branch_msg from gbp.errors import GbpError from gbp.scripts.common import ExitCodes from gbp.scripts.common import repo_setup @@ -309,80 +308,85 @@ def disable_pristine_tar(options, reason): def build_parser(name): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', - usage='%prog [options] /path/to/package.dsc [target]') + parser = GbpConfArgParserDebian.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - import_group = GbpOptionGroup(parser, "import options", - "pristine-tar and filtering") - tag_group = GbpOptionGroup(parser, "tag options", - "options related to git tag creation") - branch_group = GbpOptionGroup(parser, "version and branch naming options", - "version number and branch layout options") - for group in [import_group, branch_group, tag_group]: - parser.add_option_group(group) - - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - branch_group.add_config_file_option(option_name="debian-branch", - dest="debian_branch") - branch_group.add_config_file_option(option_name="upstream-branch", - dest="upstream_branch") - branch_group.add_boolean_config_file_option(option_name="create-missing-branches", - dest="create_missing_branches") - - tag_group.add_boolean_config_file_option(option_name="sign-tags", - dest="sign_tags") - tag_group.add_config_file_option(option_name="keyid", - dest="keyid") - tag_group.add_config_file_option(option_name="debian-tag", - dest="debian_tag") - tag_group.add_config_file_option(option_name="upstream-tag", - dest="upstream_tag") - tag_group.add_option("--skip-debian-tag", dest="skip_debian_tag", - action="store_true", default=False, - help="Don't add a tag after importing the Debian patch") - - import_group.add_config_file_option(option_name="filter", - dest="filters", action="append") - import_group.add_boolean_config_file_option(option_name="pristine-tar", - dest="pristine_tar") - import_group.add_option("--allow-same-version", action="store_true", - dest="allow_same_version", default=False, - help="allow import of already imported version") - import_group.add_boolean_config_file_option(option_name="author-is-committer", - dest="author_committer") - import_group.add_boolean_config_file_option(option_name="author-date-is-committer-date", - dest="author_committer_date") - import_group.add_boolean_config_file_option(option_name="allow-unauthenticated", - dest="allow_unauthenticated") - - parser.add_config_file_option(option_name="repo-user", dest="repo_user", - choices=['DEBIAN', 'GIT']) - parser.add_config_file_option(option_name="repo-email", dest="repo_email", - choices=['DEBIAN', 'GIT']) - parser.add_option("--download", dest='download', action="store_true", - default=False, help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-dsc(1).") + import_group = parser.add_argument_group("import options", + "pristine-tar and filtering") + tag_group = parser.add_argument_group("tag options", + "options related to git tag creation") + branch_group = parser.add_argument_group("version and branch naming options", + "version number and branch layout options") + + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + branch_group.add_conf_file_arg("--debian-branch", + dest="debian_branch") + branch_group.add_conf_file_arg("--upstream-branch", + dest="upstream_branch") + branch_group.add_bool_conf_file_arg("--create-missing-branches", + dest="create_missing_branches") + + tag_group.add_bool_conf_file_arg("--sign-tags", + dest="sign_tags") + tag_group.add_conf_file_arg("--keyid", + dest="keyid") + tag_group.add_conf_file_arg("--debian-tag", + dest="debian_tag") + tag_group.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + tag_group.add_arg("--skip-debian-tag", dest="skip_debian_tag", + action="store_true", default=False, + help="Don't add a tag after importing the Debian patch") + + import_group.add_conf_file_arg("--filter", + dest="filters", action="append") + import_group.add_bool_conf_file_arg("--pristine-tar", + dest="pristine_tar") + import_group.add_arg("--allow-same-version", action="store_true", + dest="allow_same_version", default=False, + help="allow import of already imported version") + import_group.add_bool_conf_file_arg("--author-is-committer", + dest="author_committer") + import_group.add_bool_conf_file_arg("--author-date-is-committer-date", + dest="author_committer_date") + import_group.add_bool_conf_file_arg("--allow-unauthenticated", + dest="allow_unauthenticated") + + parser.add_conf_file_arg("--repo-user", dest="repo_user", + choices=['DEBIAN', 'GIT']) + parser.add_conf_file_arg("--repo-email", dest="repo_email", + choices=['DEBIAN', 'GIT']) + parser.add_arg("--download", dest='download', action="store_true", + default=False, help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-dsc(1).") + parser.add_argument("package", metavar="PACKAGE", + help="package to import") + parser.add_argument("target_dir", metavar="TARGET_DIR", nargs="?", + help="target directory where to import") return parser def parse_args(argv): - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None + return None - (options, args) = parser.parse_args(argv[1:]) + options = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose, options.color_scheme) if options.download: gbp.log.warn("Passing --download explicitly is deprecated.") - return options, args + download, pkg = is_download(options.package) + # honor options.download until removed + options.download = download or options.download + + return options def is_download(pkg): @@ -409,34 +413,13 @@ def is_download(pkg): return (False, pkg) -def parse_all(argv): - options, args = parse_args(argv) - if not options: - return None, None, None - - if len(args) == 1: - pkg = args[0] - target = None - elif len(args) == 2: - pkg = args[0] - target = args[1] - else: - gbp.log.err("Need to give exactly one package to import. Try --help.") - return None, None, None - - download, pkg = is_download(pkg) - # honor options.download until removed - options.download = download or options.download - return options, pkg, target - - def main(argv): dirs = dict(top=os.path.abspath(os.curdir)) needs_repo = False ret = 1 skipped = False - options, pkg, target = parse_all(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error @@ -454,11 +437,11 @@ def main(argv): needs_repo = True if options.download: - dscfile = download_source(pkg, + dscfile = download_source(options.package, dirs=dirs, unauth=options.allow_unauthenticated) else: - dscfile = pkg + dscfile = options.package dsc = DscFile.parse(dscfile) if dsc.pkgformat not in ['1.0', '3.0']: @@ -467,7 +450,7 @@ def main(argv): print_dsc(dsc) if needs_repo: - target = target or dsc.pkg + target = options.target_dir or dsc.pkg if os.path.exists(target): raise GbpError("Directory '%s' already exists. If you want to import into it, " "please change into this directory otherwise move it away first." diff --git a/gbp/scripts/import_dscs.py b/gbp/scripts/import_dscs.py index 997e3ccc..f13b397f 100644 --- a/gbp/scripts/import_dscs.py +++ b/gbp/scripts/import_dscs.py @@ -26,7 +26,7 @@ from gbp.errors import GbpError from gbp.git import GitRepository, GitRepositoryError from gbp.scripts import import_dsc -from gbp.config import GbpOptionParser +from gbp.config import GbpConfig import gbp.log @@ -102,7 +102,7 @@ def set_gbp_conf_files(): Filter out all gbp.conf files that are local to the git repository and set GBP_CONF_FILES accordingly so gbp import-dsc will only use these. """ - global_config = GbpOptionParser.get_config_files(no_local=True) + global_config = GbpConfig.get_config_files(no_local=True) gbp_conf_files = ':'.join(global_config) os.environ['GBP_CONF_FILES'] = gbp_conf_files gbp.log.debug("Setting GBP_CONF_FILES to '%s'" % gbp_conf_files) diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 3d974e93..253a7645 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -29,7 +29,7 @@ from gbp.deb.uscan import (Uscan, UscanError) from gbp.deb.changelog import ChangeLog, NoChangeLogError from gbp.deb.git import GitRepositoryError -from gbp.config import GbpOptionParserDebian, GbpOptionGroup, no_upstream_branch_msg +from gbp.config import GbpConfArgParserDebian, no_upstream_branch_msg from gbp.errors import GbpError from gbp.format import format_str from gbp.git.vfs import GitVfs @@ -133,31 +133,26 @@ def detect_name_and_version(repo, source, options): return (sourcepackage, version) -def find_upstream(use_uscan, args, version=None): +def find_upstream(use_uscan, filepath, version=None): """Find the main tarball to import - either via uscan or via command line argument @return: upstream source filename or None if nothing to import @rtype: string @raise GbpError: raised on all detected errors - >>> find_upstream(False, ['too', 'many']) - Traceback (most recent call last): - ... - gbp.errors.GbpError: More than one archive specified. Try --help. - >>> find_upstream(False, []) + >>> find_upstream(False, '') Traceback (most recent call last): ... gbp.errors.GbpError: No archive to import specified. Try --help. - >>> find_upstream(True, ['tarball']) + >>> find_upstream(True, 'tarball') Traceback (most recent call last): ... gbp.errors.GbpError: you can't pass both --uscan and a filename. - >>> find_upstream(False, ['tarball']).path + >>> find_upstream(False, 'tarball').path 'tarball' """ if use_uscan: - if args: + if filepath: raise GbpError("you can't pass both --uscan and a filename.") - uscan = Uscan() gbp.log.info("Launching uscan...") try: @@ -169,15 +164,14 @@ def find_upstream(use_uscan, args, version=None): if uscan.tarball: gbp.log.info("Using uscan downloaded tarball %s" % uscan.tarball) - args.append(uscan.tarball) + filepath = uscan.tarball else: raise GbpError("uscan didn't download anything, and no source was found in ../") - if len(args) > 1: # source specified - raise GbpError("More than one archive specified. Try --help.") - elif len(args) == 0: + if not filepath: raise GbpError("No archive to import specified. Try --help.") else: - return DebianUpstreamSource(args[0]) + archive = DebianUpstreamSource(filepath) + return archive def debian_branch_merge(repo, tag, version, options): @@ -306,69 +300,70 @@ def rollback(repo, options): def build_parser(name): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', - usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan') + parser = GbpConfArgParserDebian.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - import_group = GbpOptionGroup(parser, "import options", - "pristine-tar and filtering") - tag_group = GbpOptionGroup(parser, "tag options", - "options related to git tag creation") - branch_group = GbpOptionGroup(parser, "version and branch naming options", - "version number and branch layout options") - cmd_group = GbpOptionGroup(parser, "external command options", - "how and when to invoke external commands and hooks") - for group in [import_group, branch_group, tag_group, cmd_group]: - parser.add_option_group(group) - - branch_group.add_option("-u", "--upstream-version", dest="version", - help="Upstream Version") - branch_group.add_config_file_option(option_name="debian-branch", - dest="debian_branch") - branch_group.add_config_file_option(option_name="upstream-branch", - dest="upstream_branch") - branch_group.add_config_file_option(option_name="upstream-vcs-tag", dest="vcs_tag", - help="Upstream VCS tag add to the merge commit") - branch_group.add_boolean_config_file_option(option_name="merge", dest="merge") - branch_group.add_config_file_option(option_name="merge-mode", dest="merge_mode") - - tag_group.add_boolean_config_file_option(option_name="sign-tags", - dest="sign_tags") - tag_group.add_config_file_option(option_name="keyid", - dest="keyid") - tag_group.add_config_file_option(option_name="upstream-tag", - dest="upstream_tag") - import_group.add_config_file_option(option_name="filter", - dest="filters", action="append") - import_group.add_boolean_config_file_option(option_name="pristine-tar", - dest="pristine_tar") - import_group.add_boolean_config_file_option(option_name="filter-pristine-tar", - dest="filter_pristine_tar") - import_group.add_config_file_option(option_name="import-msg", - dest="import_msg") - import_group.add_boolean_config_file_option(option_name="symlink-orig", - dest="symlink_orig") - import_group.add_config_file_option("component", action="append", metavar='COMPONENT', - dest="components") - cmd_group.add_config_file_option(option_name="postimport", dest="postimport") - - parser.add_boolean_config_file_option(option_name="interactive", - dest='interactive') - parser.add_boolean_config_file_option(option_name="rollback", - dest="rollback") - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_option("--uscan", dest='uscan', action="store_true", - default=False, help="use uscan(1) to download the new tarball.") + import_group = parser.add_argument_group("import options", + "pristine-tar and filtering") + tag_group = parser.add_argument_group("tag options", + "options related to git tag creation") + branch_group = parser.add_argument_group("version and branch naming options", + "version number and branch layout options") + cmd_group = parser.add_argument_group("external command options", + "how and when to invoke external commands and hooks") + + branch_group.add_arg("-u", "--upstream-version", dest="version", + help="Upstream Version") + branch_group.add_conf_file_arg("--debian-branch", + dest="debian_branch") + branch_group.add_conf_file_arg("--upstream-branch", + dest="upstream_branch") + branch_group.add_conf_file_arg("--upstream-vcs-tag", dest="vcs_tag", + help="Upstream VCS tag add to the merge commit") + branch_group.add_bool_conf_file_arg("--merge", dest="merge") + branch_group.add_conf_file_arg("--merge-mode", dest="merge_mode") + + tag_group.add_bool_conf_file_arg("--sign-tags", + dest="sign_tags") + tag_group.add_conf_file_arg("--keyid", + dest="keyid") + tag_group.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + import_group.add_conf_file_arg("--filter", + dest="filters", action="append") + import_group.add_bool_conf_file_arg("--pristine-tar", + dest="pristine_tar") + import_group.add_bool_conf_file_arg("--filter-pristine-tar", + dest="filter_pristine_tar") + import_group.add_conf_file_arg("--import-msg", + dest="import_msg") + import_group.add_bool_conf_file_arg("--symlink-orig", + dest="symlink_orig") + import_group.add_conf_file_arg("--component", action="append", metavar='COMPONENT', + dest="components") + cmd_group.add_conf_file_arg("--postimport", dest="postimport") + + parser.add_bool_conf_file_arg("--interactive", + dest='interactive') + parser.add_bool_conf_file_arg("--rollback", + dest="rollback") + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") # Accepted for compatibility - parser.add_option("--download", dest='download', action="store_true", - default=False, help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-orig(1).") + parser.add_arg("--download", dest='download', action="store_true", + default=False, help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-orig(1).") + + src_group = parser.add_mutually_exclusive_group(required=True) + src_group.add_arg("--uscan", action="store_true", + help="use uscan(1) to download the new tarball.") + src_group.add_argument("filepath", metavar="FILEPATH", nargs="?", + help="archive to import") return parser @@ -377,18 +372,18 @@ def parse_args(argv): @return: options and arguments """ - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None + return None - (options, args) = parser.parse_args(argv[1:]) + options = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose, options.color_scheme) if options.download: gbp.log.warn("Passing --download explicitly is deprecated.") - options.download = is_download(args) - return options, args + options.download = is_download([options.filepath]) + return options def main(argv): @@ -398,7 +393,7 @@ def main(argv): linked = False repo = None - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error @@ -420,9 +415,9 @@ def main(argv): # Download the main tarball if options.download: - upstream = download_orig(args[0]) + upstream = download_orig(options.filepath) else: - upstream = find_upstream(options.uscan, args, options.version) + upstream = find_upstream(options.uscan, options.filepath, options.version) if not upstream: return ExitCodes.uscan_up_to_date diff --git a/gbp/scripts/import_ref.py b/gbp/scripts/import_ref.py index e1177a10..7141bedd 100644 --- a/gbp/scripts/import_ref.py +++ b/gbp/scripts/import_ref.py @@ -22,7 +22,7 @@ import sys import gbp.command_wrappers as gbpc from gbp.deb.git import GitRepositoryError -from gbp.config import GbpOptionParserDebian, GbpOptionGroup +from gbp.config import GbpConfArgParserDebian from gbp.errors import GbpError import gbp.log from gbp.scripts.common import ExitCodes @@ -58,53 +58,50 @@ def get_commit_and_version_to_merge(repo, options): def build_parser(name): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', - usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan') + parser = GbpConfArgParserDebian.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - import_group = GbpOptionGroup(parser, "import options", - "import related options") - tag_group = GbpOptionGroup(parser, "tag options", - "tag related options ") - branch_group = GbpOptionGroup(parser, "version and branch naming options", - "version number and branch layout options") - cmd_group = GbpOptionGroup(parser, "external command options", - "how and when to invoke external commands and hooks") - for group in [import_group, branch_group, tag_group, cmd_group]: - parser.add_option_group(group) - - branch_group.add_option("-u", "--upstream-version", dest="version", - help="The version number to use for the new version, " - "default is ''", default='') - branch_group.add_config_file_option(option_name="debian-branch", - dest="debian_branch") - branch_group.add_config_file_option(option_name="upstream-branch", - dest="upstream_branch") - branch_group.add_config_file_option(option_name="upstream-tree", - dest="upstream_tree", - help="Where to merge the upstream changes from.", - default="VERSION") - branch_group.add_config_file_option(option_name="merge-mode", dest="merge_mode") - - tag_group.add_boolean_config_file_option(option_name="sign-tags", - dest="sign_tags") - tag_group.add_config_file_option(option_name="keyid", - dest="keyid") - tag_group.add_config_file_option(option_name="upstream-tag", - dest="upstream_tag") - import_group.add_config_file_option(option_name="import-msg", - dest="import_msg") - cmd_group.add_config_file_option(option_name="postimport", dest="postimport") - - parser.add_boolean_config_file_option(option_name="rollback", - dest="rollback") - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") + import_group = parser.add_argument_group("import options", + "import related options") + tag_group = parser.add_argument_group("tag options", + "tag related options ") + branch_group = parser.add_argument_group("version and branch naming options", + "version number and branch layout options") + cmd_group = parser.add_argument_group("external command options", + "how and when to invoke external commands and hooks") + + branch_group.add_arg("-u", "--upstream-version", dest="version", + help="The version number to use for the new version, " + "default is ''", default='') + branch_group.add_conf_file_arg("--debian-branch", + dest="debian_branch") + branch_group.add_conf_file_arg("--upstream-branch", + dest="upstream_branch") + branch_group.add_conf_file_arg("--upstream-tree", + dest="upstream_tree", + help="Where to merge the upstream changes from.", + default="VERSION") + branch_group.add_conf_file_arg("--merge-mode", dest="merge_mode") + + tag_group.add_bool_conf_file_arg("--sign-tags", + dest="sign_tags") + tag_group.add_conf_file_arg("--keyid", + dest="keyid") + tag_group.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + import_group.add_conf_file_arg("--import-msg", + dest="import_msg") + cmd_group.add_conf_file_arg("--postimport", dest="postimport") + + parser.add_bool_conf_file_arg("--rollback", + dest="rollback") + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") return parser @@ -113,21 +110,21 @@ def parse_args(argv): @return: options and arguments """ - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None + return None - (options, args) = parser.parse_args(argv[1:]) + options = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose, options.color_scheme) - return options, args + return options def main(argv): ret = 0 repo = None - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py index 4abfd9c2..c02b8586 100755 --- a/gbp/scripts/import_srpm.py +++ b/gbp/scripts/import_srpm.py @@ -33,8 +33,7 @@ RpmUpstreamSource, compose_version_str, filter_version) from gbp.rpm.git import (RpmGitRepository, GitRepositoryError) from gbp.git.modifier import GitModifier -from gbp.config import (GbpOptionParserRpm, GbpOptionGroup, - no_upstream_branch_msg) +from gbp.config import GbpConfArgParserRpm, no_upstream_branch_msg from gbp.errors import GbpError from gbp.scripts.common import ExitCodes, is_download from gbp.scripts.common import repo_setup @@ -122,99 +121,94 @@ def force_to_branch_head(repo, branch): def build_parser(name): """Construct command line parser""" try: - parser = GbpOptionParserRpm(command=os.path.basename(name), - prefix='', - usage='%prog [options] /path/to/package' - '.src.rpm [target]') + parser = GbpConfArgParserRpm.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - import_group = GbpOptionGroup(parser, "import options", - "pristine-tar and filtering") - tag_group = GbpOptionGroup(parser, "tag options", - "options related to git tag creation") - branch_group = GbpOptionGroup(parser, "version and branch naming options", - "version number and branch layout options") - - for group in [import_group, branch_group, tag_group]: - parser.add_option_group(group) - - 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", - type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_config_file_option(option_name="tmp-dir", dest="tmp_dir") - parser.add_config_file_option(option_name="vendor", action="store", - dest="vendor") - parser.add_option("--download", action="store_true", dest="download", - default=False, help="download source package") - branch_group.add_config_file_option(option_name="packaging-branch", - dest="packaging_branch") - branch_group.add_config_file_option(option_name="upstream-branch", - dest="upstream_branch") - branch_group.add_option("--upstream-vcs-tag", dest="vcs_tag", - help="Upstream VCS tag on top of which to import " - "the orig sources") - branch_group.add_boolean_config_file_option( - option_name="create-missing-branches", - dest="create_missing_branches") - branch_group.add_option("--orphan-packaging", action="store_true", - dest="orphan_packaging", default=False, - help="The packaging branch doesn't base on upstream") - branch_group.add_option("--native", action="store_true", - dest="native", default=False, - help="This is a dist native package, no separate " - "upstream branch") - - tag_group.add_boolean_config_file_option(option_name="sign-tags", - dest="sign_tags") - tag_group.add_config_file_option(option_name="keyid", - dest="keyid") - tag_group.add_config_file_option(option_name="packaging-tag", - dest="packaging_tag") - tag_group.add_config_file_option(option_name="upstream-tag", - dest="upstream_tag") - tag_group.add_option("--skip-packaging-tag", dest="skip_packaging_tag", - action="store_true", - help="Don't add a tag after importing packaging files") - - import_group.add_config_file_option(option_name="filter", - dest="filters", action="append") - import_group.add_boolean_config_file_option(option_name="pristine-tar", - dest="pristine_tar") - import_group.add_option("--allow-same-version", action="store_true", - dest="allow_same_version", default=False, - help="allow import of already imported version") - import_group.add_boolean_config_file_option( - option_name="author-is-committer", - dest="author_is_committer") - import_group.add_config_file_option(option_name="packaging-dir", - dest="packaging_dir") - - parser.add_config_file_option(option_name="repo-user", dest="repo_user", - choices=['DEBIAN', 'GIT']) - parser.add_config_file_option(option_name="repo-email", dest="repo_email", - choices=['DEBIAN', 'GIT']) + import_group = parser.add_argument_group("import options", + "pristine-tar and filtering") + tag_group = parser.add_argument_group("tag options", + "options related to git tag creation") + branch_group = parser.add_argument_group("version and branch naming options", + "version number and branch layout options") + + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + default=False, help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", + type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") + parser.add_conf_file_arg("--vendor", action="store", + dest="vendor") + parser.add_arg("--download", action="store_true", dest="download", + default=False, help="download source package") + branch_group.add_conf_file_arg("--packaging-branch", + dest="packaging_branch") + branch_group.add_conf_file_arg("--upstream-branch", + dest="upstream_branch") + branch_group.add_arg("--upstream-vcs-tag", dest="vcs_tag", + help="Upstream VCS tag on top of which to import " + "the orig sources") + branch_group.add_bool_conf_file_arg("--create-missing-branches", + dest="create_missing_branches") + branch_group.add_arg("--orphan-packaging", action="store_true", + dest="orphan_packaging", default=False, + help="The packaging branch doesn't base on upstream") + branch_group.add_arg("--native", action="store_true", + dest="native", default=False, + help="This is a dist native package, no separate " + "upstream branch") + + tag_group.add_bool_conf_file_arg("--sign-tags", + dest="sign_tags") + tag_group.add_conf_file_arg("--keyid", + dest="keyid") + tag_group.add_conf_file_arg("--packaging-tag", + dest="packaging_tag") + tag_group.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + tag_group.add_arg("--skip-packaging-tag", dest="skip_packaging_tag", + action="store_true", + help="Don't add a tag after importing packaging files") + + import_group.add_conf_file_arg("--filter", + dest="filters", action="append") + import_group.add_bool_conf_file_arg("--pristine-tar", + dest="pristine_tar") + import_group.add_arg("--allow-same-version", action="store_true", + dest="allow_same_version", default=False, + help="allow import of already imported version") + import_group.add_bool_conf_file_arg("--author-is-committer", + dest="author_is_committer") + import_group.add_conf_file_arg("--packaging-dir", + dest="packaging_dir") + + parser.add_conf_file_arg("--repo-user", dest="repo_user", + choices=['DEBIAN', 'GIT']) + parser.add_conf_file_arg("--repo-email", dest="repo_email", + choices=['DEBIAN', 'GIT']) + parser.add_argument("package", metavar="PACKAGE", help="package to import") + parser.add_argument("target_dir", metavar="TARGET_DIR", nargs="?", + help="target directory where to import") return parser def parse_args(argv): """Parse commandline arguments""" - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None + return None - (options, args) = parser.parse_args(argv[1:]) + options = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose, options.color_scheme) if options.download: gbp.log.warn("Passing --download explicitly is deprecated.") - options.download = is_download(args) - return options, args + options.download = is_download([options.package]) + return options def main(argv): @@ -224,19 +218,10 @@ def main(argv): ret = 0 skipped = False - options, args = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error - if len(args) == 1: - srpm = args[0] - target = None - elif len(args) == 2: - srpm = args[0] - target = args[1] - else: - gbp.log.err("Need to give exactly one package to import. Try --help.") - return 1 try: dirs['tmp_base'] = init_tmpdir(options.tmp_dir, 'import-srpm_') except GbpError as err: @@ -244,7 +229,9 @@ def main(argv): return 1 try: if options.download: - srpm = download_source(srpm) + srpm = download_source(options.package) + else: + srpm = options.package # Real srpm, we need to unpack, first true_srcrpm = False @@ -257,7 +244,7 @@ def main(argv): preferred_spec = src.name + '.spec' srpm = dirs['pkgextract'] elif os.path.isdir(srpm): - preferred_spec = os.path.basename(srpm.rstrip('/')) + '.spec' + preferred_spec = os.path.basename(options.package.rstrip('/')) + '.spec' else: preferred_spec = None @@ -286,7 +273,7 @@ def main(argv): except GitRepositoryError: gbp.log.info("No git repository found, creating one.") is_empty = True - target = target or spec.name + target = options.target_dir or spec.name repo = RpmGitRepository.create(target) os.chdir(repo.path) repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo) diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 7bf7736f..be99b6aa 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -23,7 +23,8 @@ import sys import tempfile import re -from gbp.config import GbpOptionParserDebian +from argparse import ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter +from gbp.config import GbpConfArgParserDebian from gbp.deb.source import DebianSource from gbp.deb.git import DebianGitRepository from gbp.git import GitRepositoryError @@ -396,8 +397,13 @@ def switch_pq(repo, branch, options): switch_to_pq_branch(repo, branch) -def usage_msg(): - return """%prog [options] action - maintain patches on a patch queue branch +class GbpPqHelpFormatter(RawDescriptionHelpFormatter, + ArgumentDefaultsHelpFormatter): + pass + + +def descr_msg(): + return """Maintain patches on a patch queue branch Actions: export export the patch queue associated to the current branch into a quilt patch series in debian/patches/ and update the @@ -411,40 +417,43 @@ def usage_msg(): def build_parser(name): + usage = "%(prog)s [options] action" try: - parser = GbpOptionParserDebian(command=os.path.basename(name), - usage=usage_msg()) + parser = GbpConfArgParserDebian.create_parser(prog=name, + usage=usage, + description=descr_msg(), + formatter_class=GbpPqHelpFormatter) except GbpError as err: gbp.log.err(err) return None - parser.add_boolean_config_file_option(option_name="patch-numbers", dest="patch_numbers") - parser.add_config_file_option(option_name="patch-num-format", dest="patch_num_format") - parser.add_boolean_config_file_option(option_name="renumber", dest="renumber") - parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, - help="verbose command execution") - parser.add_option("--topic", dest="topic", help="in case of 'apply' topic (subdir) to put patch into") - parser.add_config_file_option(option_name="time-machine", dest="time_machine", type="int") - parser.add_boolean_config_file_option("drop", dest='drop') - parser.add_boolean_config_file_option(option_name="commit", dest="commit") - parser.add_config_file_option(option_name="abbrev", dest="abbrev", type="int") - parser.add_option("--force", dest="force", action="store_true", default=False, - help="in case of import even import if the branch already exists") - parser.add_config_file_option(option_name="color", dest="color", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_config_file_option(option_name="meta-closes", dest="meta_closes") - parser.add_config_file_option(option_name="meta-closes-bugnum", dest="meta_closes_bugnum") - parser.add_config_file_option(option_name="pq-from", dest="pq_from", choices=['DEBIAN', 'TAG']) - parser.add_config_file_option(option_name="upstream-tag", dest="upstream_tag") + parser.add_bool_conf_file_arg("--patch-numbers", dest="patch_numbers") + parser.add_conf_file_arg("--patch-num-format", dest="patch_num_format") + parser.add_bool_conf_file_arg("--renumber", dest="renumber") + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_arg("--topic", dest="topic", help="in case of 'apply' topic (subdir) to put patch into") + parser.add_conf_file_arg("--time-machine", dest="time_machine", type=int) + parser.add_bool_conf_file_arg("--drop", dest='drop') + parser.add_bool_conf_file_arg("--commit", dest="commit") + parser.add_conf_file_arg("--abbrev", dest="abbrev", type=int) + parser.add_arg("--force", dest="force", action="store_true", default=False, + help="in case of import even import if the branch already exists") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_conf_file_arg("--meta-closes", dest="meta_closes") + parser.add_conf_file_arg("--meta-closes-bugnum", dest="meta_closes_bugnum") + parser.add_conf_file_arg("--pq-from", dest="pq_from", choices=['DEBIAN', 'TAG']) + parser.add_conf_file_arg("--upstream-tag", dest="upstream_tag") return parser def parse_args(argv): - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: return None, None - return parser.parse_args(argv) + return parser.parse_known_args(argv[1:]) def main(argv): @@ -456,22 +465,24 @@ def main(argv): gbp.log.setup(options.color, options.verbose, options.color_scheme) - if len(args) < 2: + if len(args) < 1: gbp.log.err("No action given.") return 1 else: - action = args[1] + action = args[0] - if args[1] in ["export", "import", "rebase", "drop", "switch"]: - pass - elif args[1] in ["apply"]: - if len(args) != 3: + if action in ["export", "import", "rebase", "drop", "switch"]: + if len(args) != 1: + gbp.log.err("Invalid options: %s" % ", ".join(args[1:])) + return 1 + elif action in ["apply"]: + if len(args) != 2: gbp.log.err("No patch name given.") return 1 else: - patchfile = args[2] + patchfile = args[1] else: - gbp.log.err("Unknown action '%s'." % args[1]) + gbp.log.err("Unknown action '%s'." % action) return 1 try: diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index fcefbb6e..2aa03130 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -24,10 +24,11 @@ import os import re import sys +from argparse import ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter import gbp.log from gbp.tmpfile import init_tmpdir, del_tmpdir, tempfile -from gbp.config import GbpOptionParserRpm +from gbp.config import GbpConfArgParserRpm from gbp.rpm.git import GitRepositoryError, RpmGitRepository from gbp.git.modifier import GitModifier from gbp.command_wrappers import GitCommand, CommandExecFailed @@ -362,9 +363,14 @@ def switch_pq(repo, current): switch_to_pq_branch(repo, current) -def usage_msg(): - return """%prog [options] action - maintain patches on a patch queue branch -Ations: +class GbpPqRpmHelpFormatter(RawDescriptionHelpFormatter, + ArgumentDefaultsHelpFormatter): + pass + + +def descr_msg(): + return """Maintain patches on a patch queue branch +Actions: export Export the patch queue / devel branch associated to the current branch into a patch series in and update the spec file import Create a patch queue / devel branch from spec file @@ -379,42 +385,44 @@ def usage_msg(): def build_parser(name): """Construct command line parser""" + usage = "%(prog)s [options] action" try: - parser = GbpOptionParserRpm(command=os.path.basename(name), - prefix='', usage=usage_msg()) - + parser = GbpConfArgParserRpm.create_parser(prog=name, + usage=usage, + description=descr_msg(), + formatter_class=GbpPqRpmHelpFormatter) except GbpError as err: gbp.log.err(err) return None - 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_option("--force", dest="force", action="store_true", - default=False, - help="In case of import even import if the branch already exists") - parser.add_boolean_config_file_option("drop", dest='drop') - parser.add_config_file_option(option_name="color", dest="color", - type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_config_file_option(option_name="tmp-dir", dest="tmp_dir") - parser.add_config_file_option(option_name="abbrev", dest="abbrev", type="int") - parser.add_config_file_option(option_name="upstream-tag", - dest="upstream_tag") - parser.add_config_file_option(option_name="spec-file", dest="spec_file") - parser.add_config_file_option(option_name="packaging-dir", - dest="packaging_dir") + parser.add_bool_conf_file_arg("--patch-numbers", + dest="patch_numbers") + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + default=False, help="Verbose command execution") + parser.add_arg("--force", dest="force", action="store_true", + default=False, + help="In case of import even import if the branch already exists") + parser.add_bool_conf_file_arg("--drop", dest="drop") + parser.add_conf_file_arg("--color", dest="color", + type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") + parser.add_conf_file_arg("--abbrev", dest="abbrev", type=int) + parser.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + parser.add_conf_file_arg("--spec-file", dest="spec_file") + parser.add_conf_file_arg("--packaging-dir", + dest="packaging_dir") return parser def parse_args(argv): """Parse command line arguments""" - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: return None, None - return parser.parse_args(argv) + return parser.parse_known_args(argv[1:]) def main(argv): @@ -427,22 +435,24 @@ def main(argv): gbp.log.setup(options.color, options.verbose, options.color_scheme) - if len(args) < 2: + if len(args) < 1: gbp.log.err("No action given.") return 1 else: - action = args[1] + action = args[0] - if args[1] in ["export", "import", "rebase", "drop", "switch", "convert"]: - pass - elif args[1] in ["apply"]: - if len(args) != 3: + if action in ["export", "import", "rebase", "drop", "switch", "convert"]: + if len(args) != 1: + gbp.log.err("Invalid options: %s" % ", ".join(args[1:])) + return 1 + elif action in ["apply"]: + if len(args) != 2: gbp.log.err("No patch name given.") return 1 else: - patchfile = args[2] + patchfile = args[1] else: - gbp.log.err("Unknown action '%s'." % args[1]) + gbp.log.err("Unknown action '%s'." % action) return 1 try: diff --git a/gbp/scripts/pristine_tar.py b/gbp/scripts/pristine_tar.py index 792bcab6..80de1d66 100644 --- a/gbp/scripts/pristine_tar.py +++ b/gbp/scripts/pristine_tar.py @@ -20,39 +20,48 @@ import os import sys import gbp.log +from argparse import ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter from gbp.command_wrappers import CommandExecFailed -from gbp.config import GbpOptionParserDebian +from gbp.config import GbpConfArgParserDebian from gbp.deb.git import (GitRepositoryError, DebianGitRepository) from gbp.deb.source import DebianSource from gbp.errors import GbpError from gbp.scripts.common import ExitCodes, get_component_tarballs -def usage_msg(): - return """%prog [action] [options] /path/to/upstream-version.tar.gz +class GbpHelpFormatter(RawDescriptionHelpFormatter, + ArgumentDefaultsHelpFormatter): + pass -Actions: + +def descr_msg(): + return """Actions: commit recreate the pristine-tar commits on the pristine-tar branch """ def build_parser(name): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', - usage=usage_msg()) + parser = GbpConfArgParserDebian.create_parser(prog=name, + description=descr_msg(), + formatter_class=GbpHelpFormatter) except GbpError as err: gbp.log.err(err) return None - parser.add_config_file_option(option_name="upstream-tag", - dest="upstream_tag") - parser.add_config_file_option("component", action="append", metavar='COMPONENT', - dest="components") - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") + parser.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + parser.add_conf_file_arg("--component", action="append", metavar='COMPONENT', + dest="components") + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_argument("action", metavar="ACTION", choices=('commit',), + help="action to take") + parser.add_argument("tarball", metavar="TARBALL", + help="tarball to operate on") return parser @@ -61,29 +70,23 @@ def parse_args(argv): @return: options and arguments """ - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None + return None - (options, args) = parser.parse_args(argv[1:]) + options = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose, options.color_scheme) - return options, args + return options def main(argv): ret = 1 repo = None - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error - if len(args) != 2 or args[0] not in ['commit']: - gbp.log.err("No action given") - return 1 - else: - tarball = args[1] - try: try: repo = DebianGitRepository('.') @@ -93,12 +96,12 @@ def main(argv): source = DebianSource('.') component_tarballs = get_component_tarballs(source.sourcepkg, source.upstream_version, - tarball, + options.tarball, options.components) upstream_tag = repo.version_to_tag(options.upstream_tag, source.upstream_version) repo.create_pristine_tar_commits(upstream_tag, - tarball, + options.tarball, component_tarballs) ret = 0 except (GitRepositoryError, GbpError, CommandExecFailed) as err: @@ -111,7 +114,7 @@ def main(argv): comp_msg = (' with additional tarballs for %s' % ", ".join([os.path.basename(t[1]) for t in component_tarballs])) if component_tarballs else '' gbp.log.info("Successfully committed pristine-tar data for version %s of %s%s" % (source.upstream_version, - tarball, + options.tarball, comp_msg)) return ret diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py index 9027d900..7b663a73 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -23,7 +23,7 @@ import os import os.path from gbp.command_wrappers import (Command, CommandExecFailed) -from gbp.config import (GbpOptionParser, GbpOptionGroup) +from gbp.config import GbpConfArgParserDebian from gbp.errors import GbpError from gbp.git import GitRepositoryError from gbp.deb.git import DebianGitRepository @@ -79,46 +79,46 @@ def fast_forward_branch(rem_repo, branch, repo, options): def build_parser(name): + description = 'safely update a repository from remote' try: - parser = GbpOptionParser(command=os.path.basename(name), prefix='', - usage='%prog [options] [repo] - safely update a repository from remote') + parser = GbpConfArgParserDebian.create_parser(prog=name, + description=description) except GbpError as err: gbp.log.err(err) return None - branch_group = GbpOptionGroup(parser, "branch options", "branch update and layout options") - parser.add_option_group(branch_group) - branch_group.add_boolean_config_file_option(option_name="ignore-branch", dest="ignore_branch") - branch_group.add_option("--force", action="store_true", dest="force", default=False, - help="force a branch update even if it can't be fast forwarded") - branch_group.add_option("--all", action="store_true", default=False, - help="update all remote-tracking branches that " - "have identical name in the remote") - branch_group.add_option("--redo-pq", action="store_true", dest="redo_pq", default=False, - help="redo the patch queue branch after a pull. Warning: this drops the old patch-queue branch") - branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") - branch_group.add_config_file_option(option_name="debian-branch", dest="debian_branch") - branch_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar") - branch_group.add_boolean_config_file_option(option_name="track-missing", dest="track_missing") - branch_group.add_option("--depth", action="store", dest="depth", default=0, - help="git history depth (for deepening shallow clones)") - 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", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") + branch_group = parser.add_argument_group("branch options", "branch update and layout options") + + branch_group.add_bool_conf_file_arg("--ignore-branch") + branch_group.add_arg("--force", action="store_true", + help="force a branch update even if it can't be fast " + "forwarded") + branch_group.add_arg("--all", action="store_true", + help="update all remote-tracking branches that " + "have identical name in the remote") + branch_group.add_arg("--redo-pq", action="store_true", + help="redo the patch queue branch after a pull. Warning: " + "this drops the old patch-queue branch") + branch_group.add_conf_file_arg("--upstream-branch") + branch_group.add_conf_file_arg("--debian-branch") + branch_group.add_bool_conf_file_arg("--pristine-tar") + branch_group.add_bool_conf_file_arg("--track-missing", dest="track_missing") + branch_group.add_arg("--depth", action="store", default=0, + help="git history depth (for deepening shallow clones)") + parser.add_arg("-v", "--verbose", action="store_true", + help="verbose command execution") + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + parser.add_argument("remote", metavar="REMOTE", nargs="?", + help="remote from which to pull") return parser def parse_args(argv): - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None - options, args = parser.parse_args(argv) - if len(args) > 2: - parser.print_help(file=sys.stderr) - return None, None - return options, args + return None + return parser.parse_args(argv[1:]) def get_remote(repo, current): @@ -144,17 +144,15 @@ def track_missing(repo, remote, branch, options): def main(argv): retval = 0 current = None - rem_repo = None - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) - if len(args) == 2: - rem_repo = args[1] - gbp.log.info("Fetching from '%s'" % rem_repo) + if options.remote: + gbp.log.info("Fetching from '%s'" % options.remote) else: gbp.log.info("Fetching from default remote for each branch") @@ -182,8 +180,8 @@ def main(argv): gbp.log.err(out) raise GbpError - repo.fetch(rem_repo, depth=options.depth) - repo.fetch(rem_repo, depth=options.depth, tags=True) + repo.fetch(options.remote, depth=options.depth) + repo.fetch(options.remote, depth=options.depth, tags=True) fetch_remote = get_remote(repo, current) for branch in [options.debian_branch, options.upstream_branch]: @@ -212,7 +210,7 @@ def main(argv): branches.add(branch) for branch in branches: - if not fast_forward_branch(rem_repo, branch, repo, options): + if not fast_forward_branch(options.remote, branch, repo, options): retval = 2 if options.redo_pq: diff --git a/gbp/scripts/push.py b/gbp/scripts/push.py index 209fd416..e79bd168 100755 --- a/gbp/scripts/push.py +++ b/gbp/scripts/push.py @@ -21,7 +21,7 @@ import sys import gbp.log -from gbp.config import GbpOptionParserDebian +from gbp.config import GbpConfArgParserDebian from gbp.deb.git import DebianGitRepository, GitRepositoryError from gbp.deb.source import DebianSourceError from gbp.deb.source import DebianSource @@ -31,38 +31,39 @@ def build_parser(name): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), - usage='%prog [options]') + parser = GbpConfArgParserDebian.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - parser.add_option("-d", "--dry-run", dest="dryrun", default=False, - action="store_true", help="dry run, don't push.") - parser.add_config_file_option(option_name="upstream-branch", - dest="upstream_branch") - parser.add_config_file_option(option_name="upstream-tag", - dest="upstream_tag") - parser.add_config_file_option(option_name="debian-branch", - dest="debian_branch") - parser.add_config_file_option(option_name="debian-tag", - dest="debian_tag") - parser.add_boolean_config_file_option(option_name="pristine-tar", - dest="pristine_tar") - parser.add_boolean_config_file_option(option_name="ignore-branch", dest="ignore_branch") - parser.add_config_file_option(option_name="color", dest="color", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_option("--verbose", action="store_true", dest="verbose", - default=False, help="verbose command execution") + parser.add_arg("-d", "--dry-run", dest="dryrun", default=False, + action="store_true", help="dry run, don't push.") + parser.add_conf_file_arg("--upstream-branch", + dest="upstream_branch") + parser.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + parser.add_conf_file_arg("--debian-branch", + dest="debian_branch") + parser.add_conf_file_arg("--debian-tag", + dest="debian_tag") + parser.add_bool_conf_file_arg("--pristine-tar", + dest="pristine_tar") + parser.add_bool_conf_file_arg("--ignore-branch", dest="ignore_branch") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_arg("--verbose", action="store_true", dest="verbose", + default=False, help="verbose command execution") + parser.add_argument("remote", metavar="REMOTE", nargs="?", + help="remote where to push") return parser def parse_args(argv): - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None - return parser.parse_args(argv) + return None + return parser.parse_args(argv[1:]) def do_push(repo, dests, to_push, dry_run): @@ -108,21 +109,15 @@ def get_remote(repo, branch): def main(argv): retval = 1 branch = None - dest = None to_push = { 'refs': {}, 'tags': [], } - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error - if len(args) > 2: - gbp.log.err("Only a single remote repository can be given") - elif len(args) == 2: - dest = args[1] - gbp.log.setup(options.color, options.verbose, options.color_scheme) try: repo = DebianGitRepository(os.path.curdir, toplevel=False) @@ -140,8 +135,7 @@ def main(argv): "on '%s'" % branch if branch else 'in detached HEAD state')) raise GbpError("Use --ignore-branch to ignore or --debian-branch to set the branch name.") - if not dest: - dest = get_remote(repo, branch) + dest = options.remote or get_remote(repo, branch) if options.debian_tag != '': dtag = repo.version_to_tag(options.debian_tag, source.version) diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py index 9212f717..77677814 100644 --- a/gbp/scripts/rpm_ch.py +++ b/gbp/scripts/rpm_ch.py @@ -27,7 +27,7 @@ import gbp.command_wrappers as gbpc import gbp.log -from gbp.config import GbpOptionParserRpm, GbpOptionGroup +from gbp.config import GbpConfArgParserRpm from gbp.errors import GbpError from gbp.rpm import (guess_spec, NoSpecError, SpecFile, split_version_str, compose_version_str) @@ -310,98 +310,96 @@ def update_changelog(changelog, entries, repo, spec, options): def build_parser(name): """Construct command line parser""" try: - parser = GbpOptionParserRpm(command=os.path.basename(name), - prefix='', usage='%prog [options] paths') + parser = GbpConfArgParserRpm.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - range_grp = GbpOptionGroup(parser, "commit range options", - "which commits to add to the changelog") - format_grp = GbpOptionGroup(parser, "changelog entry formatting", - "how to format the changelog entries") - naming_grp = GbpOptionGroup(parser, "naming", - "branch names, tag formats, directory and file naming") - parser.add_option_group(range_grp) - parser.add_option_group(format_grp) - parser.add_option_group(naming_grp) + range_grp = parser.add_argument_group("commit range options", + "which commits to add to the changelog") + format_grp = parser.add_argument_group("changelog entry formatting", + "how to format the changelog entries") + naming_grp = parser.add_argument_group("naming", + "branch names, tag formats, directory and file naming") # Non-grouped options - parser.add_option("-v", "--verbose", action="store_true", dest="verbose", - help="verbose command execution") - parser.add_config_file_option(option_name="color", dest="color", - type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_config_file_option(option_name="tmp-dir", dest="tmp_dir") - parser.add_config_file_option(option_name="vendor", action="store", - dest="vendor") - parser.add_config_file_option(option_name="git-log", dest="git_log", - help="options to pass to git-log, default is '%(git-log)s'") - parser.add_boolean_config_file_option(option_name="ignore-branch", - dest="ignore_branch") - parser.add_config_file_option(option_name="customizations", - dest="customization_file", - help="Load Python code from CUSTOMIZATION_FILE. At the " - "moment, the only useful thing the code can do is define a " - "custom ChangelogEntryFormatter class.") + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + help="verbose command execution") + parser.add_conf_file_arg("--color", dest="color", + type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") + parser.add_conf_file_arg("--vendor", action="store", + dest="vendor") + parser.add_conf_file_arg("--git-log", dest="git_log", + help="options to pass to git-log") + parser.add_bool_conf_file_arg("--ignore-branch", + dest="ignore_branch") + parser.add_conf_file_arg("--customizations", + dest="customization_file", + help="Load Python code from CUSTOMIZATION_FILE. At the " + "moment, the only useful thing the code can do is define a " + "custom ChangelogEntryFormatter class.") # Naming group options - naming_grp.add_config_file_option(option_name="packaging-branch", - dest="packaging_branch") - naming_grp.add_config_file_option(option_name="packaging-tag", - dest="packaging_tag") - naming_grp.add_config_file_option(option_name="packaging-dir", - dest="packaging_dir") - naming_grp.add_config_file_option(option_name="changelog-file", - dest="changelog_file") - naming_grp.add_config_file_option(option_name="spec-file", dest="spec_file") + naming_grp.add_conf_file_arg("--packaging-branch", + dest="packaging_branch") + naming_grp.add_conf_file_arg("--packaging-tag", + dest="packaging_tag") + naming_grp.add_conf_file_arg("--packaging-dir", + dest="packaging_dir") + naming_grp.add_conf_file_arg("--changelog-file", + dest="changelog_file") + naming_grp.add_conf_file_arg("--spec-file", dest="spec_file") # Range group options - range_grp.add_option("-s", "--since", dest="since", - help="commit to start from (e.g. HEAD^^^, release/0.1.2)") + range_grp.add_arg("-s", "--since", dest="since", + help="commit to start from (e.g. HEAD^^^, release/0.1.2)") # Formatting group options - format_grp.add_option("--no-release", action="store_false", default=True, - dest="release", - help="no release, just update the last changelog section") - format_grp.add_boolean_config_file_option(option_name="git-author", - dest="git_author") - format_grp.add_boolean_config_file_option(option_name="full", dest="full") - format_grp.add_config_file_option(option_name="id-length", dest="idlen", - help="include N digits of the commit id in the changelog " - "entry, default is '%(id-length)s'", - type="int", metavar="N") - format_grp.add_config_file_option(option_name="ignore-regex", - dest="ignore_regex", - help="Ignore lines in commit message matching regex, " - "default is '%(ignore-regex)s'") - format_grp.add_config_file_option(option_name="changelog-revision", - dest="changelog_revision") - format_grp.add_config_file_option(option_name="spawn-editor", - dest="spawn_editor") - format_grp.add_config_file_option(option_name="editor-cmd", - dest="editor_cmd") + format_grp.add_arg("--no-release", action="store_false", default=True, + dest="release", + help="no release, just update the last changelog section") + format_grp.add_bool_conf_file_arg("--git-author", + dest="git_author") + format_grp.add_bool_conf_file_arg("--full", dest="full") + format_grp.add_conf_file_arg("--id-length", dest="idlen", + help="include N digits of the commit id in " + "the changelog entry", + type=int, metavar="N") + format_grp.add_conf_file_arg("--ignore-regex", + dest="ignore_regex", + help="Ignore lines in commit message matching regex,") + format_grp.add_conf_file_arg("--changelog-revision", + dest="changelog_revision") + format_grp.add_conf_file_arg("--spawn-editor", + dest="spawn_editor") + format_grp.add_conf_file_arg("--editor-cmd", + dest="editor_cmd") + + parser.add_argument("path", metavar="PATH", nargs="*", + help="path(s) to look for changes") return parser def parse_args(argv): """Parse command line and config file options""" - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None + return None - options, args = parser.parse_args(argv[1:]) + options = parser.parse_args(argv[1:]) if not options.changelog_revision: options.changelog_revision = RpmPkgPolicy.Changelog.header_rev_format gbp.log.setup(options.color, options.verbose, options.color_scheme) - return options, args + return options def main(argv): """Script main function""" - options, args = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error @@ -422,9 +420,9 @@ def main(argv): since = get_start_commit(ch_file.changelog, repo, options) # Get range of commits from where to generate changes - if args: - gbp.log.info("Only looking for changes in '%s'" % ", ".join(args)) - commits = repo.get_commits(since=since, until='HEAD', paths=args, + if options.path: + gbp.log.info("Only looking for changes in '%s'" % ", ".join(options.path)) + commits = repo.get_commits(since=since, until='HEAD', paths=options.path, options=options.git_log.split(" ")) commits.reverse() if not commits: diff --git a/gbp/scripts/tag.py b/gbp/scripts/tag.py index 1e91fcdf..7a0ef3cd 100755 --- a/gbp/scripts/tag.py +++ b/gbp/scripts/tag.py @@ -22,7 +22,7 @@ import gbp.log from gbp.format import format_str -from gbp.config import GbpOptionParserDebian +from gbp.config import GbpConfArgParserDebian from gbp.deb.git import DebianGitRepository, GitRepositoryError from gbp.deb.source import DebianSourceError from gbp.deb.source import DebianSource @@ -80,45 +80,43 @@ def perform_tagging(repo, source, options, hook_env=None): def build_parser(name): try: - parser = GbpOptionParserDebian(command=os.path.basename(name), - usage='%prog [options]') + parser = GbpConfArgParserDebian.create_parser(prog=name) except GbpError as err: gbp.log.err(err) return None - parser.add_option("--retag", action="store_true", dest="retag", default=False, - help="don't fail if the tag already exists") - parser.add_config_file_option(option_name="debian-branch", - dest="debian_branch") - parser.add_config_file_option(option_name="debian-tag", - dest="debian_tag") - parser.add_config_file_option(option_name="debian-tag-msg", dest="debian_tag_msg") - parser.add_boolean_config_file_option(option_name="sign-tags", dest="sign_tags") - parser.add_config_file_option(option_name="keyid", dest="keyid") - parser.add_config_file_option(option_name="posttag", dest="posttag", - help="hook run after a successful tag operation, " - "default is '%(posttag)s'") - parser.add_boolean_config_file_option(option_name="ignore-branch", dest="ignore_branch") - parser.add_boolean_config_file_option(option_name="ignore-new", dest="ignore_new") - parser.add_config_file_option(option_name="color", dest="color", type='tristate') - parser.add_config_file_option(option_name="color-scheme", - dest="color_scheme") - parser.add_option("--verbose", action="store_true", dest="verbose", - default=False, help="verbose command execution") + parser.add_arg("--retag", action="store_true", dest="retag", default=False, + help="don't fail if the tag already exists") + parser.add_conf_file_arg("--debian-branch", + dest="debian_branch") + parser.add_conf_file_arg("--debian-tag", + dest="debian_tag") + parser.add_conf_file_arg("--debian-tag-msg", dest="debian_tag_msg") + parser.add_bool_conf_file_arg("--sign-tags", dest="sign_tags") + parser.add_conf_file_arg("--keyid", dest="keyid") + parser.add_conf_file_arg("--posttag", dest="posttag", + help="hook run after a successful tag operation") + parser.add_bool_conf_file_arg("--ignore-branch", dest="ignore_branch") + parser.add_bool_conf_file_arg("--ignore-new", dest="ignore_new") + parser.add_conf_file_arg("--color", dest="color", type='tristate') + parser.add_conf_file_arg("--color-scheme", + dest="color_scheme") + parser.add_arg("--verbose", action="store_true", dest="verbose", + default=False, help="verbose command execution") return parser def parse_args(argv): - parser = build_parser(argv[0]) + parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None - return parser.parse_args(argv) + return None + return parser.parse_args(argv[1:]) def main(argv): retval = 1 - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error diff --git a/tests/18_test_Config.py b/tests/18_test_Config.py index 60cd9cff..74f97064 100644 --- a/tests/18_test_Config.py +++ b/tests/18_test_Config.py @@ -2,7 +2,7 @@ import os import unittest -from gbp.config import GbpOptionParser, GbpOptionGroup +from gbp.config import GbpConfig, GbpConfArgParser from .testutils import GbpLogTester @@ -29,16 +29,17 @@ def test_default(self): """ for n in range(1, 5): for prefix in ['', 'git-', 'gbp-']: - parser = GbpOptionParser('%scmd%d' % (prefix, n)) - self.assertEqual(parser.config['default_option'], 'default_default1') + parser = GbpConfArgParser.create_parser(prog='%scmd%d' % + (prefix, n)) + self.assertEqual(parser.config.get_value('default_option'), 'default_default1') def test_single_override(self): """ A value in any command section should override the default """ for prefix in ['', 'git-', 'gbp-']: - parser = GbpOptionParser('%scmd1' % prefix) - self.assertEqual(parser.config['single_override_option1'], 'single_override_value1') + parser = GbpConfArgParser.create_parser(prog='%scmd1' % prefix) + self.assertEqual(parser.config.get_value('single_override_option1'), 'single_override_value1') # No deprecation warning since the test1.conf section is [cmd1] self._check_log_empty() @@ -47,8 +48,8 @@ def test_single_git_override(self): A value in any git-command section should override the default """ for prefix in ['', 'git-']: - parser = GbpOptionParser('%scmd2' % prefix) - self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1') + parser = GbpConfArgParser.create_parser(prog='%scmd2' % prefix) + self.assertEqual(parser.config.get_value('single_git_override_option1'), 'single_git_override_value1') for line in range(0, 2): self._check_log(line, ".*Old style config section \[git-cmd2\] found please rename to \[cmd2\]") @@ -57,8 +58,8 @@ def test_single_gbp_override(self): A value in any gbp-command section should override the default """ for prefix in ['', 'gbp-']: - parser = GbpOptionParser('%scmd3' % prefix) - self.assertEqual(parser.config['single_gbp_override_option1'], 'single_gbp_override_value1') + parser = GbpConfArgParser.create_parser(prog='%scmd3' % prefix) + self.assertEqual(parser.config.get_value('single_gbp_override_option1'), 'single_gbp_override_value1') for line in range(0, 2): self._check_log(line, ".*Old style config section \[gbp-cmd3\] found please rename to \[cmd3\]") @@ -68,8 +69,10 @@ def test_single_git_override_disabled_deprecations(self): """ for prefix in ['', 'git-']: os.environ['GBP_DISABLE_SECTION_DEPRECATION'] = 'true' - parser = GbpOptionParser('%scmd2' % prefix) - self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1') + parser = GbpConfArgParser.create_parser(prog='%scmd2' % prefix) + self.assertEqual( + parser.config.get_value('single_git_override_option1'), + 'single_git_override_value1') for line in range(0, 2): self._check_log_empty() os.environ.pop('GBP_DISABLE_SECTION_DEPRECATION') @@ -82,53 +85,61 @@ def test_new_overrides_git(self): for n in range(4, 6): for prefix in ['', 'git-']: cmd = '%scmd%d' % (prefix, n) - parser = GbpOptionParser(cmd) - actual = parser.config['new_overrides_git_option1'] + parser = GbpConfArgParser.create_parser(prog=cmd) + actual = parser.config.get_value('new_overrides_git_option1') expected = 'new_overrides_git_value1' self.assertEqual(actual, expected, "%s != %s for %s" % (actual, expected, cmd)) - def test_get_config_file_value(self): + def test_get_conf_file_value(self): """ Read a single value from the parsed config """ - parser = GbpOptionParser('cmd4') - self.assertEqual(parser.get_config_file_value('new_overrides_git_option1'), + parser = GbpConfArgParser.create_parser(prog='cmd4') + self.assertEqual(parser.get_conf_file_value('new_overrides_git_option1'), 'new_overrides_git_value1') - self.assertEqual(parser.get_config_file_value('doesnotexist'), None) + self.assertEqual(parser.get_conf_file_value('doesnotexist'), None) def test_param_list(self): - parser = GbpOptionParser('cmd4') + parser = GbpConfArgParser.create_parser(prog='cmd4') - branch_group = GbpOptionGroup(parser, "branch options", "branch update and layout options") - parser.add_option_group(branch_group) - branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") - branch_group.add_config_file_option("debian-branch", dest="upstream_branch") - parser.add_config_file_option(option_name="color", dest="color", type='tristate') + branch_group = parser.add_argument_group("branch options", "branch update and layout options") + branch_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") + branch_group.add_conf_file_arg("--debian-branch", dest="upstream_branch") + parser.add_conf_file_arg("--color", dest="color", type='tristate') - params = parser.valid_options + params = parser.conf_file_args self.assertTrue('upstream-branch' in params) self.assertTrue('debian-branch' in params) self.assertTrue('color' in params) def test_short_option_with_prefix(self): """Options with short options can't have a prefix""" - class TestOptonParser(GbpOptionParser): + class TestConfig(GbpConfig): list_opts = [] defaults = {'withshort': 'foo'} + + class TestParser(GbpConfArgParser): short_opts = {'withshort': '-S'} - parser = TestOptonParser('cmd', prefix='p') + + config = TestConfig('cmd') + parser = TestParser.create_parser(prefix='p', prog='cmd', config=config) with self.assertRaisesRegexp(ValueError, "Options with prefix cannot have a short option"): - parser.add_config_file_option(option_name="withshort", dest="with_short", help="foo") + parser.add_conf_file_arg("--withshort", dest="with_short", help="foo") def test_short_option(self): - class TestOptionParser(GbpOptionParser): + class TestConfig(GbpConfig): list_opts = [] defaults = {'withshort': 'foo'} + + class TestParser(GbpConfArgParser): short_opts = {'withshort': '-S'} - parser = TestOptionParser('cmd') - parser.add_config_file_option(option_name="withshort", dest="with_short", help="foo") - self.assertEquals('withshort', parser.valid_options[0]) - self.assertEquals(len(parser.valid_options), 1) - self.assertTrue(parser.has_option("--withshort")) - self.assertTrue(parser.has_option("-S")) + config = TestConfig('cmd') + parser = TestParser.create_parser(prog='cmd', config=config) + parser.add_conf_file_arg("--withshort", dest="with_short", help="foo") + self.assertTrue('withshort' in parser.conf_file_args) + self.assertEquals(len(parser.conf_file_args), 1) + args = parser.parse_args(['--withshort', 'bar']) + self.assertEquals(getattr(args, 'with_short'), 'bar') + args = parser.parse_args(['-S', 'baz']) + self.assertEquals(getattr(args, 'with_short'), 'baz') diff --git a/tests/27_test_create_remote_repo.py b/tests/27_test_create_remote_repo.py index 7ab3c51f..7603d403 100644 --- a/tests/27_test_create_remote_repo.py +++ b/tests/27_test_create_remote_repo.py @@ -33,7 +33,7 @@ def test_no_config_templates(self): self.assertFalse(os.path.exists(self.confname)) os.environ['GBP_CONF_FILES'] = self.confname - _, _, sections = create_remote_repo.parse_args(['create-remote-repo']) + _, sections = create_remote_repo.parse_args(['create-remote-repo']) self.assertEqual(create_remote_repo.get_config_names(sections), []) @@ -42,6 +42,6 @@ def test_list_config_templates(self): self.assertTrue(os.path.exists(self.confname)) os.environ['GBP_CONF_FILES'] = self.confname - _, _, sections = create_remote_repo.parse_args(['create-remote-repo']) + _, sections = create_remote_repo.parse_args(['create-remote-repo']) self.assertEqual(create_remote_repo.get_config_names(sections), ['config1', 'config2']) diff --git a/tests/component/rpm/test_import_orig_rpm.py b/tests/component/rpm/test_import_orig_rpm.py index c27601db..90aacb07 100644 --- a/tests/component/rpm/test_import_orig_rpm.py +++ b/tests/component/rpm/test_import_orig_rpm.py @@ -20,13 +20,14 @@ import shutil import sys import subprocess -from nose.tools import eq_ +from nose.tools import assert_raises, eq_ from io import StringIO from gbp.scripts.import_orig import main as import_orig from tests.component import ComponentTestBase, ComponentTestGitRepository from tests.component.rpm import RPM_TEST_DATA_DIR +from tests.testutils import capture_stderr # Disable "Method could be a function warning" # pylint: disable=R0201 @@ -90,13 +91,16 @@ def test_invalid_args(self): origs = [os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2'), os.path.join(DATA_DIR, 'gbp-test-1.1.tar.bz2')] # Test empty args - eq_(mock_import([]), 1) - self._clear_log() + with capture_stderr(): + with assert_raises(SystemExit) as err: + eq_(mock_import([]), 1) + eq_(err.code, 2) # Test multiple archives - eq_(mock_import([] + origs), 1) - self._check_log(0, 'gbp:error: More than one archive specified') - self._clear_log() + with capture_stderr(): + with assert_raises(SystemExit) as err: + eq_(mock_import([] + origs), 1) + eq_(err.code, 2) # Check that nothing is in the repo self._check_repo_state(repo, None, []) diff --git a/tests/component/rpm/test_import_srpm.py b/tests/component/rpm/test_import_srpm.py index 17344b21..87235eb5 100644 --- a/tests/component/rpm/test_import_srpm.py +++ b/tests/component/rpm/test_import_srpm.py @@ -47,7 +47,8 @@ class TestImportPacked(ComponentTestBase): def test_invalid_args(self): """See that import-srpm fails gracefully if called with invalid args""" - eq_(mock_import([]), 1) + with assert_raises(SystemExit): + eq_(mock_import([]), 1) with assert_raises(SystemExit): mock_import(['--invalid-arg=123']) diff --git a/tests/component/rpm/test_pq_rpm.py b/tests/component/rpm/test_pq_rpm.py index 16044fdc..3eff5218 100644 --- a/tests/component/rpm/test_pq_rpm.py +++ b/tests/component/rpm/test_pq_rpm.py @@ -18,7 +18,7 @@ import os import tempfile -from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611 +from nose.tools import eq_, ok_ # pylint: disable=E0611 from gbp.scripts.pq_rpm import main as pq from gbp.git import GitRepository @@ -60,9 +60,9 @@ def test_invalid_args(self): self._clear_log() # Test invalid cmdline options - with assert_raises(SystemExit): - with capture_stderr(): - mock_pq(['--invalid-arg=123']) + with capture_stderr(): + eq_(mock_pq(['export', '--invalid-arg=123']), 1) + self._check_log(0, "gbp:error: Invalid options: --invalid-arg=123") def test_import_outside_repo(self): """Run pq-rpm when not in a git repository""" diff --git a/tests/doctests/test_Config.py b/tests/doctests/test_Config.py index 8d6eadb5..5311f947 100644 --- a/tests/doctests/test_Config.py +++ b/tests/doctests/test_Config.py @@ -1,8 +1,8 @@ # vim: set fileencoding=utf-8 : """ -Test L{gbp.config.GbpOptionParser} -Test L{gbp.config.GbpOptionParserDebian} +Test L{gbp.config.GbpConfArgParser} +Test L{gbp.config.GbpConfArgParserDebian} """ from .. import context # noqa: F401 @@ -11,62 +11,62 @@ def test_option_parser(): """ Methods tested: - - L{gbp.config.GbpOptionParser.add_config_file_option} - - L{gbp.config.GbpOptionParser.add_boolean_config_file_option} + - L{gbp.config.GbpConfArgParser.add_conf_file_arg} + - L{gbp.config.GbpConfArgParser.add_bool_conf_file_arg} >>> import gbp.config - >>> c = gbp.config.GbpOptionParser('common', prefix='test') - >>> c.add_config_file_option(option_name='upstream-branch', dest='upstream') - >>> c.add_boolean_config_file_option(option_name='overlay', dest='overlay') - >>> c.add_boolean_config_file_option(option_name='track', dest='track') + >>> c = gbp.config.GbpConfArgParser.create_parser(prog='common', prefix='test') + >>> c.add_conf_file_arg('--upstream-branch', dest='upstream') + >>> c.add_bool_conf_file_arg('--overlay', dest='overlay') + >>> c.add_bool_conf_file_arg('--track', dest='track') """ def test_option_parser_debian(): """ Methods tested: - - L{gbp.config.GbpOptionParserDebian.add_config_file_option} + - L{gbp.config.GbpConfArgParserDebian.add_conf_file_arg} >>> import gbp.config - >>> c = gbp.config.GbpOptionParserDebian('debian') - >>> c.add_config_file_option(option_name='builder', dest='builder') + >>> c = gbp.config.GbpConfArgParserDebian.create_parser(prog='debian') + >>> c.add_conf_file_arg('--builder', dest='builder') Traceback (most recent call last): ... KeyError: 'builder' - >>> c.add_config_file_option(option_name='builder', dest='builder', help='foo') + >>> c.add_conf_file_arg('--builder', dest='builder', help='foo') """ def test_option_group(): """ Methods tested: - - L{gbp.config.GbpOptionGroup.add_config_file_option} - - L{gbp.config.GbpOptionGroup.add_boolean_config_file_option} + - L{gbp.config.GbpOptionGroup.add_conf_file_arg} + - L{gbp.config.GbpOptionGroup.add_bool_conf_file_arg} >>> import gbp.config - >>> c = gbp.config.GbpOptionParser('debian') - >>> g = gbp.config.GbpOptionGroup(c, 'wheezy') - >>> g.add_config_file_option(option_name='debian-branch', dest='branch') - >>> g.add_boolean_config_file_option(option_name='track', dest='track') + >>> c = gbp.config.GbpConfArgParser.create_parser(prog='debian') + >>> g = c.add_argument_group('wheezy') + >>> g.add_conf_file_arg('--debian-branch', dest='branch') + >>> g.add_bool_conf_file_arg('--track', dest='track') """ def test_tristate(): """ Methods tested: - - L{gbp.config.GbpOptionParser.add_config_file_option} + - L{gbp.config.GbpConfArgParser.add_conf_file_arg} >>> import gbp.config - >>> c = gbp.config.GbpOptionParser('tristate') - >>> c.add_config_file_option(option_name="color", dest="color", type='tristate') - >>> options, args= c.parse_args(['--color=auto']) + >>> c = gbp.config.GbpConfArgParser.create_parser(prog='tristate') + >>> c.add_conf_file_arg("--color", dest="color", type='tristate') + >>> options = c.parse_args(['--color=auto']) >>> options.color auto >>> options.color.is_off() False - >>> c = gbp.config.GbpOptionParser('tristate') - >>> c.add_config_file_option(option_name="color", dest="color", type='tristate') - >>> options, args= c.parse_args(['--color=off']) + >>> c = gbp.config.GbpConfArgParser.create_parser(prog='tristate') + >>> c.add_conf_file_arg("--color", dest="color", type='tristate') + >>> options = c.parse_args(['--color=off']) >>> options.color off >>> options.color.is_off() @@ -78,21 +78,19 @@ def test_filter(): """ The filter option should always parse as a list >>> import os - >>> from gbp.config import GbpOptionParser + >>> from gbp.config import GbpConfig >>> tmpdir = str(context.new_tmpdir('bar')) >>> confname = os.path.join(tmpdir, 'gbp.conf') - >>> GbpOptionParser._set_config_file_value('bar', 'filter', 'asdf', filename=confname) - >>> os.environ['GBP_CONF_FILES'] = confname - >>> parser = GbpOptionParser('bar') - >>> parser.config['filter'] + >>> GbpConfig._set_config_file_value('bar', 'filter', 'asdf', filename=confname) + >>> config = GbpConfig('bar', config_files=[confname]) + >>> config.get_value('filter') ['asdf'] >>> f = open(confname, 'w') >>> ret = f.write("[bar]\\nfilter = ['this', 'is', 'a', 'list']\\n") >>> f.close() - >>> parser = GbpOptionParser('bar') - >>> parser.config['filter'] + >>> config = GbpConfig('bar', config_files=[confname]) + >>> config.get_value('filter') ['this', 'is', 'a', 'list'] - >>> del os.environ['GBP_CONF_FILES'] """ @@ -100,13 +98,13 @@ def test_filters(): """ The filter can be given in plural form >>> import os - >>> from gbp.config import GbpOptionParser + >>> from gbp.config import GbpConfig, GbpConfArgParser >>> tmpdir = str(context.new_tmpdir('bar')) >>> confname = os.path.join(tmpdir, 'gbp.conf') - >>> GbpOptionParser._set_config_file_value('bar', 'filters', '["abc", "def"]\\n', filename=confname) + >>> GbpConfig._set_config_file_value('bar', 'filters', '["abc", "def"]\\n', filename=confname) >>> os.environ['GBP_CONF_FILES'] = confname - >>> parser = GbpOptionParser('bar') - >>> parser.config['filter'] + >>> parser = GbpConfArgParser.create_parser(prog='bar') + >>> parser.config.get_value('filter') ['abc', 'def'] >>> del os.environ['GBP_CONF_FILES'] """ From 3a6db9bca47f0d539974e3a0959b179c2eeba55a Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 28 May 2014 12:23:38 +0300 Subject: [PATCH 2/6] config: allow adding config file arg without help Previously, adding a config file arg with no help resulted in KeyError if no default help text was defined. Now, it is possible to add a config arg without a help text. This makes the argument parser more consistent as adding "non-conf-file-args" requires no help text, either. Signed-off-by: Markus Lehtonen --- gbp/config.py | 2 +- tests/doctests/test_Config.py | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/gbp/config.py b/gbp/config.py index b5c61cd3..2919da0f 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -661,7 +661,7 @@ def add_conf_file_arg(self, *args, **kwargs): else: kwargs['default'] = self.config.get_value(name) self.conf_file_args.add(name) - if 'help' not in kwargs: + if 'help' not in kwargs and name in self.config.default_helps: kwargs['help'] = self.config.default_helps[name] new_arg = self.add_arg(*args, **kwargs) diff --git a/tests/doctests/test_Config.py b/tests/doctests/test_Config.py index 5311f947..482be249 100644 --- a/tests/doctests/test_Config.py +++ b/tests/doctests/test_Config.py @@ -29,10 +29,6 @@ def test_option_parser_debian(): >>> import gbp.config >>> c = gbp.config.GbpConfArgParserDebian.create_parser(prog='debian') - >>> c.add_conf_file_arg('--builder', dest='builder') - Traceback (most recent call last): - ... - KeyError: 'builder' >>> c.add_conf_file_arg('--builder', dest='builder', help='foo') """ From c55b5dcb8599b11fd1c311e5d62b0b8ac142e3f8 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 28 May 2014 12:30:56 +0300 Subject: [PATCH 3/6] GbpConfArgParser.get_conf_file_value: only allow valid options Raise an exception if the queried option is not in the list of valid config file args. Signed-off-by: Markus Lehtonen --- gbp/config.py | 6 +++--- tests/18_test_Config.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gbp/config.py b/gbp/config.py index 2919da0f..eb742c9c 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -708,10 +708,10 @@ def get_conf_file_value(self, option_name): @returns: The config file option value or C{None} if it doesn't exist @rtype: C{str} or C{None} """ - try: + if option_name in self.conf_file_args: return self.config.get_value(option_name) - except KeyError: - return None + else: + raise KeyError("Invalid option: %s" % option_name) class GbpConfigDebian(GbpConfig): diff --git a/tests/18_test_Config.py b/tests/18_test_Config.py index 74f97064..6571b6fb 100644 --- a/tests/18_test_Config.py +++ b/tests/18_test_Config.py @@ -95,9 +95,11 @@ def test_get_conf_file_value(self): Read a single value from the parsed config """ parser = GbpConfArgParser.create_parser(prog='cmd4') + parser.add_conf_file_arg('--new_overrides_git_option1') self.assertEqual(parser.get_conf_file_value('new_overrides_git_option1'), 'new_overrides_git_value1') - self.assertEqual(parser.get_conf_file_value('doesnotexist'), None) + with self.assertRaises(KeyError): + parser.get_conf_file_value('doesnotexist') def test_param_list(self): parser = GbpConfArgParser.create_parser(prog='cmd4') From 6fa93b33d721efb90c464c8691cd70541c6a2882 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Thu, 18 Jan 2018 11:04:19 +0200 Subject: [PATCH 4/6] pq: use argparse subparsers Rework pq and pq-rpm commands to utilize the subparsers (or subcommands) functionality of Python argparse. This changes the calling convention slightly: now the action (export, import, ...) must be the first argument - all other cmdline arguments/options must be given after that. E.g. it is not possible to do 'gbp pq -v export' anymore, but, one must use 'gbp pq export -v'. Signed-off-by: Markus Lehtonen --- gbp/config.py | 12 +++ gbp/scripts/pq.py | 131 ++++++++++++++-------------- gbp/scripts/pq_rpm.py | 133 +++++++++++++++-------------- tests/component/rpm/test_pq_rpm.py | 33 +++---- 4 files changed, 163 insertions(+), 146 deletions(-) diff --git a/gbp/config.py b/gbp/config.py index eb742c9c..f36546db 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -696,6 +696,18 @@ def add_mutually_exclusive_group(self, *args, **kwargs): return self._wrap_generator('add_mutually_exclusive_group', *args, **kwargs) + def add_subparsers(self, *args, **kwargs): + """Add subparsers""" + return self._wrap_generator('add_subparsers', *args, **kwargs) + + def add_parser(self, *args, **kwargs): + """Add parser. Only valid for subparser instances!""" + if 'parents' in kwargs: + for parser in kwargs['parents']: + self.conf_file_args.update(parser.conf_file_args) + return self._wrap_generator('add_parser', + *args, **kwargs) + def __getattr__(self, name): return self.wrapped.__getattribute__(name) diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index be99b6aa..21f8a468 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -23,7 +23,6 @@ import sys import tempfile import re -from argparse import ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter from gbp.config import GbpConfArgParserDebian from gbp.deb.source import DebianSource from gbp.deb.git import DebianGitRepository @@ -397,93 +396,95 @@ def switch_pq(repo, branch, options): switch_to_pq_branch(repo, branch) -class GbpPqHelpFormatter(RawDescriptionHelpFormatter, - ArgumentDefaultsHelpFormatter): - pass - - -def descr_msg(): - return """Maintain patches on a patch queue branch -Actions: - export export the patch queue associated to the current branch - into a quilt patch series in debian/patches/ and update the - series file. - import create a patch queue branch from quilt patches in debian/patches. - rebase switch to patch queue branch associated to the current - branch and rebase against current branch. - drop drop (delete) the patch queue associated to the current branch. - apply apply a patch - switch switch to patch-queue branch and vice versa""" - - def build_parser(name): - usage = "%(prog)s [options] action" + description = "Maintain patches on a patch queue branch" + usage = "%(prog)s [-h] [--version] ACTION [options]" + epilog = "See '%(prog)s ACTION --help' for action-specific options" try: parser = GbpConfArgParserDebian.create_parser(prog=name, usage=usage, - description=descr_msg(), - formatter_class=GbpPqHelpFormatter) + description=description, + epilog=epilog) + _parent = GbpConfArgParserDebian.create_parser(prog=name, + add_help=False) except GbpError as err: gbp.log.err(err) return None - parser.add_bool_conf_file_arg("--patch-numbers", dest="patch_numbers") - parser.add_conf_file_arg("--patch-num-format", dest="patch_num_format") - parser.add_bool_conf_file_arg("--renumber", dest="renumber") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, - help="verbose command execution") - parser.add_arg("--topic", dest="topic", help="in case of 'apply' topic (subdir) to put patch into") - parser.add_conf_file_arg("--time-machine", dest="time_machine", type=int) - parser.add_bool_conf_file_arg("--drop", dest='drop') - parser.add_bool_conf_file_arg("--commit", dest="commit") - parser.add_conf_file_arg("--abbrev", dest="abbrev", type=int) - parser.add_arg("--force", dest="force", action="store_true", default=False, - help="in case of import even import if the branch already exists") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - parser.add_conf_file_arg("--meta-closes", dest="meta_closes") - parser.add_conf_file_arg("--meta-closes-bugnum", dest="meta_closes_bugnum") - parser.add_conf_file_arg("--pq-from", dest="pq_from", choices=['DEBIAN', 'TAG']) - parser.add_conf_file_arg("--upstream-tag", dest="upstream_tag") + # Add common arguments + _parent.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + _parent.add_conf_file_arg("--color", dest="color", type='tristate') + _parent.add_conf_file_arg("--color-scheme", + dest="color_scheme") + _parent.add_conf_file_arg("--pq-from", dest="pq_from", choices=['DEBIAN', 'TAG']) + _parent.add_conf_file_arg("--upstream-tag", dest="upstream_tag") + _parent.add_arg("--force", dest="force", action="store_true", default=False, + help="in case of import even import if the branch already exists") + _parent.add_conf_file_arg("--time-machine", dest="time_machine", type=int) + + # Add subcommands + subparsers = parser.add_subparsers(title='actions', dest='action') + + # Export + _parser = subparsers.add_parser('export', parents=[_parent], + help="export the patch queue associated to the current " + "branch into a quilt patch series in debian/patches/ " + "and update the series file.") + _parser.add_bool_conf_file_arg("--patch-numbers", dest="patch_numbers") + _parser.add_conf_file_arg("--patch-num-format", dest="patch_num_format") + _parser.add_bool_conf_file_arg("--renumber", dest="renumber") + _parser.add_bool_conf_file_arg("--drop", dest='drop') + _parser.add_bool_conf_file_arg("--commit", dest="commit") + _parser.add_conf_file_arg("--abbrev", dest="abbrev", type=int) + _parser.add_conf_file_arg("--meta-closes", dest="meta_closes") + _parser.add_conf_file_arg("--meta-closes-bugnum", dest="meta_closes_bugnum") + # Import + _parser = subparsers.add_parser('import', parents=[_parent], + help="create a patch queue branch from" + "quilt patches in debian/patches.") + # Rebase + _parser = subparsers.add_parser('rebase', parents=[_parent], + help="switch to patch queue branch associated to the current " + "branch and rebase against current branch.") + # Drop + _parser = subparsers.add_parser('drop', parents=[_parent], + help="drop (delete) the patch queue " + "associated to the current branch.") + # Apply + _parser = subparsers.add_parser('apply', parents=[_parent], + help="apply a patch") + _parser.add_arg("--topic", dest="topic", help="in case of 'apply' topic (subdir) to put patch into") + _parser.add_argument("patch", metavar="PATCH", help="Patch to apply") + # Switch + _parser = subparsers.add_parser('switch', parents=[_parent], + help="switch to patch-queue branch and vice versa") + return parser def parse_args(argv): parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None - return parser.parse_known_args(argv[1:]) + return None + + args = parser.parse_args(argv[1:]) + + if args.action is None: + parser.error("You need to specify an action") + return args def main(argv): retval = 0 - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) - if len(args) < 1: - gbp.log.err("No action given.") - return 1 - else: - action = args[0] - - if action in ["export", "import", "rebase", "drop", "switch"]: - if len(args) != 1: - gbp.log.err("Invalid options: %s" % ", ".join(args[1:])) - return 1 - elif action in ["apply"]: - if len(args) != 2: - gbp.log.err("No patch name given.") - return 1 - else: - patchfile = args[1] - else: - gbp.log.err("Unknown action '%s'." % action) - return 1 + action = options.action try: repo = DebianGitRepository(os.path.curdir) @@ -502,7 +503,7 @@ def main(argv): elif action == "rebase": rebase_pq(repo, current, options) elif action == "apply": - patch = Patch(patchfile) + patch = Patch(options.patch) maintainer = get_maintainer_from_control(repo) apply_single_patch(repo, current, patch, maintainer, options.topic) elif action == "switch": diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 2aa03130..089add74 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -24,7 +24,6 @@ import os import re import sys -from argparse import ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter import gbp.log from gbp.tmpfile import init_tmpdir, del_tmpdir, tempfile @@ -363,57 +362,72 @@ def switch_pq(repo, current): switch_to_pq_branch(repo, current) -class GbpPqRpmHelpFormatter(RawDescriptionHelpFormatter, - ArgumentDefaultsHelpFormatter): - pass - - -def descr_msg(): - return """Maintain patches on a patch queue branch -Actions: -export Export the patch queue / devel branch associated to the - current branch into a patch series in and update the spec file -import Create a patch queue / devel branch from spec file - and patches in current dir. -rebase Switch to patch queue / devel branch associated to the current - branch and rebase against upstream. -drop Drop (delete) the patch queue /devel branch associated to - the current branch. -apply Apply a patch -switch Switch to patch-queue branch and vice versa.""" - - def build_parser(name): """Construct command line parser""" - usage = "%(prog)s [options] action" + description = "maintain patches on a patch queue branch" + usage = "%(prog)s [-h] [--version] ACTION [options]" + epilog = "See '%(prog)s ACTION --help' for action-specific options" + try: parser = GbpConfArgParserRpm.create_parser(prog=name, usage=usage, - description=descr_msg(), - formatter_class=GbpPqRpmHelpFormatter) + description=description, + epilog=epilog) + _parent = GbpConfArgParserRpm.create_parser(prog=name, + add_help=False) except GbpError as err: gbp.log.err(err) return None - parser.add_bool_conf_file_arg("--patch-numbers", - dest="patch_numbers") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", - default=False, help="Verbose command execution") - parser.add_arg("--force", dest="force", action="store_true", - default=False, - help="In case of import even import if the branch already exists") - parser.add_bool_conf_file_arg("--drop", dest="drop") - parser.add_conf_file_arg("--color", dest="color", - type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") - parser.add_conf_file_arg("--abbrev", dest="abbrev", type=int) - parser.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") - parser.add_conf_file_arg("--spec-file", dest="spec_file") - parser.add_conf_file_arg("--packaging-dir", - dest="packaging_dir") + # Add common arguments + _parent.add_arg("-v", "--verbose", action="store_true", dest="verbose", + default=False, help="Verbose command execution") + _parent.add_conf_file_arg("--color", dest="color", + type='tristate') + _parent.add_conf_file_arg("--color-scheme", + dest="color_scheme") + _parent.add_conf_file_arg("--tmp-dir", dest="tmp_dir") + _parent.add_conf_file_arg("--upstream-tag", + dest="upstream_tag") + _parent.add_conf_file_arg("--spec-file", dest="spec_file") + _parent.add_conf_file_arg("--packaging-dir", + dest="packaging_dir") + + # Add subcommands + subparsers = parser.add_subparsers(title='actions', dest='action') + + # Export + _parser = subparsers.add_parser('export', parents=[_parent], + help="Export the patch queue / devel branch associated to the " + "current branch into a patch series in and update the spec " + "file") + _parser.add_bool_conf_file_arg("--patch-numbers", + dest="patch_numbers") + _parser.add_conf_file_arg("--abbrev", dest="abbrev", type=int) + _parser.add_bool_conf_file_arg("--drop", dest="drop") + # Import + _parser = subparsers.add_parser('import', parents=[_parent], + help="Create a patch queue / devel branch from spec file " + "and patches in current dir.") + _parser.add_arg("--force", dest="force", action="store_true", + default=False, + help="In case of import even import if the branch already exists") + # Rebase + _parser = subparsers.add_parser('rebase', parents=[_parent], + help="Switch to patch queue / devel branch associated to the " + "current branch and rebase against upstream.") + # Drop + _parser = subparsers.add_parser('drop', parents=[_parent], + help="Drop (delete) the patch queue /devel branch associated " + "to the current branch.") + # Apply + _parser = subparsers.add_parser('apply', parents=[_parent], + help="Apply a patch") + _parser.add_argument("patch", metavar="PATCH", help="Patch to apply") + # Switch + _parser = subparsers.add_parser('switch', parents=[_parent], + help="Switch to patch-queue branch and vice versa.") + return parser @@ -421,39 +435,26 @@ def parse_args(argv): """Parse command line arguments""" parser = build_parser(os.path.basename(argv[0])) if not parser: - return None, None - return parser.parse_known_args(argv[1:]) + return None + + args = parser.parse_args(argv[1:]) + + if args.action is None: + parser.error("You need to specify an action") + return args def main(argv): """Main function for the gbp pq-rpm command""" retval = 0 - (options, args) = parse_args(argv) + options = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) - if len(args) < 1: - gbp.log.err("No action given.") - return 1 - else: - action = args[0] - - if action in ["export", "import", "rebase", "drop", "switch", "convert"]: - if len(args) != 1: - gbp.log.err("Invalid options: %s" % ", ".join(args[1:])) - return 1 - elif action in ["apply"]: - if len(args) != 2: - gbp.log.err("No patch name given.") - return 1 - else: - patchfile = args[1] - else: - gbp.log.err("Unknown action '%s'." % action) - return 1 + action = options.action try: repo = RpmGitRepository(os.path.curdir) @@ -474,7 +475,7 @@ def main(argv): elif action == "rebase": rebase_pq(repo, options) elif action == "apply": - patch = Patch(patchfile) + patch = Patch(options.patch) apply_single_patch(repo, current, patch, fallback_author=None) elif action == "switch": switch_pq(repo, current) diff --git a/tests/component/rpm/test_pq_rpm.py b/tests/component/rpm/test_pq_rpm.py index 3eff5218..1dac04aa 100644 --- a/tests/component/rpm/test_pq_rpm.py +++ b/tests/component/rpm/test_pq_rpm.py @@ -18,7 +18,7 @@ import os import tempfile -from nose.tools import eq_, ok_ # pylint: disable=E0611 +from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611 from gbp.scripts.pq_rpm import main as pq from gbp.git import GitRepository @@ -49,20 +49,21 @@ def _has_patches(self, specfile, patches): def test_invalid_args(self): """See that pq-rpm fails gracefully when called with invalid args""" GitRepository.create('.') - # Test empty args - eq_(mock_pq([]), 1) - self._check_log(0, 'gbp:error: No action given.') - self._clear_log() + with capture_stderr(): + # Test empty args + with assert_raises(SystemExit) as err: + eq_(mock_pq([]), 1) + eq_(err.code, 2) - # Test invalid command - eq_(mock_pq(['mycommand']), 1) - self._check_log(0, "gbp:error: Unknown action 'mycommand'") - self._clear_log() + # Test invalid command + with assert_raises(SystemExit) as err: + eq_(mock_pq(['mycommand']), 1) + eq_(err.code, 2) - # Test invalid cmdline options - with capture_stderr(): - eq_(mock_pq(['export', '--invalid-arg=123']), 1) - self._check_log(0, "gbp:error: Invalid options: --invalid-arg=123") + # Test invalid cmdline options + with assert_raises(SystemExit) as err: + eq_(mock_pq(['export', '--invalid-arg=123']), 1) + eq_(err.code, 2) def test_import_outside_repo(self): """Run pq-rpm when not in a git repository""" @@ -234,8 +235,10 @@ def test_apply(self): branches = repo.get_local_branches() + ['patch-queue/master'] # No patch given - eq_(mock_pq(['apply']), 1) - self._check_log(-1, "gbp:error: No patch name given.") + with capture_stderr(): + with assert_raises(SystemExit) as err: + eq_(mock_pq(['apply']), 1) + eq_(err.code, 2) # Create a pristine pq-branch repo.create_branch('patch-queue/master', 'upstream') From 30ebb97dfcfbefd547fb4a4e51393a01e4ec7917 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Mon, 15 Jan 2018 11:32:45 +0200 Subject: [PATCH 5/6] scripts: drop redundant argparser 'default' args There is no need to provide a default when 'store_true' or 'store_false' action is used. Signed-off-by: Markus Lehtonen --- gbp/scripts/buildpackage.py | 8 ++++---- gbp/scripts/buildpackage_rpm.py | 6 ++---- gbp/scripts/clone.py | 4 ++-- gbp/scripts/create_remote_repo.py | 1 - gbp/scripts/dch.py | 22 +++++++++++----------- gbp/scripts/export_orig.py | 2 +- gbp/scripts/import_dsc.py | 8 ++++---- gbp/scripts/import_orig.py | 4 ++-- gbp/scripts/import_ref.py | 2 +- gbp/scripts/import_srpm.py | 11 +++++------ gbp/scripts/pq.py | 4 ++-- gbp/scripts/pq_rpm.py | 3 +-- gbp/scripts/pristine_tar.py | 2 +- gbp/scripts/push.py | 4 ++-- gbp/scripts/rpm_ch.py | 2 +- gbp/scripts/tag.py | 4 ++-- 16 files changed, 41 insertions(+), 46 deletions(-) diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index e2e4e163..a84c9e50 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -353,17 +353,17 @@ def build_parser(name, prefix=None): "alternative build tree related options") parser.add_bool_conf_file_arg("--ignore-new", dest="ignore_new") - parser.add_arg("--verbose", action="store_true", dest="verbose", default=False, + parser.add_arg("--verbose", action="store_true", dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", dest="color_scheme") parser.add_conf_file_arg("--notify", dest="notify", type='tristate') - tag_group.add_arg("--tag", action="store_true", dest="tag", default=False, + tag_group.add_arg("--tag", action="store_true", dest="tag", help="create a tag after a successful build") - tag_group.add_arg("--tag-only", action="store_true", dest="tag_only", default=False, + tag_group.add_arg("--tag-only", action="store_true", dest="tag_only", help="don't build, only tag and run the posttag hook") - tag_group.add_arg("--retag", action="store_true", dest="retag", default=False, + tag_group.add_arg("--retag", action="store_true", dest="retag", help="don't fail if the tag already exists") tag_group.add_bool_conf_file_arg("--sign-tags", dest="sign_tags") tag_group.add_conf_file_arg("--keyid", dest="keyid") diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index 06fcd84d..70f4e217 100644 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -324,7 +324,7 @@ def build_parser(name, prefix=None, git_treeish=None): parser.add_bool_conf_file_arg("--ignore-new", dest="ignore_new") parser.add_arg("--verbose", action="store_true", dest="verbose", - default=False, help="verbose command execution") + help="verbose command execution") parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") parser.add_conf_file_arg("--color", dest="color", type='tristate') @@ -337,13 +337,11 @@ def build_parser(name, prefix=None, git_treeish=None): parser.add_conf_file_arg("--native", dest="native", type='tristate') tag_group.add_arg("--tag", action="store_true", dest="tag", - default=False, help="create a tag after a successful build") tag_group.add_arg("--tag-only", action="store_true", dest="tag_only", - default=False, help="don't build, only tag and run the posttag hook") tag_group.add_arg("--retag", action="store_true", dest="retag", - default=False, help="don't fail if the tag already exists") + help="don't fail if the tag already exists") tag_group.add_bool_conf_file_arg("--sign-tags", dest="sign_tags") tag_group.add_conf_file_arg("--keyid", dest="keyid") diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py index 287129e4..ee4baf12 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -109,7 +109,7 @@ def build_parser(name): branch_group = parser.add_argument_group("branch options", "branch tracking and layout options") cmd_group = parser.add_argument_group("external command options", "how and when to invoke hooks") - branch_group.add_arg("--all", action="store_true", dest="all", default=False, + branch_group.add_arg("--all", action="store_true", dest="all", help="track all branches, not only debian and upstream") branch_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") branch_group.add_conf_file_arg("--debian-branch", dest="debian_branch") @@ -122,7 +122,7 @@ def build_parser(name): help="hook to run after cloning the source tree") cmd_group.add_bool_conf_file_arg("--hooks", dest="hooks") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", dest="color_scheme") diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py index 7a41eff3..66e65e3b 100644 --- a/gbp/scripts/create_remote_repo.py +++ b/gbp/scripts/create_remote_repo.py @@ -245,7 +245,6 @@ def build_parser(name, sections=[]): parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", - default=False, help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index a6876965..6ab86551 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -352,36 +352,36 @@ def build_parser(name): help="expression to determine the next snapshot number") parser.add_conf_file_arg("--git-log", dest="git_log", help="options to pass to git-log") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", dest="color_scheme") range_group.add_arg("-s", "--since", dest="since", help="commit to start from (e.g. HEAD^^^, debian/0.4.3)") - range_group.add_arg("-a", "--auto", action="store_true", dest="auto", default=False, + range_group.add_arg("-a", "--auto", action="store_true", dest="auto", help="autocomplete changelog from last snapshot or tag") - version_group.add_arg("-R", "--release", action="store_true", dest="release", default=False, + version_group.add_arg("-R", "--release", action="store_true", dest="release", help="mark as release") - version_group.add_arg("-S", "--snapshot", action="store_true", dest="snapshot", default=False, + version_group.add_arg("-S", "--snapshot", action="store_true", dest="snapshot", help="mark as snapshot build") version_group.add_arg("-D", "--distribution", dest="distribution", help="Set distribution") - version_group.add_arg("--force-distribution", action="store_true", dest="force_distribution", default=False, + version_group.add_arg("--force-distribution", action="store_true", dest="force_distribution", help="Force the provided distribution to be used, " "even if it doesn't match the list of known distributions") version_group.add_arg("-N", "--new-version", dest="new_version", help="use this as base for the new version number") version_group.add_conf_file_arg("--urgency", dest="urgency") - version_group.add_arg("--bpo", dest="bpo", action="store_true", default=False, + version_group.add_arg("--bpo", dest="bpo", action="store_true", help="Increment the Debian release number for an upload to backports, " "and add a backport upload changelog comment.") - version_group.add_arg("--nmu", dest="nmu", action="store_true", default=False, + version_group.add_arg("--nmu", dest="nmu", action="store_true", help="Increment the Debian release number for a non-maintainer upload") - version_group.add_arg("--qa", dest="qa", action="store_true", default=False, + version_group.add_arg("--qa", dest="qa", action="store_true", help="Increment the Debian release number for a Debian QA Team upload, " "and add a QA upload changelog comment.") - version_group.add_arg("--team", dest="team", action="store_true", default=False, + version_group.add_arg("--team", dest="team", action="store_true", help="Increment the Debian release number for a Debian Team upload, " "and add a Team upload changelog comment.") - version_group.add_arg("--security", dest="security", action="store_true", default=False, + version_group.add_arg("--security", dest="security", action="store_true", help="Increment the Debian release number for a security upload and " "add a security upload changelog comment.") version_group.add_bool_conf_file_arg("--git-author", dest="use_git_author") @@ -399,7 +399,7 @@ def build_parser(name): commit_group.add_conf_file_arg("--spawn-editor", dest="spawn_editor") parser.add_conf_file_arg("--commit-msg", dest="commit_msg") - parser.add_arg("-c", "--commit", action="store_true", dest="commit", default=False, + parser.add_arg("-c", "--commit", action="store_true", dest="commit", help="commit changelog file after generating") parser.add_conf_file_arg("--dch-opt", dest="dch_opts", action="append", help="option to pass to dch verbatim, " diff --git a/gbp/scripts/export_orig.py b/gbp/scripts/export_orig.py index 2676b37b..5643bb9b 100755 --- a/gbp/scripts/export_orig.py +++ b/gbp/scripts/export_orig.py @@ -275,7 +275,7 @@ def build_parser(name): branch_group = parser.add_argument_group("branch options", "branch layout options") - parser.add_arg("--verbose", action="store_true", dest="verbose", default=False, + parser.add_arg("--verbose", action="store_true", dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py index e1c12db2..ce323e23 100644 --- a/gbp/scripts/import_dsc.py +++ b/gbp/scripts/import_dsc.py @@ -320,7 +320,7 @@ def build_parser(name): branch_group = parser.add_argument_group("version and branch naming options", "version number and branch layout options") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", @@ -341,7 +341,7 @@ def build_parser(name): tag_group.add_conf_file_arg("--upstream-tag", dest="upstream_tag") tag_group.add_arg("--skip-debian-tag", dest="skip_debian_tag", - action="store_true", default=False, + action="store_true", help="Don't add a tag after importing the Debian patch") import_group.add_conf_file_arg("--filter", @@ -349,7 +349,7 @@ def build_parser(name): import_group.add_bool_conf_file_arg("--pristine-tar", dest="pristine_tar") import_group.add_arg("--allow-same-version", action="store_true", - dest="allow_same_version", default=False, + dest="allow_same_version", help="allow import of already imported version") import_group.add_bool_conf_file_arg("--author-is-committer", dest="author_committer") @@ -363,7 +363,7 @@ def build_parser(name): parser.add_conf_file_arg("--repo-email", dest="repo_email", choices=['DEBIAN', 'GIT']) parser.add_arg("--download", dest='download', action="store_true", - default=False, help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-dsc(1).") + help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-dsc(1).") parser.add_argument("package", metavar="PACKAGE", help="package to import") parser.add_argument("target_dir", metavar="TARGET_DIR", nargs="?", diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 253a7645..f988970c 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -349,7 +349,7 @@ def build_parser(name): dest='interactive') parser.add_bool_conf_file_arg("--rollback", dest="rollback") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", @@ -357,7 +357,7 @@ def build_parser(name): # Accepted for compatibility parser.add_arg("--download", dest='download', action="store_true", - default=False, help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-orig(1).") + help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-orig(1).") src_group = parser.add_mutually_exclusive_group(required=True) src_group.add_arg("--uscan", action="store_true", diff --git a/gbp/scripts/import_ref.py b/gbp/scripts/import_ref.py index 7141bedd..2ab2acd3 100644 --- a/gbp/scripts/import_ref.py +++ b/gbp/scripts/import_ref.py @@ -97,7 +97,7 @@ def build_parser(name): parser.add_bool_conf_file_arg("--rollback", dest="rollback") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py index c02b8586..0e166e54 100755 --- a/gbp/scripts/import_srpm.py +++ b/gbp/scripts/import_srpm.py @@ -134,7 +134,7 @@ def build_parser(name): "version number and branch layout options") parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", - default=False, help="verbose command execution") + help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", @@ -143,7 +143,7 @@ def build_parser(name): parser.add_conf_file_arg("--vendor", action="store", dest="vendor") parser.add_arg("--download", action="store_true", dest="download", - default=False, help="download source package") + help="download source package") branch_group.add_conf_file_arg("--packaging-branch", dest="packaging_branch") branch_group.add_conf_file_arg("--upstream-branch", @@ -154,10 +154,9 @@ def build_parser(name): branch_group.add_bool_conf_file_arg("--create-missing-branches", dest="create_missing_branches") branch_group.add_arg("--orphan-packaging", action="store_true", - dest="orphan_packaging", default=False, + dest="orphan_packaging", help="The packaging branch doesn't base on upstream") - branch_group.add_arg("--native", action="store_true", - dest="native", default=False, + branch_group.add_arg("--native", action="store_true", dest="native", help="This is a dist native package, no separate " "upstream branch") @@ -178,7 +177,7 @@ def build_parser(name): import_group.add_bool_conf_file_arg("--pristine-tar", dest="pristine_tar") import_group.add_arg("--allow-same-version", action="store_true", - dest="allow_same_version", default=False, + dest="allow_same_version", help="allow import of already imported version") import_group.add_bool_conf_file_arg("--author-is-committer", dest="author_is_committer") diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 21f8a468..59dad643 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -412,14 +412,14 @@ def build_parser(name): return None # Add common arguments - _parent.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + _parent.add_arg("-v", "--verbose", action="store_true", dest="verbose", help="verbose command execution") _parent.add_conf_file_arg("--color", dest="color", type='tristate') _parent.add_conf_file_arg("--color-scheme", dest="color_scheme") _parent.add_conf_file_arg("--pq-from", dest="pq_from", choices=['DEBIAN', 'TAG']) _parent.add_conf_file_arg("--upstream-tag", dest="upstream_tag") - _parent.add_arg("--force", dest="force", action="store_true", default=False, + _parent.add_arg("--force", dest="force", action="store_true", help="in case of import even import if the branch already exists") _parent.add_conf_file_arg("--time-machine", dest="time_machine", type=int) diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 089add74..71ae3605 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -381,7 +381,7 @@ def build_parser(name): # Add common arguments _parent.add_arg("-v", "--verbose", action="store_true", dest="verbose", - default=False, help="Verbose command execution") + help="Verbose command execution") _parent.add_conf_file_arg("--color", dest="color", type='tristate') _parent.add_conf_file_arg("--color-scheme", @@ -410,7 +410,6 @@ def build_parser(name): help="Create a patch queue / devel branch from spec file " "and patches in current dir.") _parser.add_arg("--force", dest="force", action="store_true", - default=False, help="In case of import even import if the branch already exists") # Rebase _parser = subparsers.add_parser('rebase', parents=[_parent], diff --git a/gbp/scripts/pristine_tar.py b/gbp/scripts/pristine_tar.py index 80de1d66..d313b714 100644 --- a/gbp/scripts/pristine_tar.py +++ b/gbp/scripts/pristine_tar.py @@ -53,7 +53,7 @@ def build_parser(name): dest="upstream_tag") parser.add_conf_file_arg("--component", action="append", metavar='COMPONENT', dest="components") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", default=False, + parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", dest="color", type='tristate') parser.add_conf_file_arg("--color-scheme", diff --git a/gbp/scripts/push.py b/gbp/scripts/push.py index e79bd168..49e3b58f 100755 --- a/gbp/scripts/push.py +++ b/gbp/scripts/push.py @@ -36,7 +36,7 @@ def build_parser(name): gbp.log.err(err) return None - parser.add_arg("-d", "--dry-run", dest="dryrun", default=False, + parser.add_arg("-d", "--dry-run", dest="dryrun", action="store_true", help="dry run, don't push.") parser.add_conf_file_arg("--upstream-branch", dest="upstream_branch") @@ -53,7 +53,7 @@ def build_parser(name): parser.add_conf_file_arg("--color-scheme", dest="color_scheme") parser.add_arg("--verbose", action="store_true", dest="verbose", - default=False, help="verbose command execution") + help="verbose command execution") parser.add_argument("remote", metavar="REMOTE", nargs="?", help="remote where to push") return parser diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py index 77677814..f3306fd4 100644 --- a/gbp/scripts/rpm_ch.py +++ b/gbp/scripts/rpm_ch.py @@ -356,7 +356,7 @@ def build_parser(name): range_grp.add_arg("-s", "--since", dest="since", help="commit to start from (e.g. HEAD^^^, release/0.1.2)") # Formatting group options - format_grp.add_arg("--no-release", action="store_false", default=True, + format_grp.add_arg("--no-release", action="store_false", dest="release", help="no release, just update the last changelog section") format_grp.add_bool_conf_file_arg("--git-author", diff --git a/gbp/scripts/tag.py b/gbp/scripts/tag.py index 7a0ef3cd..adf2e81a 100755 --- a/gbp/scripts/tag.py +++ b/gbp/scripts/tag.py @@ -85,7 +85,7 @@ def build_parser(name): gbp.log.err(err) return None - parser.add_arg("--retag", action="store_true", dest="retag", default=False, + parser.add_arg("--retag", action="store_true", dest="retag", help="don't fail if the tag already exists") parser.add_conf_file_arg("--debian-branch", dest="debian_branch") @@ -102,7 +102,7 @@ def build_parser(name): parser.add_conf_file_arg("--color-scheme", dest="color_scheme") parser.add_arg("--verbose", action="store_true", dest="verbose", - default=False, help="verbose command execution") + help="verbose command execution") return parser From 37147bf5efa3e1a0f77e2dd9d2c35df72ff65c38 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Mon, 15 Jan 2018 12:19:07 +0200 Subject: [PATCH 6/6] scripts: drop redundant argparser 'dest' args These are the defaults automatically provided by argparse. This hopefully slightly improves readability of the code. Signed-off-by: Markus Lehtonen --- gbp/scripts/buildpackage.py | 73 ++++++++++----------- gbp/scripts/buildpackage_rpm.py | 104 ++++++++++++------------------ gbp/scripts/clone.py | 28 ++++---- gbp/scripts/create_remote_repo.py | 26 +++----- gbp/scripts/dch.py | 67 ++++++++++--------- gbp/scripts/export_orig.py | 19 +++--- gbp/scripts/import_dsc.py | 50 ++++++-------- gbp/scripts/import_orig.py | 50 ++++++-------- gbp/scripts/import_ref.py | 37 ++++------- gbp/scripts/import_srpm.py | 59 ++++++----------- gbp/scripts/pq.py | 33 +++++----- gbp/scripts/pq_rpm.py | 27 ++++---- gbp/scripts/pristine_tar.py | 10 ++- gbp/scripts/pull.py | 2 +- gbp/scripts/push.py | 24 +++---- gbp/scripts/rpm_ch.py | 48 ++++++-------- gbp/scripts/tag.py | 27 ++++---- 17 files changed, 281 insertions(+), 403 deletions(-) diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index a84c9e50..2eb1841e 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -352,33 +352,31 @@ def build_parser(name, prefix=None): export_group = parser.add_argument_group("export build-tree options", "alternative build tree related options") - parser.add_bool_conf_file_arg("--ignore-new", dest="ignore_new") - parser.add_arg("--verbose", action="store_true", dest="verbose", + parser.add_bool_conf_file_arg("--ignore-new") + parser.add_arg("--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - parser.add_conf_file_arg("--notify", dest="notify", type='tristate') - tag_group.add_arg("--tag", action="store_true", dest="tag", + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + parser.add_conf_file_arg("--notify", type='tristate') + tag_group.add_arg("--tag", action="store_true", help="create a tag after a successful build") - tag_group.add_arg("--tag-only", action="store_true", dest="tag_only", + tag_group.add_arg("--tag-only", action="store_true", help="don't build, only tag and run the posttag hook") - tag_group.add_arg("--retag", action="store_true", dest="retag", + tag_group.add_arg("--retag", action="store_true", help="don't fail if the tag already exists") - tag_group.add_bool_conf_file_arg("--sign-tags", dest="sign_tags") - tag_group.add_conf_file_arg("--keyid", dest="keyid") - tag_group.add_conf_file_arg("--debian-tag", dest="debian_tag") - tag_group.add_conf_file_arg("--debian-tag-msg", dest="debian_tag_msg") - tag_group.add_conf_file_arg("--upstream-tag", dest="upstream_tag") - orig_group.add_conf_file_arg("--upstream-tree", dest="upstream_tree") - orig_group.add_bool_conf_file_arg("--pristine-tar", dest="pristine_tar") - orig_group.add_bool_conf_file_arg("--pristine-tar-commit", - dest="pristine_tar_commit") - orig_group.add_conf_file_arg("--force-create", dest="force_create", + tag_group.add_bool_conf_file_arg("--sign-tags") + tag_group.add_conf_file_arg("--keyid") + tag_group.add_conf_file_arg("--debian-tag") + tag_group.add_conf_file_arg("--debian-tag-msg") + tag_group.add_conf_file_arg("--upstream-tag") + orig_group.add_conf_file_arg("--upstream-tree") + orig_group.add_bool_conf_file_arg("--pristine-tar") + orig_group.add_bool_conf_file_arg("--pristine-tar-commit") + orig_group.add_conf_file_arg("--force-create", help="force creation of orig tarball", action="store_true") - orig_group.add_conf_file_arg("--no-create-orig", dest="no_create_orig", + orig_group.add_conf_file_arg("--no-create-orig", help="don't create orig tarball", action="store_true") - orig_group.add_conf_file_arg("--tarball-dir", dest="tarball_dir", type="path", + orig_group.add_conf_file_arg("--tarball-dir", type="path", help="location to look for external tarballs") orig_group.add_conf_file_arg("--compression", dest="comp_type", help="Compression type") @@ -386,38 +384,37 @@ def build_parser(name, prefix=None): help="Compression level") orig_group.add_conf_file_arg("--component", action="append", metavar='COMPONENT', dest="components") - branch_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") - branch_group.add_conf_file_arg("--debian-branch", dest="debian_branch") - branch_group.add_bool_conf_file_arg("--ignore-branch", dest="ignore_branch") + branch_group.add_conf_file_arg("--upstream-branch") + branch_group.add_conf_file_arg("--debian-branch") + branch_group.add_bool_conf_file_arg("--ignore-branch") branch_group.add_bool_conf_file_arg("--submodules", dest="with_submodules") - cmd_group.add_conf_file_arg("--builder", dest="builder", + cmd_group.add_conf_file_arg("--builder", help="command to build the Debian package") - cmd_group.add_conf_file_arg("--cleaner", dest="cleaner", + cmd_group.add_conf_file_arg("--cleaner", help="command to clean the working copy") - cmd_group.add_conf_file_arg("--prebuild", dest="prebuild", + cmd_group.add_conf_file_arg("--prebuild", help="hook to run before a build") - cmd_group.add_conf_file_arg("--postexport", dest="postexport", + cmd_group.add_conf_file_arg("--postexport", help="hook to run after exporting the source tree") - cmd_group.add_conf_file_arg("--postbuild", dest="postbuild", + cmd_group.add_conf_file_arg("--postbuild", help="hook run after a successful build") - cmd_group.add_conf_file_arg("--posttag", dest="posttag", + cmd_group.add_conf_file_arg("--posttag", help="hook run after a successful tag operation") cmd_group.add_bool_conf_file_arg("--pbuilder", dest="use_pbuilder") cmd_group.add_bool_conf_file_arg("--qemubuilder", dest="use_qemubuilder") cmd_group.add_conf_file_arg("--dist", dest="pbuilder_dist") cmd_group.add_conf_file_arg("--arch", dest="pbuilder_arch") - cmd_group.add_bool_conf_file_arg("--pbuilder-autoconf", - dest="pbuilder_autoconf") - cmd_group.add_conf_file_arg("--pbuilder-options", dest="pbuilder_options") - cmd_group.add_bool_conf_file_arg("--hooks", dest="hooks") - export_group.add_conf_file_arg("--export-dir", dest="export_dir", type="path", + cmd_group.add_bool_conf_file_arg("--pbuilder-autoconf") + cmd_group.add_conf_file_arg("--pbuilder-options") + cmd_group.add_bool_conf_file_arg("--hooks") + export_group.add_conf_file_arg("--export-dir", type="path", help="before building the package export " "the source into EXPORT_DIR") - export_group.add_conf_file_arg("--export", dest="export", + export_group.add_conf_file_arg("--export", help="export treeish object TREEISH", metavar="TREEISH") - export_group.add_bool_conf_file_arg("--purge", dest="purge") - export_group.add_bool_conf_file_arg("--overlay", dest="overlay") + export_group.add_bool_conf_file_arg("--purge") + export_group.add_bool_conf_file_arg("--overlay") return parser diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index 70f4e217..8e0afd8f 100644 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -321,100 +321,76 @@ def build_parser(name, prefix=None, git_treeish=None): export_group = parser.add_argument_group("export build-tree options", "alternative build tree related options") - parser.add_bool_conf_file_arg("--ignore-new", - dest="ignore_new") - parser.add_arg("--verbose", action="store_true", dest="verbose", + parser.add_bool_conf_file_arg("--ignore-new") + parser.add_arg("--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") - parser.add_conf_file_arg("--color", dest="color", + parser.add_conf_file_arg("--tmp-dir") + parser.add_conf_file_arg("--color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - parser.add_conf_file_arg("--notify", dest="notify", + parser.add_conf_file_arg("--color-scheme") + parser.add_conf_file_arg("--notify", type='tristate') - parser.add_conf_file_arg("--vendor", action="store", - dest="vendor") - parser.add_conf_file_arg("--native", dest="native", + parser.add_conf_file_arg("--vendor", action="store") + parser.add_conf_file_arg("--native", type='tristate') - tag_group.add_arg("--tag", action="store_true", dest="tag", + tag_group.add_arg("--tag", action="store_true", help="create a tag after a successful build") - tag_group.add_arg("--tag-only", action="store_true", dest="tag_only", + tag_group.add_arg("--tag-only", action="store_true", help="don't build, only tag and run the posttag hook") - tag_group.add_arg("--retag", action="store_true", dest="retag", + tag_group.add_arg("--retag", action="store_true", help="don't fail if the tag already exists") - tag_group.add_bool_conf_file_arg("--sign-tags", - dest="sign_tags") - tag_group.add_conf_file_arg("--keyid", dest="keyid") - tag_group.add_conf_file_arg("--packaging-tag", - dest="packaging_tag") - tag_group.add_conf_file_arg("--packaging-tag-msg", - dest="packaging_tag_msg") - tag_group.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") - orig_group.add_conf_file_arg("--upstream-tree", - dest="upstream_tree") - orig_group.add_bool_conf_file_arg("--pristine-tar", - dest="pristine_tar") - orig_group.add_bool_conf_file_arg("--pristine-tar-commit", - dest="pristine_tar_commit") - orig_group.add_conf_file_arg("--force-create", - dest="force_create", action="store_true", + tag_group.add_bool_conf_file_arg("--sign-tags") + tag_group.add_conf_file_arg("--keyid") + tag_group.add_conf_file_arg("--packaging-tag") + tag_group.add_conf_file_arg("--packaging-tag-msg") + tag_group.add_conf_file_arg("--upstream-tag") + orig_group.add_conf_file_arg("--upstream-tree") + orig_group.add_bool_conf_file_arg("--pristine-tar") + orig_group.add_bool_conf_file_arg("--pristine-tar-commit") + orig_group.add_conf_file_arg("--force-create", action="store_true", help="force creation of upstream source tarball") - orig_group.add_conf_file_arg("--no-create-orig", - dest="no_create_orig", action="store_true", + orig_group.add_conf_file_arg("--no-create-orig", action="store_true", help="don't create upstream source tarball") - orig_group.add_conf_file_arg("--tarball-dir", - dest="tarball_dir", type="path", + orig_group.add_conf_file_arg("--tarball-dir", type="path", help="location to look for external tarballs") orig_group.add_conf_file_arg("--compression-level", dest="comp_level", help="Compression level") - branch_group.add_conf_file_arg("--upstream-branch", - dest="upstream_branch") - branch_group.add_conf_file_arg("--packaging-branch", - dest="packaging_branch") - branch_group.add_bool_conf_file_arg("--ignore-branch", - dest="ignore_branch") + branch_group.add_conf_file_arg("--upstream-branch") + branch_group.add_conf_file_arg("--packaging-branch") + branch_group.add_bool_conf_file_arg("--ignore-branch") branch_group.add_bool_conf_file_arg("--submodules", dest="with_submodules") - cmd_group.add_conf_file_arg("--builder", dest="builder", + cmd_group.add_conf_file_arg("--builder", help="command to build the package") - cmd_group.add_conf_file_arg("--cleaner", dest="cleaner", + cmd_group.add_conf_file_arg("--cleaner", help="command to clean the working copy") - cmd_group.add_conf_file_arg("--prebuild", dest="prebuild", + cmd_group.add_conf_file_arg("--prebuild", help="command to run before a build") cmd_group.add_conf_file_arg("--postexport", - dest="postexport", help="command to run after exporting the source tree") - cmd_group.add_conf_file_arg("--postbuild", dest="postbuild", + cmd_group.add_conf_file_arg("--postbuild", help="hook run after a successful build") - cmd_group.add_conf_file_arg("--posttag", dest="posttag", + cmd_group.add_conf_file_arg("--posttag", help="hook run after a successful tag operation") cmd_group.add_bool_conf_file_arg("--mock", dest="use_mock") cmd_group.add_conf_file_arg("--dist", dest="mock_dist") cmd_group.add_conf_file_arg("--arch", dest="mock_arch") - cmd_group.add_conf_file_arg("--mock-root", dest="mock_root") - cmd_group.add_conf_file_arg("--mock-options", dest="mock_options") - cmd_group.add_bool_conf_file_arg("--hooks", dest="hooks") + cmd_group.add_conf_file_arg("--mock-root") + cmd_group.add_conf_file_arg("--mock-options") + cmd_group.add_bool_conf_file_arg("--hooks") export_group.add_arg("--no-build", action="store_true", - dest="no_build", help="Don't run builder or the associated hooks") - export_group.add_conf_file_arg("--export-dir", - dest="export_dir", type="path", + export_group.add_conf_file_arg("--export-dir", type="path", help="Build topdir, also export the sources under " "EXPORT_DIR") - export_group.add_conf_file_arg("--export-specdir", - dest="export_specdir", type="path") - export_group.add_conf_file_arg("--export-sourcedir", - dest="export_sourcedir", type="path") - export_group.add_conf_file_arg("--export", dest="export", - metavar="TREEISH", + export_group.add_conf_file_arg("--export-specdir", type="path") + export_group.add_conf_file_arg("--export-sourcedir", type="path") + export_group.add_conf_file_arg("--export", metavar="TREEISH", help="export treeish object TREEISH") - export_group.add_conf_file_arg("--packaging-dir", - dest="packaging_dir") - export_group.add_conf_file_arg("--spec-file", - dest="spec_file") - export_group.add_conf_file_arg("--spec-vcs-tag", dest="spec_vcs_tag") + export_group.add_conf_file_arg("--packaging-dir") + export_group.add_conf_file_arg("--spec-file") + export_group.add_conf_file_arg("--spec-vcs-tag") return parser diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py index ee4baf12..ec25ac21 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -109,27 +109,25 @@ def build_parser(name): branch_group = parser.add_argument_group("branch options", "branch tracking and layout options") cmd_group = parser.add_argument_group("external command options", "how and when to invoke hooks") - branch_group.add_arg("--all", action="store_true", dest="all", + branch_group.add_arg("--all", action="store_true", help="track all branches, not only debian and upstream") - branch_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") - branch_group.add_conf_file_arg("--debian-branch", dest="debian_branch") - branch_group.add_bool_conf_file_arg("--pristine-tar", dest="pristine_tar") - branch_group.add_arg("--depth", action="store", dest="depth", default=0, + branch_group.add_conf_file_arg("--upstream-branch") + branch_group.add_conf_file_arg("--debian-branch") + branch_group.add_bool_conf_file_arg("--pristine-tar") + branch_group.add_arg("--depth", action="store", default=0, help="git history depth (for creating shallow clones)") - branch_group.add_arg("--reference", action="store", dest="reference", default=None, + branch_group.add_arg("--reference", action="store", default=None, help="git reference repository (use local copies where possible)") - cmd_group.add_conf_file_arg("--postclone", dest="postclone", + cmd_group.add_conf_file_arg("--postclone", help="hook to run after cloning the source tree") - cmd_group.add_bool_conf_file_arg("--hooks", dest="hooks") + cmd_group.add_bool_conf_file_arg("--hooks") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + parser.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", dest="color_scheme") - parser.add_conf_file_arg("--repo-user", dest="repo_user", - choices=['DEBIAN', 'GIT']) - parser.add_conf_file_arg("--repo-email", dest="repo_email", - choices=['DEBIAN', 'GIT']) + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + parser.add_conf_file_arg("--repo-user", choices=['DEBIAN', 'GIT']) + parser.add_conf_file_arg("--repo-email", choices=['DEBIAN', 'GIT']) parser.add_argument("repository", metavar="REPOSITORY", help="repository to clone") parser.add_argument("directory", metavar="DIRECTORY", nargs="?", diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py index 66e65e3b..250cd487 100644 --- a/gbp/scripts/create_remote_repo.py +++ b/gbp/scripts/create_remote_repo.py @@ -232,33 +232,23 @@ def build_parser(name, sections=[]): "branch layout and tracking options") branch_group.add_conf_file_arg("--remote-url-pattern", dest="remote_url") - branch_group.add_conf_file_arg("--upstream-branch", - dest="upstream_branch") - branch_group.add_conf_file_arg("--debian-branch", - dest="debian_branch") - branch_group.add_bool_conf_file_arg("--pristine-tar", - dest="pristine_tar") - branch_group.add_bool_conf_file_arg("--track", - dest='track') - branch_group.add_bool_conf_file_arg("--bare", - dest='bare') + branch_group.add_conf_file_arg("--upstream-branch") + branch_group.add_conf_file_arg("--debian-branch") + branch_group.add_bool_conf_file_arg("--pristine-tar") + branch_group.add_bool_conf_file_arg("--track") + branch_group.add_bool_conf_file_arg("--bare") parser.add_arg("-v", "--verbose", action="store_true", - dest="verbose", help="verbose command execution") parser.add_conf_file_arg("--color", - dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") + parser.add_conf_file_arg("--color-scheme") parser.add_arg("--remote-name", dest="name", default="origin", help="The name of the remote, default is 'origin'") - parser.add_conf_file_arg("--template-dir", - dest="template_dir") - parser.add_conf_file_arg("--remote-config", - dest="remote_config") + parser.add_conf_file_arg("--template-dir") + parser.add_conf_file_arg("--remote-config") parser.add_argument("action", metavar="ACTION", nargs="?", default="create", choices=('create', 'list'), help="action to take") diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index 6ab86551..1da79e22 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -343,63 +343,62 @@ def build_parser(name): custom_group = parser.add_argument_group("customization", "options for customization") - parser.add_bool_conf_file_arg("--ignore-branch", dest="ignore_branch") - naming_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") - naming_group.add_conf_file_arg("--debian-branch", dest="debian_branch") - naming_group.add_conf_file_arg("--upstream-tag", dest="upstream_tag") - naming_group.add_conf_file_arg("--debian-tag", dest="debian_tag") - naming_group.add_conf_file_arg("--snapshot-number", dest="snapshot_number", + parser.add_bool_conf_file_arg("--ignore-branch") + naming_group.add_conf_file_arg("--upstream-branch") + naming_group.add_conf_file_arg("--debian-branch") + naming_group.add_conf_file_arg("--upstream-tag") + naming_group.add_conf_file_arg("--debian-tag") + naming_group.add_conf_file_arg("--snapshot-number", help="expression to determine the next snapshot number") - parser.add_conf_file_arg("--git-log", dest="git_log", + parser.add_conf_file_arg("--git-log", help="options to pass to git-log") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + parser.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", dest="color_scheme") - range_group.add_arg("-s", "--since", dest="since", help="commit to start from (e.g. HEAD^^^, debian/0.4.3)") - range_group.add_arg("-a", "--auto", action="store_true", dest="auto", + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + range_group.add_arg("-s", "--since", help="commit to start from (e.g. HEAD^^^, debian/0.4.3)") + range_group.add_arg("-a", "--auto", action="store_true", help="autocomplete changelog from last snapshot or tag") - version_group.add_arg("-R", "--release", action="store_true", dest="release", + version_group.add_arg("-R", "--release", action="store_true", help="mark as release") - version_group.add_arg("-S", "--snapshot", action="store_true", dest="snapshot", + version_group.add_arg("-S", "--snapshot", action="store_true", help="mark as snapshot build") - version_group.add_arg("-D", "--distribution", dest="distribution", help="Set distribution") - version_group.add_arg("--force-distribution", action="store_true", dest="force_distribution", + version_group.add_arg("-D", "--distribution", help="Set distribution") + version_group.add_arg("--force-distribution", action="store_true", help="Force the provided distribution to be used, " "even if it doesn't match the list of known distributions") - version_group.add_arg("-N", "--new-version", dest="new_version", + version_group.add_arg("-N", "--new-version", help="use this as base for the new version number") - version_group.add_conf_file_arg("--urgency", dest="urgency") - version_group.add_arg("--bpo", dest="bpo", action="store_true", + version_group.add_conf_file_arg("--urgency") + version_group.add_arg("--bpo", action="store_true", help="Increment the Debian release number for an upload to backports, " "and add a backport upload changelog comment.") - version_group.add_arg("--nmu", dest="nmu", action="store_true", + version_group.add_arg("--nmu", action="store_true", help="Increment the Debian release number for a non-maintainer upload") - version_group.add_arg("--qa", dest="qa", action="store_true", + version_group.add_arg("--qa", action="store_true", help="Increment the Debian release number for a Debian QA Team upload, " "and add a QA upload changelog comment.") - version_group.add_arg("--team", dest="team", action="store_true", + version_group.add_arg("--team", action="store_true", help="Increment the Debian release number for a Debian Team upload, " "and add a Team upload changelog comment.") - version_group.add_arg("--security", dest="security", action="store_true", + version_group.add_arg("--security", action="store_true", help="Increment the Debian release number for a security upload and " "add a security upload changelog comment.") version_group.add_bool_conf_file_arg("--git-author", dest="use_git_author") - commit_group.add_bool_conf_file_arg("--meta", dest="meta") - commit_group.add_conf_file_arg("--meta-closes", dest="meta_closes") - commit_group.add_conf_file_arg("--meta-closes-bugnum", dest="meta_closes_bugnum") - commit_group.add_bool_conf_file_arg("--full", dest="full") + commit_group.add_bool_conf_file_arg("--meta") + commit_group.add_conf_file_arg("--meta-closes") + commit_group.add_conf_file_arg("--meta-closes-bugnum") + commit_group.add_bool_conf_file_arg("--full") commit_group.add_conf_file_arg("--id-length", dest="idlen", help="include N digits of the commit id in the changelog entry", type=int, metavar="N") - commit_group.add_conf_file_arg("--ignore-regex", dest="ignore_regex", + commit_group.add_conf_file_arg("--ignore-regex", help="Ignore commit lines matching regex") - commit_group.add_bool_conf_file_arg("--multimaint", dest="multimaint") - commit_group.add_bool_conf_file_arg("--multimaint-merge", dest="multimaint_merge") - commit_group.add_conf_file_arg("--spawn-editor", dest="spawn_editor") - parser.add_conf_file_arg("--commit-msg", - dest="commit_msg") - parser.add_arg("-c", "--commit", action="store_true", dest="commit", + commit_group.add_bool_conf_file_arg("--multimaint") + commit_group.add_bool_conf_file_arg("--multimaint-merge") + commit_group.add_conf_file_arg("--spawn-editor") + parser.add_conf_file_arg("--commit-msg") + parser.add_arg("-c", "--commit", action="store_true", help="commit changelog file after generating") parser.add_conf_file_arg("--dch-opt", dest="dch_opts", action="append", help="option to pass to dch verbatim, " diff --git a/gbp/scripts/export_orig.py b/gbp/scripts/export_orig.py index 5643bb9b..f2a3a0c5 100755 --- a/gbp/scripts/export_orig.py +++ b/gbp/scripts/export_orig.py @@ -275,17 +275,16 @@ def build_parser(name): branch_group = parser.add_argument_group("branch options", "branch layout options") - parser.add_arg("--verbose", action="store_true", dest="verbose", + parser.add_arg("--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - tag_group.add_conf_file_arg("--upstream-tag", dest="upstream_tag") - orig_group.add_conf_file_arg("--upstream-tree", dest="upstream_tree") - orig_group.add_bool_conf_file_arg("--pristine-tar", dest="pristine_tar") - orig_group.add_conf_file_arg("--force-create", dest="force_create", + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + tag_group.add_conf_file_arg("--upstream-tag") + orig_group.add_conf_file_arg("--upstream-tree") + orig_group.add_bool_conf_file_arg("--pristine-tar") + orig_group.add_conf_file_arg("--force-create", help="force creation of orig tarball", action="store_true") - orig_group.add_conf_file_arg("--tarball-dir", dest="tarball_dir", type="path", + orig_group.add_conf_file_arg("--tarball-dir", type="path", help="location to look for external tarballs") orig_group.add_conf_file_arg("--compression", dest="comp_type", help="Compression type") @@ -293,7 +292,7 @@ def build_parser(name): help="Compression level") orig_group.add_conf_file_arg("--component", action="append", metavar='COMPONENT', dest="components") - branch_group.add_conf_file_arg("--upstream-branch", dest="upstream_branch") + branch_group.add_conf_file_arg("--upstream-branch") branch_group.add_bool_conf_file_arg("--submodules", dest="with_submodules") return parser diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py index ce323e23..e5bb7096 100644 --- a/gbp/scripts/import_dsc.py +++ b/gbp/scripts/import_dsc.py @@ -320,49 +320,35 @@ def build_parser(name): branch_group = parser.add_argument_group("version and branch naming options", "version number and branch layout options") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + parser.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - branch_group.add_conf_file_arg("--debian-branch", - dest="debian_branch") - branch_group.add_conf_file_arg("--upstream-branch", - dest="upstream_branch") - branch_group.add_bool_conf_file_arg("--create-missing-branches", - dest="create_missing_branches") - - tag_group.add_bool_conf_file_arg("--sign-tags", - dest="sign_tags") - tag_group.add_conf_file_arg("--keyid", - dest="keyid") - tag_group.add_conf_file_arg("--debian-tag", - dest="debian_tag") - tag_group.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") - tag_group.add_arg("--skip-debian-tag", dest="skip_debian_tag", - action="store_true", + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + branch_group.add_conf_file_arg("--debian-branch") + branch_group.add_conf_file_arg("--upstream-branch") + branch_group.add_bool_conf_file_arg("--create-missing-branches") + + tag_group.add_bool_conf_file_arg("--sign-tags") + tag_group.add_conf_file_arg("--keyid") + tag_group.add_conf_file_arg("--debian-tag") + tag_group.add_conf_file_arg("--upstream-tag") + tag_group.add_arg("--skip-debian-tag", action="store_true", help="Don't add a tag after importing the Debian patch") import_group.add_conf_file_arg("--filter", dest="filters", action="append") - import_group.add_bool_conf_file_arg("--pristine-tar", - dest="pristine_tar") + import_group.add_bool_conf_file_arg("--pristine-tar") import_group.add_arg("--allow-same-version", action="store_true", - dest="allow_same_version", help="allow import of already imported version") import_group.add_bool_conf_file_arg("--author-is-committer", dest="author_committer") import_group.add_bool_conf_file_arg("--author-date-is-committer-date", dest="author_committer_date") - import_group.add_bool_conf_file_arg("--allow-unauthenticated", - dest="allow_unauthenticated") - - parser.add_conf_file_arg("--repo-user", dest="repo_user", - choices=['DEBIAN', 'GIT']) - parser.add_conf_file_arg("--repo-email", dest="repo_email", - choices=['DEBIAN', 'GIT']) - parser.add_arg("--download", dest='download', action="store_true", + import_group.add_bool_conf_file_arg("--allow-unauthenticated") + + parser.add_conf_file_arg("--repo-user", choices=['DEBIAN', 'GIT']) + parser.add_conf_file_arg("--repo-email", choices=['DEBIAN', 'GIT']) + parser.add_arg("--download", action="store_true", help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-dsc(1).") parser.add_argument("package", metavar="PACKAGE", help="package to import") diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index f988970c..3f777161 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -316,47 +316,35 @@ def build_parser(name): branch_group.add_arg("-u", "--upstream-version", dest="version", help="Upstream Version") - branch_group.add_conf_file_arg("--debian-branch", - dest="debian_branch") - branch_group.add_conf_file_arg("--upstream-branch", - dest="upstream_branch") + branch_group.add_conf_file_arg("--debian-branch") + branch_group.add_conf_file_arg("--upstream-branch") branch_group.add_conf_file_arg("--upstream-vcs-tag", dest="vcs_tag", help="Upstream VCS tag add to the merge commit") - branch_group.add_bool_conf_file_arg("--merge", dest="merge") - branch_group.add_conf_file_arg("--merge-mode", dest="merge_mode") - - tag_group.add_bool_conf_file_arg("--sign-tags", - dest="sign_tags") - tag_group.add_conf_file_arg("--keyid", - dest="keyid") - tag_group.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") + branch_group.add_bool_conf_file_arg("--merge") + branch_group.add_conf_file_arg("--merge-mode") + + tag_group.add_bool_conf_file_arg("--sign-tags") + tag_group.add_conf_file_arg("--keyid") + tag_group.add_conf_file_arg("--upstream-tag") import_group.add_conf_file_arg("--filter", dest="filters", action="append") - import_group.add_bool_conf_file_arg("--pristine-tar", - dest="pristine_tar") - import_group.add_bool_conf_file_arg("--filter-pristine-tar", - dest="filter_pristine_tar") - import_group.add_conf_file_arg("--import-msg", - dest="import_msg") - import_group.add_bool_conf_file_arg("--symlink-orig", - dest="symlink_orig") + import_group.add_bool_conf_file_arg("--pristine-tar") + import_group.add_bool_conf_file_arg("--filter-pristine-tar") + import_group.add_conf_file_arg("--import-msg") + import_group.add_bool_conf_file_arg("--symlink-orig") import_group.add_conf_file_arg("--component", action="append", metavar='COMPONENT', dest="components") - cmd_group.add_conf_file_arg("--postimport", dest="postimport") + cmd_group.add_conf_file_arg("--postimport") - parser.add_bool_conf_file_arg("--interactive", - dest='interactive') - parser.add_bool_conf_file_arg("--rollback", - dest="rollback") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + parser.add_bool_conf_file_arg("--interactive") + parser.add_bool_conf_file_arg("--rollback") + parser.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") # Accepted for compatibility - parser.add_arg("--download", dest='download', action="store_true", + parser.add_arg("--download", action="store_true", help="Ignored. Accepted for compatibility; see EXAMPLES in gbp-import-orig(1).") src_group = parser.add_mutually_exclusive_group(required=True) diff --git a/gbp/scripts/import_ref.py b/gbp/scripts/import_ref.py index 2ab2acd3..51be5129 100644 --- a/gbp/scripts/import_ref.py +++ b/gbp/scripts/import_ref.py @@ -75,33 +75,24 @@ def build_parser(name): branch_group.add_arg("-u", "--upstream-version", dest="version", help="The version number to use for the new version, " "default is ''", default='') - branch_group.add_conf_file_arg("--debian-branch", - dest="debian_branch") - branch_group.add_conf_file_arg("--upstream-branch", - dest="upstream_branch") + branch_group.add_conf_file_arg("--debian-branch") + branch_group.add_conf_file_arg("--upstream-branch") branch_group.add_conf_file_arg("--upstream-tree", - dest="upstream_tree", help="Where to merge the upstream changes from.", default="VERSION") - branch_group.add_conf_file_arg("--merge-mode", dest="merge_mode") - - tag_group.add_bool_conf_file_arg("--sign-tags", - dest="sign_tags") - tag_group.add_conf_file_arg("--keyid", - dest="keyid") - tag_group.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") - import_group.add_conf_file_arg("--import-msg", - dest="import_msg") - cmd_group.add_conf_file_arg("--postimport", dest="postimport") - - parser.add_bool_conf_file_arg("--rollback", - dest="rollback") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + branch_group.add_conf_file_arg("--merge-mode") + + tag_group.add_bool_conf_file_arg("--sign-tags") + tag_group.add_conf_file_arg("--keyid") + tag_group.add_conf_file_arg("--upstream-tag") + import_group.add_conf_file_arg("--import-msg") + cmd_group.add_conf_file_arg("--postimport") + + parser.add_bool_conf_file_arg("--rollback") + parser.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") return parser diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py index 0e166e54..ead2d000 100755 --- a/gbp/scripts/import_srpm.py +++ b/gbp/scripts/import_srpm.py @@ -133,61 +133,44 @@ def build_parser(name): branch_group = parser.add_argument_group("version and branch naming options", "version number and branch layout options") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + parser.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", + parser.add_conf_file_arg("--color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") - parser.add_conf_file_arg("--vendor", action="store", - dest="vendor") - parser.add_arg("--download", action="store_true", dest="download", + parser.add_conf_file_arg("--color-scheme") + parser.add_conf_file_arg("--tmp-dir") + parser.add_conf_file_arg("--vendor", action="store") + parser.add_arg("--download", action="store_true", help="download source package") - branch_group.add_conf_file_arg("--packaging-branch", - dest="packaging_branch") - branch_group.add_conf_file_arg("--upstream-branch", - dest="upstream_branch") + branch_group.add_conf_file_arg("--packaging-branch") + branch_group.add_conf_file_arg("--upstream-branch") branch_group.add_arg("--upstream-vcs-tag", dest="vcs_tag", help="Upstream VCS tag on top of which to import " "the orig sources") - branch_group.add_bool_conf_file_arg("--create-missing-branches", - dest="create_missing_branches") + branch_group.add_bool_conf_file_arg("--create-missing-branches") branch_group.add_arg("--orphan-packaging", action="store_true", - dest="orphan_packaging", help="The packaging branch doesn't base on upstream") - branch_group.add_arg("--native", action="store_true", dest="native", + branch_group.add_arg("--native", action="store_true", help="This is a dist native package, no separate " "upstream branch") - tag_group.add_bool_conf_file_arg("--sign-tags", - dest="sign_tags") - tag_group.add_conf_file_arg("--keyid", - dest="keyid") - tag_group.add_conf_file_arg("--packaging-tag", - dest="packaging_tag") - tag_group.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") - tag_group.add_arg("--skip-packaging-tag", dest="skip_packaging_tag", - action="store_true", + tag_group.add_bool_conf_file_arg("--sign-tags") + tag_group.add_conf_file_arg("--keyid") + tag_group.add_conf_file_arg("--packaging-tag") + tag_group.add_conf_file_arg("--upstream-tag") + tag_group.add_arg("--skip-packaging-tag", action="store_true", help="Don't add a tag after importing packaging files") import_group.add_conf_file_arg("--filter", dest="filters", action="append") - import_group.add_bool_conf_file_arg("--pristine-tar", - dest="pristine_tar") + import_group.add_bool_conf_file_arg("--pristine-tar") import_group.add_arg("--allow-same-version", action="store_true", - dest="allow_same_version", help="allow import of already imported version") - import_group.add_bool_conf_file_arg("--author-is-committer", - dest="author_is_committer") - import_group.add_conf_file_arg("--packaging-dir", - dest="packaging_dir") - - parser.add_conf_file_arg("--repo-user", dest="repo_user", - choices=['DEBIAN', 'GIT']) - parser.add_conf_file_arg("--repo-email", dest="repo_email", - choices=['DEBIAN', 'GIT']) + import_group.add_bool_conf_file_arg("--author-is-committer") + import_group.add_conf_file_arg("--packaging-dir") + + parser.add_conf_file_arg("--repo-user", choices=['DEBIAN', 'GIT']) + parser.add_conf_file_arg("--repo-email", choices=['DEBIAN', 'GIT']) parser.add_argument("package", metavar="PACKAGE", help="package to import") parser.add_argument("target_dir", metavar="TARGET_DIR", nargs="?", help="target directory where to import") diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 59dad643..4f0d28b7 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -412,16 +412,15 @@ def build_parser(name): return None # Add common arguments - _parent.add_arg("-v", "--verbose", action="store_true", dest="verbose", + _parent.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - _parent.add_conf_file_arg("--color", dest="color", type='tristate') - _parent.add_conf_file_arg("--color-scheme", - dest="color_scheme") - _parent.add_conf_file_arg("--pq-from", dest="pq_from", choices=['DEBIAN', 'TAG']) - _parent.add_conf_file_arg("--upstream-tag", dest="upstream_tag") - _parent.add_arg("--force", dest="force", action="store_true", + _parent.add_conf_file_arg("--color", type='tristate') + _parent.add_conf_file_arg("--color-scheme") + _parent.add_conf_file_arg("--pq-from", choices=['DEBIAN', 'TAG']) + _parent.add_conf_file_arg("--upstream-tag") + _parent.add_arg("--force", action="store_true", help="in case of import even import if the branch already exists") - _parent.add_conf_file_arg("--time-machine", dest="time_machine", type=int) + _parent.add_conf_file_arg("--time-machine", type=int) # Add subcommands subparsers = parser.add_subparsers(title='actions', dest='action') @@ -431,14 +430,14 @@ def build_parser(name): help="export the patch queue associated to the current " "branch into a quilt patch series in debian/patches/ " "and update the series file.") - _parser.add_bool_conf_file_arg("--patch-numbers", dest="patch_numbers") - _parser.add_conf_file_arg("--patch-num-format", dest="patch_num_format") - _parser.add_bool_conf_file_arg("--renumber", dest="renumber") - _parser.add_bool_conf_file_arg("--drop", dest='drop') - _parser.add_bool_conf_file_arg("--commit", dest="commit") - _parser.add_conf_file_arg("--abbrev", dest="abbrev", type=int) - _parser.add_conf_file_arg("--meta-closes", dest="meta_closes") - _parser.add_conf_file_arg("--meta-closes-bugnum", dest="meta_closes_bugnum") + _parser.add_bool_conf_file_arg("--patch-numbers") + _parser.add_conf_file_arg("--patch-num-format") + _parser.add_bool_conf_file_arg("--renumber") + _parser.add_bool_conf_file_arg("--drop") + _parser.add_bool_conf_file_arg("--commit") + _parser.add_conf_file_arg("--abbrev", type=int) + _parser.add_conf_file_arg("--meta-closes") + _parser.add_conf_file_arg("--meta-closes-bugnum") # Import _parser = subparsers.add_parser('import', parents=[_parent], help="create a patch queue branch from" @@ -454,7 +453,7 @@ def build_parser(name): # Apply _parser = subparsers.add_parser('apply', parents=[_parent], help="apply a patch") - _parser.add_arg("--topic", dest="topic", help="in case of 'apply' topic (subdir) to put patch into") + _parser.add_arg("--topic", help="in case of 'apply' topic (subdir) to put patch into") _parser.add_argument("patch", metavar="PATCH", help="Patch to apply") # Switch _parser = subparsers.add_parser('switch', parents=[_parent], diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 71ae3605..1a7e76b0 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -380,18 +380,14 @@ def build_parser(name): return None # Add common arguments - _parent.add_arg("-v", "--verbose", action="store_true", dest="verbose", + _parent.add_arg("-v", "--verbose", action="store_true", help="Verbose command execution") - _parent.add_conf_file_arg("--color", dest="color", - type='tristate') - _parent.add_conf_file_arg("--color-scheme", - dest="color_scheme") - _parent.add_conf_file_arg("--tmp-dir", dest="tmp_dir") - _parent.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") - _parent.add_conf_file_arg("--spec-file", dest="spec_file") - _parent.add_conf_file_arg("--packaging-dir", - dest="packaging_dir") + _parent.add_conf_file_arg("--color", type='tristate') + _parent.add_conf_file_arg("--color-scheme") + _parent.add_conf_file_arg("--tmp-dir") + _parent.add_conf_file_arg("--upstream-tag") + _parent.add_conf_file_arg("--spec-file") + _parent.add_conf_file_arg("--packaging-dir") # Add subcommands subparsers = parser.add_subparsers(title='actions', dest='action') @@ -401,15 +397,14 @@ def build_parser(name): help="Export the patch queue / devel branch associated to the " "current branch into a patch series in and update the spec " "file") - _parser.add_bool_conf_file_arg("--patch-numbers", - dest="patch_numbers") - _parser.add_conf_file_arg("--abbrev", dest="abbrev", type=int) - _parser.add_bool_conf_file_arg("--drop", dest="drop") + _parser.add_bool_conf_file_arg("--patch-numbers") + _parser.add_conf_file_arg("--abbrev", type=int) + _parser.add_bool_conf_file_arg("--drop") # Import _parser = subparsers.add_parser('import', parents=[_parent], help="Create a patch queue / devel branch from spec file " "and patches in current dir.") - _parser.add_arg("--force", dest="force", action="store_true", + _parser.add_arg("--force", action="store_true", help="In case of import even import if the branch already exists") # Rebase _parser = subparsers.add_parser('rebase', parents=[_parent], diff --git a/gbp/scripts/pristine_tar.py b/gbp/scripts/pristine_tar.py index d313b714..34eaeedd 100644 --- a/gbp/scripts/pristine_tar.py +++ b/gbp/scripts/pristine_tar.py @@ -49,15 +49,13 @@ def build_parser(name): gbp.log.err(err) return None - parser.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") + parser.add_conf_file_arg("--upstream-tag") parser.add_conf_file_arg("--component", action="append", metavar='COMPONENT', dest="components") - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + parser.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") parser.add_argument("action", metavar="ACTION", choices=('commit',), help="action to take") parser.add_argument("tarball", metavar="TARBALL", diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py index 7b663a73..dae519af 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -102,7 +102,7 @@ def build_parser(name): branch_group.add_conf_file_arg("--upstream-branch") branch_group.add_conf_file_arg("--debian-branch") branch_group.add_bool_conf_file_arg("--pristine-tar") - branch_group.add_bool_conf_file_arg("--track-missing", dest="track_missing") + branch_group.add_bool_conf_file_arg("--track-missing") branch_group.add_arg("--depth", action="store", default=0, help="git history depth (for deepening shallow clones)") parser.add_arg("-v", "--verbose", action="store_true", diff --git a/gbp/scripts/push.py b/gbp/scripts/push.py index 49e3b58f..034a5061 100755 --- a/gbp/scripts/push.py +++ b/gbp/scripts/push.py @@ -38,21 +38,15 @@ def build_parser(name): parser.add_arg("-d", "--dry-run", dest="dryrun", action="store_true", help="dry run, don't push.") - parser.add_conf_file_arg("--upstream-branch", - dest="upstream_branch") - parser.add_conf_file_arg("--upstream-tag", - dest="upstream_tag") - parser.add_conf_file_arg("--debian-branch", - dest="debian_branch") - parser.add_conf_file_arg("--debian-tag", - dest="debian_tag") - parser.add_bool_conf_file_arg("--pristine-tar", - dest="pristine_tar") - parser.add_bool_conf_file_arg("--ignore-branch", dest="ignore_branch") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - parser.add_arg("--verbose", action="store_true", dest="verbose", + parser.add_conf_file_arg("--upstream-branch") + parser.add_conf_file_arg("--upstream-tag") + parser.add_conf_file_arg("--debian-branch") + parser.add_conf_file_arg("--debian-tag") + parser.add_bool_conf_file_arg("--pristine-tar") + parser.add_bool_conf_file_arg("--ignore-branch") + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + parser.add_arg("--verbose", action="store_true", help="verbose command execution") parser.add_argument("remote", metavar="REMOTE", nargs="?", help="remote where to push") diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py index f3306fd4..da23617f 100644 --- a/gbp/scripts/rpm_ch.py +++ b/gbp/scripts/rpm_ch.py @@ -323,19 +323,16 @@ def build_parser(name): "branch names, tag formats, directory and file naming") # Non-grouped options - parser.add_arg("-v", "--verbose", action="store_true", dest="verbose", + parser.add_arg("-v", "--verbose", action="store_true", help="verbose command execution") - parser.add_conf_file_arg("--color", dest="color", + parser.add_conf_file_arg("--color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - parser.add_conf_file_arg("--tmp-dir", dest="tmp_dir") - parser.add_conf_file_arg("--vendor", action="store", - dest="vendor") - parser.add_conf_file_arg("--git-log", dest="git_log", + parser.add_conf_file_arg("--color-scheme") + parser.add_conf_file_arg("--tmp-dir") + parser.add_conf_file_arg("--vendor", action="store") + parser.add_conf_file_arg("--git-log", help="options to pass to git-log") - parser.add_bool_conf_file_arg("--ignore-branch", - dest="ignore_branch") + parser.add_bool_conf_file_arg("--ignore-branch") parser.add_conf_file_arg("--customizations", dest="customization_file", help="Load Python code from CUSTOMIZATION_FILE. At the " @@ -343,38 +340,29 @@ def build_parser(name): "custom ChangelogEntryFormatter class.") # Naming group options - naming_grp.add_conf_file_arg("--packaging-branch", - dest="packaging_branch") - naming_grp.add_conf_file_arg("--packaging-tag", - dest="packaging_tag") - naming_grp.add_conf_file_arg("--packaging-dir", - dest="packaging_dir") - naming_grp.add_conf_file_arg("--changelog-file", - dest="changelog_file") - naming_grp.add_conf_file_arg("--spec-file", dest="spec_file") + naming_grp.add_conf_file_arg("--packaging-branch") + naming_grp.add_conf_file_arg("--packaging-tag") + naming_grp.add_conf_file_arg("--packaging-dir") + naming_grp.add_conf_file_arg("--changelog-file") + naming_grp.add_conf_file_arg("--spec-file") # Range group options - range_grp.add_arg("-s", "--since", dest="since", + range_grp.add_arg("-s", "--since", help="commit to start from (e.g. HEAD^^^, release/0.1.2)") # Formatting group options format_grp.add_arg("--no-release", action="store_false", dest="release", help="no release, just update the last changelog section") - format_grp.add_bool_conf_file_arg("--git-author", - dest="git_author") - format_grp.add_bool_conf_file_arg("--full", dest="full") + format_grp.add_bool_conf_file_arg("--git-author") + format_grp.add_bool_conf_file_arg("--full") format_grp.add_conf_file_arg("--id-length", dest="idlen", help="include N digits of the commit id in " "the changelog entry", type=int, metavar="N") format_grp.add_conf_file_arg("--ignore-regex", - dest="ignore_regex", help="Ignore lines in commit message matching regex,") - format_grp.add_conf_file_arg("--changelog-revision", - dest="changelog_revision") - format_grp.add_conf_file_arg("--spawn-editor", - dest="spawn_editor") - format_grp.add_conf_file_arg("--editor-cmd", - dest="editor_cmd") + format_grp.add_conf_file_arg("--changelog-revision") + format_grp.add_conf_file_arg("--spawn-editor") + format_grp.add_conf_file_arg("--editor-cmd") parser.add_argument("path", metavar="PATH", nargs="*", help="path(s) to look for changes") diff --git a/gbp/scripts/tag.py b/gbp/scripts/tag.py index adf2e81a..eb8a6b1e 100755 --- a/gbp/scripts/tag.py +++ b/gbp/scripts/tag.py @@ -85,23 +85,20 @@ def build_parser(name): gbp.log.err(err) return None - parser.add_arg("--retag", action="store_true", dest="retag", + parser.add_arg("--retag", action="store_true", help="don't fail if the tag already exists") - parser.add_conf_file_arg("--debian-branch", - dest="debian_branch") - parser.add_conf_file_arg("--debian-tag", - dest="debian_tag") - parser.add_conf_file_arg("--debian-tag-msg", dest="debian_tag_msg") - parser.add_bool_conf_file_arg("--sign-tags", dest="sign_tags") - parser.add_conf_file_arg("--keyid", dest="keyid") - parser.add_conf_file_arg("--posttag", dest="posttag", + parser.add_conf_file_arg("--debian-branch") + parser.add_conf_file_arg("--debian-tag") + parser.add_conf_file_arg("--debian-tag-msg") + parser.add_bool_conf_file_arg("--sign-tags") + parser.add_conf_file_arg("--keyid") + parser.add_conf_file_arg("--posttag", help="hook run after a successful tag operation") - parser.add_bool_conf_file_arg("--ignore-branch", dest="ignore_branch") - parser.add_bool_conf_file_arg("--ignore-new", dest="ignore_new") - parser.add_conf_file_arg("--color", dest="color", type='tristate') - parser.add_conf_file_arg("--color-scheme", - dest="color_scheme") - parser.add_arg("--verbose", action="store_true", dest="verbose", + parser.add_bool_conf_file_arg("--ignore-branch") + parser.add_bool_conf_file_arg("--ignore-new") + parser.add_conf_file_arg("--color", type='tristate') + parser.add_conf_file_arg("--color-scheme") + parser.add_arg("--verbose", action="store_true", help="verbose command execution") return parser