xref: /OK3568_Linux_fs/buildroot/utils/get-developers (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/usr/bin/env python3
2
3import argparse
4import getdeveloperlib
5import sys
6
7
8def parse_args():
9    parser = argparse.ArgumentParser()
10    parser.add_argument('patches', metavar='P', type=argparse.FileType('r'), nargs='*',
11                        help='list of patches (use - to read patches from stdin)')
12    parser.add_argument('-a', dest='architecture', action='store',
13                        help='find developers in charge of this architecture')
14    parser.add_argument('-p', dest='package', action='store',
15                        help='find developers in charge of this package')
16    parser.add_argument('-f', dest='files', nargs='*',
17                        help='find developers in charge of these files')
18    parser.add_argument('-c', dest='check', action='store_const',
19                        const=True, help='list files not handled by any developer')
20    parser.add_argument('-e', dest='email', action='store_const',
21                        const=True, help='only list affected developer email addresses')
22    return parser.parse_args()
23
24
25def __main__():
26    args = parse_args()
27
28    # Check that only one action is given
29    action = 0
30    if args.architecture is not None:
31        action += 1
32    if args.package is not None:
33        action += 1
34    if args.files:
35        action += 1
36    if args.check:
37        action += 1
38    if len(args.patches) != 0:
39        action += 1
40    if action > 1:
41        print("Cannot do more than one action")
42        return
43    if action == 0:
44        print("No action specified")
45        return
46
47    devs = getdeveloperlib.parse_developers()
48    if devs is None:
49        sys.exit(1)
50
51    # Handle the check action
52    if args.check:
53        files = getdeveloperlib.check_developers(devs)
54        for f in files:
55            print(f)
56
57    # Handle the architecture action
58    if args.architecture is not None:
59        for dev in devs:
60            if args.architecture in dev.architectures:
61                print(dev.name)
62        return
63
64    # Handle the package action
65    if args.package is not None:
66        for dev in devs:
67            if args.package in dev.packages:
68                print(dev.name)
69        return
70
71    # Handle the files action
72    if args.files is not None:
73        for dev in devs:
74            for f in args.files:
75                if dev.hasfile(f):
76                    print(dev.name)
77                    break
78
79    # Handle the patches action
80    if len(args.patches) != 0:
81        (files, infras) = getdeveloperlib.analyze_patches(args.patches)
82        matching_devs = set()
83        for dev in devs:
84            # See if we have developers matching by package name
85            for f in files:
86                if dev.hasfile(f):
87                    matching_devs.add(dev.name)
88            # See if we have developers matching by package infra
89            for i in infras:
90                if i in dev.infras:
91                    matching_devs.add(dev.name)
92
93        if args.email:
94            for dev in matching_devs:
95                print(dev)
96        else:
97            result = "--to buildroot@buildroot.org"
98            for dev in matching_devs:
99                result += " --cc \"%s\"" % dev
100
101            if result != "":
102                print("git send-email %s" % result)
103
104
105__main__()
106