This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_index.py
47 lines (40 loc) · 1.57 KB
/
generate_index.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
import os
from proposals import root_folder, walk, status_list
def update(fname, tmp_fname):
if not os.path.exists(fname):
os.rename(tmp_fname, fname)
print('Generated %s.' % fname)
return
with open(fname, encoding='utf-8', mode='rt') as f:
old = f.read()
with open(tmp_fname, encoding='utf-8', mode='rt') as f:
new = f.read()
if old == new:
print('No change to %s.' % fname)
os.remove(tmp_fname)
return
os.remove(fname)
os.rename(tmp_fname, fname)
print('Updated %s.' % fname)
def main(name, dir, fname):
fname = os.path.join(root_folder, fname)
# Load all metadata
all = [proposal for proposal in walk(dir)]
tmp_fname = fname + '.tmp'
with open(fname, 'r', encoding='utf-8') as curr, open(tmp_fname, 'w', encoding='utf-8') as out:
current = curr.read()
parts = current.split(f'## {name} Overview')
prefix = parts[0]
out.write(prefix)
out.write(f"## {name} Overview\n")
for status in status_list:
out.write(f"\n### {status}\n")
with_status = [proposal for proposal in all if proposal.status == status]
for proposal in with_status:
line = f"* [{proposal.title}]({proposal.relpath})"
out.write(line + '\n')
out.write("\n\n>(This file is machine-generated; see [code/generate_index.py](code/generate_index.py).)\n")
update(fname, tmp_fname)
if __name__ == '__main__':
main('Plugins', 'plugins', 'plugins.md')
main('Presets', 'presets', 'presets.md')