forked from developers-against-repressions/case-212
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_readme.py
executable file
·58 lines (43 loc) · 1.51 KB
/
update_readme.py
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
#!/usr/bin/env python3
import os
import re
class InvalidFileFormatException(Exception):
pass
def load_signed():
signed = []
pattern1 = re.compile(r'([^|]+)\|([^|]+)$')
pattern2 = re.compile(r'\s*\|([^|]+)\|([^|]+)\|\s*$')
dir = 'signed'
for basename in os.listdir(dir):
filename = os.path.join(dir, basename)
if not os.path.isfile(filename):
print('Skipping non-file "%s"' % filename)
continue
with open(filename) as inp:
for i, line in enumerate(inp):
line = line.strip()
if not line:
continue
m = re.match(pattern1, line) or re.match(pattern2, line)
if not m and line:
raise InvalidFileFormatException(
'File "%s", line %d: line does not follow the format:\n\t"%s"'
% (filename, i + 1, line)
)
signed.append((m.group(1).strip(), m.group(2).strip()))
return signed
def write_signed(signed, outp):
for signature in signed:
outp.write('| %-30s | %-50s |\n' % signature)
def update_readme(signed):
with open('pre-readme.md') as inp, open('README.md', 'w') as outp:
for line in inp:
if line.strip() == '<!-- Signed -->':
write_signed(signed, outp)
else:
outp.write(line)
def main():
signed = load_signed()
update_readme(signed)
if __name__ == '__main__':
main()