aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo/commands/maintdb.py
blob: ad830b40e53d45aa9457e5881c64c7c77b454a1f (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
57
58
#!/usr/bin/python
from MgaRepo import Error, config
from MgaRepo.command import *
from MgaRepo.util import execcmd, get_helper
import sys


HELP = """\
Usage: 
    Take maintainership of one package :
       mgarepo maintdb set [package] [login]

    Remove yourself from maintainer of a package :
       mgarepo maintdb set [package] nobody

    See who is maintainer of a package :
       mgarepo maintdb get [package]

    See the list of all packages with their maintainer :
       mgarepo maintdb get

"""

def parse_options():
    parser = OptionParser(help=HELP)
    opts, args = parser.parse_args()
    if len(args):
        opts.maintdb_args = args
    else:
        raise Error("you need to provide arguments, see them with --help")
    return opts

def maintdb(maintdb_args):
    host = config.get("maintdb", "host", "maintdb.mageia.org")
    if (maintdb_args[0] == 'get' and len(maintdb_args)>=2):
        import urllib.request
        try:
            page=urllib.request.urlopen('http://'+host+'/'+maintdb_args[1])
            rep = page.read().decode('utf8')
        except urllib.error.HTTPError as e:
            if e.code == 404 :
                rep = "There is no package named {}".format(maintdb_args[1])
            else:
                rep = e.reason
        except Exception as e:
            rep = "Error trying to query the database : {}. Have you active Internet connection?".format(e.reason)
        print(rep)
    else:
        maintdb_helper = get_helper("maintdb")
        cmd_args = ' '.join(maintdb_args)
        command = "ssh %s %s %s" % (host, maintdb_helper, cmd_args)
        execcmd(command, show=True)
    sys.exit(0)

def main():
    do_command(parse_options, maintdb)

# vim:et:ts=4:sw=4