From 6d64a6bebf611be4c273c839df8dee3ede5917fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Thu, 30 Jun 2016 22:51:36 +0200 Subject: change githubimport into a github command with several ~sub-commands --- MgaRepo/commands/github.py | 53 ++++++++++++++++++++++++++++++++++++++++ MgaRepo/commands/githubimport.py | 33 ------------------------- 2 files changed, 53 insertions(+), 33 deletions(-) create mode 100644 MgaRepo/commands/github.py delete mode 100644 MgaRepo/commands/githubimport.py (limited to 'MgaRepo') diff --git a/MgaRepo/commands/github.py b/MgaRepo/commands/github.py new file mode 100644 index 0000000..c2fd188 --- /dev/null +++ b/MgaRepo/commands/github.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +from MgaRepo import Error +from MgaRepo.command import * +from MgaRepo.GitHub import GitHub +import getopt +import sys + +HELP = """\ +Usage: mgarepo github [OPTIONS] URL + +Import a git-svn cloned repository to github + +Options: + -h Show this message + +Examples: + mgarepo github import existingpkg + mgarepo github import svn://svn.mageia.org/svn/packages/cauldron/existingpkg +""" + +def github_import(target=".", **kwargs): + github = GitHub() + github.import_package(target) + +def github_delete(pkg, **kwargs): + github = GitHub() + github.delete_repository(pkg) + +def parse_options(): + parser = OptionParser(help=HELP) + opts, args = parser.parse_args() + if len(args) < 2:#not in (2, 3): + raise Error("invalid arguments") + opts.func = globals().get("github_"+args[0], None) + if args[0] == "import": + opts.target = args[1] + elif args[0] == "delete": + opts.pkg = args[1] + else: + raise Error("invalid arguments: %s" % str(args)) + return opts + +def dispatch_cmd(*args, **kwargs): + func = kwargs.pop("func", None) + if func: + func(**kwargs) + else: + raise Error("invalid command: %s %s" % (sys.argv[0], sys.argv[1])) + +def main(): + do_command(parse_options, dispatch_cmd) + +# vim:et:ts=4:sw=4 diff --git a/MgaRepo/commands/githubimport.py b/MgaRepo/commands/githubimport.py deleted file mode 100644 index afc73c5..0000000 --- a/MgaRepo/commands/githubimport.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/python -from MgaRepo import Error -from MgaRepo.command import * -from MgaRepo.GitHub import GitHub -import getopt -import sys - -HELP = """\ -Usage: mgarepo github-import [OPTIONS] URL - -Import a git-svn cloned repository to github - -Options: - -h Show this message - -Examples: - mgarepo githubimport existingpkg - mgarepo githubimport svn+ssh://svn.mageia.org/svn/packages/cauldron/existingpkg -""" - -def githubimport(target="."): - github = GitHub() - github.import_package(target) - -def parse_options(): - parser = OptionParser(help=HELP) - opts, args = parser.parse_args() - return opts - -def main(): - do_command(parse_options, githubimport) - -# vim:et:ts=4:sw=4 -- cgit v1.2.1