-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoose
executable file
·71 lines (55 loc) · 1.9 KB
/
choose
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
"""Usage: choose (merger|reviewer) [PROJECT] [--noob] [--not NAME...]
Project defaults to nengo.
Examples
--------
choose merger
Chooses a merger among nengo experts.
choose reviewer nengo_ocl --noob
Chooses a reviewer among nengo_ocl non-experts.
See man choose for more information.
"""
import argparse
import json
import os.path
import random
import sys
if __name__ != '__main__':
raise ImportError("Don't import me, bro!")
roles = ["merger", "reviewer"]
projects = ["nengo", "nengo_gui", "nengo_ocl"]
# Process command line args
parser = argparse.ArgumentParser()
parser.add_argument('role', type=str)
parser.add_argument('project', type=str, nargs='?', default="nengo")
parser.add_argument('--noob', dest='expert', action='store_const',
const=False, default=True)
parser.add_argument('--not', dest='exclude', nargs='+', default=[])
args = parser.parse_args()
role = args.role
project = args.project
expert = args.expert
if role not in roles:
sys.exit(__doc__)
if project not in projects:
print("%s not recognized. Including all contributors." % project)
project = None
# Read contributors.json into a list
contrib_f = os.path.join(os.path.dirname(__file__), "contributors.json")
with open(contrib_f, 'r') as fp:
contribs = json.load(fp)
# Filter list based on role and expertise
contribs = [contrib for contrib in contribs
if contrib[role] and (project in contrib["expertise"]) == expert]
# Exclude any specified names
for name in args.exclude:
contribs = [contrib for contrib in contribs
if name not in contrib["name"].lower()]
# Can we choose someone?
if len(contribs) == 0:
print("Sorry, no one meets that description! Relax your requirements.")
else:
# Choose someone!
contrib = random.choice(contribs)
print("The lucky %s is %s!\nIf that doesn't work, run this again." % (
role, contrib["name"]))