aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-12-09 11:38:27 +0100
committerGuido Günther <agx@sigxcpu.org>2016-12-09 12:31:23 +0100
commitef1d8e7250776a282eec3183d413141448a7be2f (patch)
treed75ea95b91fead9606b70a1175866411e9d6442e
parenta75955f0a243c8359d556b4927cb310472986480 (diff)
create_remote_repo: allow to list config sections
-rw-r--r--docs/manpages/gbp-create-remote-repo.sgml8
-rw-r--r--gbp/scripts/create_remote_repo.py50
-rw-r--r--tests/27_test_create_remote_repo.py47
-rw-r--r--tests/data/gbp_create_remote_repo.conf8
4 files changed, 102 insertions, 11 deletions
diff --git a/docs/manpages/gbp-create-remote-repo.sgml b/docs/manpages/gbp-create-remote-repo.sgml
index b6135991..a1167e2f 100644
--- a/docs/manpages/gbp-create-remote-repo.sgml
+++ b/docs/manpages/gbp-create-remote-repo.sgml
@@ -30,6 +30,10 @@
<arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
<arg><option>--[no-]track</option></arg>
<arg><option>--[no-]bare</option></arg>
+ <group choice="opt">
+ <arg><replaceable>create</replaceable></arg>
+ <arg><replaceable>list</replaceable></arg>
+ </group>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
@@ -48,6 +52,10 @@
class="groupname">collab-maint</systemitem> repository on <systemitem
class="systemname">git.debian.org</systemitem>.
</para>
+ <para>
+ When invoked with <option>list</option> it lists the available
+ remote config templates.
+ </para>
</refsect1>
<refsect1>
<title>OPTIONS</title>
diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py
index da08a0ba..c05119e0 100644
--- a/gbp/scripts/create_remote_repo.py
+++ b/gbp/scripts/create_remote_repo.py
@@ -204,11 +204,18 @@ def push_branches(remote, branches):
gitPush([remote['url'], '--tags'])
+def usage_msg():
+ return """%prog [options] - create a remote git repository
+Actions:
+ create create the repository. This is the default when no action is
+ given.
+ list list available configuration templates for remote repositories"""
+
+
def build_parser(name, sections=[]):
try:
parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='',
- usage='%prog [options] - '
- 'create a remote repository',
+ usage=usage_msg(),
sections=sections)
except (GbpError, configparser.NoSectionError) as err:
gbp.log.err(err)
@@ -258,21 +265,19 @@ def parse_args(argv):
@param argv: the command line arguments
@type argv: C{list} of C{str}
"""
-
- # We simpley handle the template section as an additional config file
+ sections = []
+ # We handle the template section as an additional config file
# section to parse, this makes e.g. --help work as expected:
for arg in argv:
if arg.startswith('--remote-config='):
sections = ['remote-config %s' % arg.split('=', 1)[1]]
break
- else:
- sections = []
parser = build_parser(argv[0], sections)
if not parser:
- return None, None
+ return None, None, None
- return parser.parse_args(argv)
+ return list(parser.parse_args(argv)) + [parser.config_file_sections]
def do_create(options):
@@ -353,11 +358,29 @@ def do_create(options):
return retval
+def get_config_names(sections):
+ config_names = []
+ for section in sections:
+ if section.startswith("remote-config "):
+ config_names.append(section.split(' ', 1)[1])
+ return config_names
+
+
+def do_list(sections):
+ names = get_config_names(sections)
+ if names:
+ gbp.log.info("Available remote config templates:")
+ for n in names:
+ print(" %s" % n)
+ else:
+ gbp.log.info("No remot config templates found.")
+ return 0
+
+
def main(argv):
retval = 1
- options, args = parse_args(argv)
-
+ options, args, sections = parse_args(argv)
if not options:
return ExitCodes.parse_error
@@ -370,7 +393,12 @@ def main(argv):
return 1
action = args[1]
- retval = do_create(options)
+ if action == 'create':
+ retval = do_create(options)
+ elif action == 'list':
+ retval = do_list(sections)
+ else:
+ gbp.log.error("Unknown action '%s'" % action)
return retval
diff --git a/tests/27_test_create_remote_repo.py b/tests/27_test_create_remote_repo.py
new file mode 100644
index 00000000..7ab3c51f
--- /dev/null
+++ b/tests/27_test_create_remote_repo.py
@@ -0,0 +1,47 @@
+# vim: set fileencoding=utf-8 :
+# (C) 2016 Guido Günther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, please see
+# <http://www.gnu.org/licenses/>
+"""Test the L{gbp} create_remote_repo command"""
+
+import os
+import unittest
+import gbp.scripts.create_remote_repo as create_remote_repo
+
+
+class TestGbpCreateRemoteRepoCommand(unittest.TestCase):
+ def setUp(self):
+ self.conffiles_save = os.environ.get('GBP_CONF_FILES')
+
+ def tearDown(self):
+ if self.conffiles_save:
+ os.environ['GBP_CONF_FILES'] = self.conffiles_save
+
+ def test_no_config_templates(self):
+ self.confname = 'tests/data/gbp_nonexistent.conf'
+ self.assertFalse(os.path.exists(self.confname))
+ os.environ['GBP_CONF_FILES'] = self.confname
+
+ _, _, sections = create_remote_repo.parse_args(['create-remote-repo'])
+ self.assertEqual(create_remote_repo.get_config_names(sections),
+ [])
+
+ def test_list_config_templates(self):
+ self.confname = 'tests/data/gbp_create_remote_repo.conf'
+ self.assertTrue(os.path.exists(self.confname))
+ os.environ['GBP_CONF_FILES'] = self.confname
+
+ _, _, sections = create_remote_repo.parse_args(['create-remote-repo'])
+ self.assertEqual(create_remote_repo.get_config_names(sections),
+ ['config1', 'config2'])
diff --git a/tests/data/gbp_create_remote_repo.conf b/tests/data/gbp_create_remote_repo.conf
new file mode 100644
index 00000000..15c440de
--- /dev/null
+++ b/tests/data/gbp_create_remote_repo.conf
@@ -0,0 +1,8 @@
+# Data for TestGbpCreateRemoteRepo
+
+[remote-config config1]]
+remote-url-pattern = ssh://git.debian.org/git/pkg-libvirt/%(pkg)s.git
+template-dir = /srv/alioth.debian.org/chroot/home/groups/pkg-libvirt/git-template
+
+[remote-config config2]
+remote-url-pattern = ssh://git.debian.org/git/calendarserver/%(pkg)s.git