-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_rfcs.py
More file actions
67 lines (52 loc) · 1.79 KB
/
process_rfcs.py
File metadata and controls
67 lines (52 loc) · 1.79 KB
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
import pathlib
import sys
sourcedir = pathlib.Path(sys.argv[1])
destdir = pathlib.Path(sys.argv[2])
rfcs = []
for rfc in sourcedir.glob('RFC-*.rst'):
if rfc.name.startswith(('RFC-000', 'RFC-template')):
continue
n = rfc.name.split('-')[1]
with open(rfc, 'r', encoding='utf-8') as f:
lines = f.readlines()
assert lines[0].startswith('- Feature: ')
raw_title = lines[0][10:].strip()
title = f'RFC {n}: {raw_title}'
assert lines[1].startswith('- Status: ')
status = lines[1][10:].strip()
lines[:1] = [
'.. _rfc-' + n + ':\n',
'\n',
title + '\n',
'@' * len(title) + '\n',
'\n',
]
new_name = rfc.name.removeprefix('RFC-')
dest_file = destdir / new_name
with open(dest_file, 'w', encoding='utf-8') as f:
f.writelines(lines)
rfcs.append((new_name.removesuffix('.rst'), n, raw_title, status))
rfcs.sort()
with open(destdir / 'index.rst', 'r', encoding='utf-8') as f:
lines = f.readlines()
with open(destdir / 'index.rst', 'w', encoding='utf-8') as f:
for line in lines:
if line.strip() == '.. toctree::':
f.write(line)
f.write(' :maxdepth: 1\n')
f.write(' :hidden:\n\n')
for ref in rfcs:
f.write(f' {ref[0]}\n')
f.write('\n')
f.write('.. list-table::\n')
f.write(' :widths: 10 70 20\n')
f.write(' :header-rows: 1\n\n')
f.write(' * - #\n')
f.write(' - Title\n')
f.write(' - Status\n')
for ref, n, title, status in rfcs:
f.write(f' * - {n}\n')
f.write(f' - :ref:`{title} <rfc-{n}>`\n')
f.write(f' - {status}\n')
break
f.write(line)