Commit ef1d8e72 authored by Guido Günther's avatar Guido Günther

create_remote_repo: allow to list config sections

parent a75955f0
......@@ -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>
......
......@@ -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
......
# 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'])
# 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment