From 794ab0a8b74b96d63dc4b46aeecba48cf4ca6fef Mon Sep 17 00:00:00 2001 From: lrossett Date: Apr 13 2021 23:38:20 +0000 Subject: dynamic cli with no need for sig extra checks --- diff --git a/src/bin/centpkg b/src/bin/centpkg index 040626d..adc5811 100755 --- a/src/bin/centpkg +++ b/src/bin/centpkg @@ -16,5 +16,5 @@ from centpkg.__main__ import main if __name__ == "__main__": - main(sig=False) + main() diff --git a/src/bin/centpkg-sig b/src/bin/centpkg-sig index 156c43a..f45d33f 100644 --- a/src/bin/centpkg-sig +++ b/src/bin/centpkg-sig @@ -17,5 +17,5 @@ from centpkg.__main__ import main if __name__ == "__main__": - main(sig=True) + main() diff --git a/src/centpkg/__main__.py b/src/centpkg/__main__.py index 68e5cd1..549e5b2 100644 --- a/src/centpkg/__main__.py +++ b/src/centpkg/__main__.py @@ -24,27 +24,22 @@ import pyrpkg.utils import centpkg.cli -def main(sig): +def main(): """ Centpkg main. - Params: - sig: Flag to switch between centpkg-sig and centpkg. """ # Setup an argparser and parse the known commands to get the config file program_name = os.path.basename(sys.argv[0]) # Modified ArgumentParser provides parameter "allow_abbrev=False" (which affects processing # of commandline arguments with common prefix). Generaly it is available since python3.6. + # This enables "allow_abbrev" for older python versions. parser = pyrpkg.cli.ArgumentParser(add_help=False) - if sig: - parser.add_argument('-C', '--config', help='Specify a config file to use', - default='/etc/rpkg/centpkg-sig.conf') - else: - parser.add_argument('-C', '--config', help='Specify a config file to use', - default='/etc/rpkg/centpkg.conf') + parser.add_argument('-C', '--config', help='Specify a config file to use', + default=f'/etc/rpkg/%s.conf' % program_name) (args, other) = parser.parse_known_args() @@ -57,10 +52,7 @@ def main(sig): config = ConfigParser.SafeConfigParser() config.read(args.config) - if sig: - client = centpkg.cli.centpkgClientSig(config) - else: - client = centpkg.cli.centpkgClient(config) + client = centpkg.cli.centpkgClient(config, name=program_name) client.do_imports(site='centpkg') client.parse_cmdline() diff --git a/src/centpkg/cli.py b/src/centpkg/cli.py index 61e3147..ac8a849 100755 --- a/src/centpkg/cli.py +++ b/src/centpkg/cli.py @@ -20,12 +20,17 @@ import textwrap from centpkg.utils import config_get_safely, do_add_remote, do_fork from pyrpkg.cli import cliClient +from pyrpkg import rpkgError from six.moves.urllib_parse import urlparse +_DEFAULT_API_BASE_URL = 'https://gitlab.com' + + class centpkgClient(cliClient): - def __init__(self, config, name=None): - self.DEFAULT_CLI_NAME = 'centpkg' + def __init__(self, config, name='centpkg'): + self.DEFAULT_CLI_NAME = name + super(centpkgClient, self).__init__(config, name) self.setup_centos_subparsers() @@ -36,7 +41,11 @@ class centpkgClient(cliClient): def register_do_fork(self): help_msg = 'Create a new fork of the current repository' distgit_section = '{0}.distgit'.format(self.name) - distgit_api_base_url = config_get_safely(self.config, distgit_section, "apibaseurl") + # uses default dist-git url in case section is not present + try: + distgit_api_base_url = config_get_safely(self.config, distgit_section, "apibaseurl") + except rpkgError: + distgit_api_base_url = _DEFAULT_API_BASE_URL description = textwrap.dedent(''' Create a new fork of the current repository @@ -115,17 +124,3 @@ class centpkgClient(cliClient): else: msg = "Remote with name '{0}' already exists." self.log.info(msg.format(self.cmd.user)) - - -class centpkgClientSig(cliClient): - def __init__(self, config, name=None): - self.DEFAULT_CLI_NAME = 'centpkg-sig' - super(centpkgClientSig, self).__init__(config, name) - - self.setup_centos_subparsers() - - def setup_centos_subparsers(self): - self.register_parser() - - def register_parser(self): - pass