def build_parser(name): try: parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] repository - clone a remote repository') except ConfigParser.ParsingError as err: gbp.log.err(err) return None branch_group = GbpOptionGroup(parser, "branch options", "branch tracking and layout options") parser.add_option_group(branch_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)") 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") return parser
def build_parser(name): try: parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] - safely update a repository from remote') except configparser.ParsingError 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("--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_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") return parser
def test_get_config_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'), 'new_overrides_git_value1') self.assertEqual(parser.get_config_file_value('doesnotexist'), None)
def build_parser(name): try: parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] [repo] - safely update a repository from remote') 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("--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_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") return parser
def build_cmd_parser(section): """ Populate the parser to get a list of valid options """ try: # Populate the parser to get a list of # valid options module = import_command(section) parser = module.build_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() return parser
def test_default(self): """ A value only in the default section should be available in all commands """ 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')
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')
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') for line in range(0, 2): self._check_log(line, ".*Old style config section \[gbp-cmd3\] found please rename to \[cmd3\]")
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) 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)
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') # No deprecation warning since the test1.conf section is [cmd1] self._check_log_empty()
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 git-import-dsc will only use these. """ files = GbpOptionParser.get_config_files() global_config = [ f for f in files if f.startswith('/') ] 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)
def test_single_git_override_disabled_deprecations(self): """ With disabled deprecations we shouldn't see a log line """ for prefix in ['', 'git-']: os.environ['GBP_DISABLE_SECTION_DEPRECTATION'] = 'true' parser = GbpOptionParser('%scmd2' % prefix) self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1') for line in range(0, 2): self._check_log_empty() os.environ.pop('GBP_DISABLE_SECTION_DEPRECTATION')
def test_new_overrides_git(self): """ A value in the cmd section should override the old git-cmd section independent from how we're invoked """ 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'] expected = 'new_overrides_git_value1' self.assertEqual(actual, expected, "%s != %s for %s" % (actual, expected, cmd))
def build_parser(name): try: parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] command[.optionname] - display configuration settings') except configparser.ParsingError 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") return parser
def parse_args (argv): parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='', usage='%prog [options] repository - clone a remote repository') branch_group = GbpOptionGroup(parser, "branch options", "branch tracking and layout options") parser.add_option_group(branch_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)") 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") (options, args) = parser.parse_args(argv) gbp.log.setup(options.color, options.verbose, options.color_scheme) return (options, args)
def ensure_gbp_settings(self): """ Ensure some gbp settings are correct. """ parser = GbpOptionParser('import-orig') if parser.config.get('pristine-tar') != 'True': err = '"pristine-tar" is %s. Set to "True" in debian/gbp.conf.' raise RuntimeError(err % parser.config.get('pristine-tar')) if parser.config.get('merge-mode') != 'replace': err = '"merge-mode" is %s. Set to "replace" in debian/gbp.conf.' raise RuntimeError(err % parser.config.get('merge-mode')) # ensure upstream branch is unique for this debian branch debian_branch = parser.config.get('debian-branch') upstream_branch = parser.config.get('upstream-branch') expected = 'upstream/%s' % debian_branch if upstream_branch != expected: err = '"upstream-branch" is "%s". Set to "%s" in debian/gbp.conf.' raise RuntimeError(err % (upstream_branch, expected))
def test_param_list(self): parser = GbpOptionParser('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') params = parser.valid_options self.assertTrue('upstream-branch' in params) self.assertTrue('debian-branch' in params) self.assertTrue('color' in params)
def main(argv): retval = 0 current = None parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='', usage='%prog [options] - safely update a repository from remote') 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("--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_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") (options, args) = parser.parse_args(argv) gbp.log.setup(options.color, options.verbose, options.color_scheme) try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: branches = [] try: current = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --git-ignore-branch if options.ignore_branch: current = repo.head gbp.log.info("Found detached head at '%s'" % current) else: raise for branch in [ options.debian_branch, options.upstream_branch ]: if repo.has_branch(branch): branches += [ branch ] if repo.has_pristine_tar_branch() and options.pristine_tar: branches += [ repo.pristine_tar_branch ] (ret, out) = repo.is_clean() if not ret: gbp.log.err("You have uncommitted changes in your source tree:") gbp.log.err(out) raise GbpError repo.fetch(depth=options.depth) repo.fetch(depth=options.depth, tags=True) for branch in branches: if not fast_forward_branch(branch, repo, options): retval = 2 if options.redo_pq: repo.set_branch(options.debian_branch) Command("gbp-pq")(["drop"]) Command("gbp-pq")(["import"]) repo.set_branch(current) except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 return retval
def build_parser(name): try: parser = GbpOptionParser(command=os.path.basename(name), prefix='', usage='%prog [options] repository - 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']) return parser
def parse_cmd_config(command): """Make a command parse it's config files""" parser = GbpOptionParser(command) parser.parse_config_files() return parser
def build_parser(name): try: parser = GbpOptionParser( command=os.path.basename(name), prefix='', usage='%prog [options] repository - 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']) return parser
def setup_upstream_branch(self): """ Ensure we have a local "upstream/foo" branch. """ parser = GbpOptionParser('import-orig') upstream_branch = parser.config.get('upstream-branch') util.ensure_local_branch(upstream_branch)