-
Notifications
You must be signed in to change notification settings - Fork 2
/
sendto
executable file
·62 lines (54 loc) · 1.8 KB
/
sendto
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
#! /usr/bin/python3
import subprocess
import sys
from os.path import exists
GET_MAINTAINER_PATH = "./scripts/get_maintainer.pl"
if not exists(GET_MAINTAINER_PATH):
raise Exception(f"Can't find {GET_MAINTAINER_PATH}, "
"are you in linux directory?")
argv = sys.argv
if len(argv) < 2:
raise Exception("Usage: $ sendto <patch_file>")
if argv[1][-6:] != '.patch':
raise Exception("Need .patch file (check arg)")
cmd = [f"{GET_MAINTAINER_PATH}", argv[1]]
try:
result = subprocess.run(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except:
print(f"subprocess.run failure... "
"Potentially lacking permissions for {GET_MAINTAINER_PATH}")
get_maintainer_output = result.stdout.decode('UTF-8')
get_maintainer_errors = result.stderr.decode('UTF-8')
if len(get_maintainer_errors):
raise Exception(f"error in {GET_MAINTAINER_PATH}, check patch file")
lines = []
for line in get_maintainer_output.split('\n')[:-1]:
line = line.strip()
idx_of_paren = line.index('(')
before = line[0:idx_of_paren - 1]
before = before.replace('"', '')
after = line[idx_of_paren + 1:-1]
lines.append((before, after))
TO = '--to '
CC = '--cc '
send_info = []
for (before, after) in lines:
is_maintainer = ('maintainer' in after)
res = (TO if is_maintainer else CC) + f'"{before}"'
send_info.append(res)
warns = []
clean = " \\\n".join(send_info)
if '--to' not in clean and '--cc' not in clean:
warns.append(f"No recipients, manually check {GET_MAINTAINER_PATH}")
elif '--to' not in clean:
warns.append(f"Lack of --to, manually check {GET_MAINTAINER_PATH}")
output = \
f'''
git send-email \\
{clean} {argv[1]}
{''.join(f'# Warning: {warn}' for warn in warns)}
{get_maintainer_errors}
'''
print(output, end='')