aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo/commands/github.py
blob: 3d600bccb25dd6f7fc90e9b874dde727ec0adbd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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_clone(pkg, **kwargs):
    github = GitHub()
    github.clone_repository(pkg)

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" or args[0] == "clone":
        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