mirror of
https://git.centos.org/centos/centpkg.git
synced 2025-02-23 08:12:55 +00:00
dynamic cli with no need for sig extra checks
This commit is contained in:
parent
0a698c7890
commit
794ab0a8b7
4 changed files with 19 additions and 32 deletions
|
@ -16,5 +16,5 @@
|
|||
from centpkg.__main__ import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sig=False)
|
||||
main()
|
||||
|
||||
|
|
|
@ -17,5 +17,5 @@
|
|||
from centpkg.__main__ import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sig=True)
|
||||
main()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue