|
| 1 | +#! /usr/bin/python3 |
| 2 | +import subprocess |
| 3 | +import sys |
| 4 | +from os.path import exists |
| 5 | +GET_MAINTAINER_PATH = "./scripts/get_maintainer.pl" |
| 6 | +if not exists(GET_MAINTAINER_PATH): |
| 7 | + raise Exception(f"Can't find {GET_MAINTAINER_PATH}, " |
| 8 | + "are you in linux directory?" |
| 9 | + ) |
| 10 | + |
| 11 | +argv = sys.argv |
| 12 | +if len(argv) < 2: |
| 13 | + raise Exception("Usage: $ sendto <patch_file>") |
| 14 | +if argv[1][-6:] != '.patch': |
| 15 | + raise Exception("Need .patch file (check arg)") |
| 16 | +cmd = [f"{GET_MAINTAINER_PATH}", argv[1]] |
| 17 | +try: |
| 18 | + result = subprocess.run(cmd, stdout=subprocess.PIPE, |
| 19 | + stderr=subprocess.PIPE) |
| 20 | +except: |
| 21 | + print(f"subprocess.run failure... " |
| 22 | + "Potentially lacking permissions for {GET_MAINTAINER_PATH}" |
| 23 | + ) |
| 24 | + |
| 25 | +get_maintainer_output = result.stdout.decode('UTF-8') |
| 26 | +get_maintainer_errors = result.stderr.decode('UTF-8') |
| 27 | +if len(get_maintainer_errors): |
| 28 | + raise Exception(f"error in {GET_MAINTAINER_PATH}, check patch file") |
| 29 | + |
| 30 | +lines = [] |
| 31 | +for line in get_maintainer_output.split('\n')[:-1]: |
| 32 | + line = line.strip() |
| 33 | + idx_of_paren = line.index('(') |
| 34 | + before = line[0:idx_of_paren-1] |
| 35 | + before = before.replace('"', '') |
| 36 | + after = line[idx_of_paren+1:-1] |
| 37 | + lines.append((before, after)) |
| 38 | + |
| 39 | +TO = '--to ' |
| 40 | +CC = '--cc ' |
| 41 | +send_info = [] |
| 42 | +for (before, after) in lines: |
| 43 | + is_maintainer = ('maintainer' in after) |
| 44 | + res = (TO if is_maintainer else CC) + f'"{before}"' |
| 45 | + send_info.append(res) |
| 46 | + |
| 47 | +warns = [] |
| 48 | +clean = " \\\n".join(send_info) |
| 49 | +if '--to' not in clean and '--cc' not in clean: |
| 50 | + warns.append(f"No recipients, manually check {GET_MAINTAINER_PATH}") |
| 51 | +elif '--to' not in clean: |
| 52 | + warns.append(f"Lack of --to, manually check {GET_MAINTAINER_PATH}") |
| 53 | + |
| 54 | +output = \ |
| 55 | +f''' |
| 56 | +git send-email \\ |
| 57 | +{clean} {argv[1]} |
| 58 | +
|
| 59 | +{''.join(f'# Warning: {warn}' for warn in warns)} |
| 60 | +{get_maintainer_errors} |
| 61 | +''' |
| 62 | +print(output, end='') |
0 commit comments