aboutsummaryrefslogtreecommitdiff
blob: 6c722a9b399135b118355c83e947f2c5d687356c (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
#!/usr/bin/env python3

import sys
import xml.etree.ElementTree as ET

from http.client import HTTPSConnection
from typing import Iterator, NamedTuple
from urllib.parse import quote_plus


class Maintainer(NamedTuple):
    name: str
    email: str

    def check_details(self, client: HTTPSConnection):
        try:
            client.request("GET", f"/rest/user?names={quote_plus(self.email)}")
            resp = client.getresponse()
            resp.read()
            return resp.status == 200
        except Exception:
            return False


def read_all_maintainers(files: Iterator[str]) -> Iterator[Maintainer]:
    for file in files:
        try:
            tree = ET.parse(file)
            for maintainer in tree.findall('./maintainer'):
                values = {child.tag: child.text for child in maintainer}
                yield Maintainer(name=values.get('name', ''), email=values.get('email', ''))
        except FileNotFoundError:
            print(file, 'not found')


def check_maintainers(maintainers: Iterator[Maintainer]) -> Iterator[Maintainer]:
    try:
        client = HTTPSConnection('bugs.gentoo.org')
        for m in maintainers:
            if m.check_details(client):
                print(f'\033[92m\u2713 {m.name} <{m.email}>\033[0m')
            else:
                print(f'\033[91m\u2717 {m.name} <{m.email}>\033[0m')
                yield m
    finally:
        client.close()


if __name__ == '__main__':
    try:
        files = input().split()
    except EOFError:
        sys.exit(0)

    maintainers = set(read_all_maintainers(files))
    missing_maintainers = tuple(check_maintainers(maintainers))
    sys.exit(int(len(missing_maintainers) != 0))