]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - utils/get-developers
clamav: reformat patches as Git-formatted patches
[coffee/buildroot.git] / utils / get-developers
1 #!/usr/bin/env python
2
3 import argparse
4 import getdeveloperlib
5 import sys
6 import os
7
8
9 def parse_args():
10     parser = argparse.ArgumentParser()
11     parser.add_argument('patches', metavar='P', type=argparse.FileType('r'), nargs='*',
12                         help='list of patches (use - to read patches from stdin)')
13     parser.add_argument('-a', dest='architecture', action='store',
14                         help='find developers in charge of this architecture')
15     parser.add_argument('-p', dest='package', action='store',
16                         help='find developers in charge of this package')
17     parser.add_argument('-f', dest='files', nargs='*',
18                         help='find developers in charge of these files')
19     parser.add_argument('-c', dest='check', action='store_const',
20                         const=True, help='list files not handled by any developer')
21     return parser.parse_args()
22
23
24 def __main__():
25     devs = getdeveloperlib.parse_developers()
26     if devs is None:
27         sys.exit(1)
28     args = parse_args()
29
30     # Check that only one action is given
31     action = 0
32     if args.architecture is not None:
33         action += 1
34     if args.package is not None:
35         action += 1
36     if args.files:
37         action += 1
38     if args.check:
39         action += 1
40     if len(args.patches) != 0:
41         action += 1
42     if action > 1:
43         print("Cannot do more than one action")
44         return
45     if action == 0:
46         print("No action specified")
47         return
48
49     # Handle the check action
50     if args.check:
51         files = getdeveloperlib.check_developers(devs)
52         for f in files:
53             print(f)
54
55     # Handle the architecture action
56     if args.architecture is not None:
57         for dev in devs:
58             if args.architecture in dev.architectures:
59                 print(dev.name)
60         return
61
62     # Handle the package action
63     if args.package is not None:
64         for dev in devs:
65             if args.package in dev.packages:
66                 print(dev.name)
67         return
68
69     # Handle the files action
70     if args.files is not None:
71         args.files = [os.path.abspath(f) for f in args.files]
72         for dev in devs:
73             for devfile in dev.files:
74                 commonfiles = [f for f in args.files if f.startswith(devfile)]
75                 if commonfiles:
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         result = "--to buildroot@buildroot.org"
94         for dev in matching_devs:
95             result += " --cc \"%s\"" % dev
96
97         if result != "":
98             print("git send-email %s" % result)
99
100
101 __main__()