]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - utils/get-developers
Merge branch 'next'
[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 def 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     return parser.parse_args()
21
22 def __main__():
23     devs = getdeveloperlib.parse_developers()
24     if devs is None:
25         sys.exit(1)
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     # Handle the check action
48     if args.check:
49         files = getdeveloperlib.check_developers(devs)
50         for f in files:
51             print(f)
52
53     # Handle the architecture action
54     if args.architecture is not None:
55         for dev in devs:
56             if args.architecture in dev.architectures:
57                 print(dev.name)
58         return
59
60     # Handle the package action
61     if args.package is not None:
62         for dev in devs:
63             if args.package in dev.packages:
64                 print(dev.name)
65         return
66
67     # Handle the files action
68     if args.files is not None:
69         args.files = [os.path.abspath(f) for f in args.files]
70         for dev in devs:
71             for devfile in dev.files:
72                 commonfiles = [f for f in args.files if f.startswith(devfile)]
73                 if commonfiles:
74                     print(dev.name)
75                     break
76
77     # Handle the patches action
78     if len(args.patches) != 0:
79         (files, infras) = getdeveloperlib.analyze_patches(args.patches)
80         matching_devs = set()
81         for dev in devs:
82             # See if we have developers matching by package name
83             for f in files:
84                 if dev.hasfile(f):
85                     matching_devs.add(dev.name)
86             # See if we have developers matching by package infra
87             for i in infras:
88                 if i in dev.infras:
89                     matching_devs.add(dev.name)
90
91         result = "--to buildroot@buildroot.org"
92         for dev in matching_devs:
93             result += " --cc \"%s\"" % dev
94
95         if result != "":
96             print("git send-email %s" % result)
97
98 __main__()
99