diff options
author | Guido Günther <agx@sigxcpu.org> | 2014-04-02 22:13:46 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2014-04-03 20:34:07 +0200 |
commit | 459d9bfcce481b0da71e9493e644488c83e0e9ba (patch) | |
tree | 4fa6b653354cba87f5da0953b151d54af474a5bb /gbp/scripts/create_remote_repo.py | |
parent | b393080ac3b98342b53849d14049db024183f0cb (diff) |
config: add decorator to add_option_* functions
This allows us to build an internal list of valid options and print
these.
Diffstat (limited to 'gbp/scripts/create_remote_repo.py')
-rw-r--r-- | gbp/scripts/create_remote_repo.py | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py index c8c4a36a..f0e680b4 100644 --- a/gbp/scripts/create_remote_repo.py +++ b/gbp/scripts/create_remote_repo.py @@ -18,6 +18,7 @@ # Based on the aa-create-git-repo and dom-new-git-repo shell scripts """Create a remote repo based on the current one""" +import ConfigParser import sys import os, os.path import urlparse @@ -225,30 +226,16 @@ def push_branches(remote, branches): gitPush([remote['url'], '--tags']) -def parse_args(argv, sections=[]): - """ - Parse the command line arguments and config files. - - @param argv: the command line arguments - @type argv: C{list} of C{str} - @param sections: additional sections to add to the config file parser - besides the command name - @type sections: C{list} of C{str} - """ - - # We simpley 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 = [] +def build_parser(name, sections=[]): + try: + parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='', + usage='%prog [options] - ' + 'create a remote repository', + sections=sections) + except ConfigParser.ParsingError as err: + gbp.log.err(err) + return None - parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='', - usage='%prog [options] - ' - 'create a remote repository', - sections=sections) branch_group = GbpOptionGroup(parser, "branch options", "branch layout and tracking options") @@ -281,10 +268,34 @@ def parse_args(argv, sections=[]): dest="template_dir") parser.add_config_file_option(option_name="remote-config", dest="remote_config") + return parser + + +def parse_args(argv, sections=[]): + """ + Parse the command line arguments and config files. + + @param argv: the command line arguments + @type argv: C{list} of C{str} + @param sections: additional sections to add to the config file parser + besides the command name + @type sections: C{list} of C{str} + """ + + # We simpley 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 = [] - (options, args) = parser.parse_args(argv) + parser = build_parser(argv[0], sections) + if not parser: + return None, None - return options, args + return parser.parse_args(argv) def main(argv): |