-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate_readme_table.py
More file actions
65 lines (46 loc) · 1.58 KB
/
update_readme_table.py
File metadata and controls
65 lines (46 loc) · 1.58 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
from pathlib import Path
import db as db_lib
README_PATH = Path('readme.md')
SPLIT_AT_STR = 'ID | Description | Tags | Versions | Options'
def make_table() -> str:
"""
Build the Markdown table string
"""
db = db_lib.Database.load_from_default_file()
lines = []
lines.append('ID | Description | Tags | Versions | Options')
lines.append('-- | ----------- | ---- | -------- | -------')
for id in sorted(db.entries):
entry = db.entries[id]
if entry.tags:
tags_str = ' ' + entry.comma_separated_tags_str()
else:
tags_str = ''
if entry.fixed_in:
versions_str = f' Fixed in: {entry.comma_separated_fixed_in_str()}'
elif entry.only_in:
versions_str = f' Only in: {entry.comma_separated_only_in_str()}'
else:
versions_str = ''
if entry.options:
options = list(entry.options)
else:
options = ['on']
options.append('off')
options_str = ', '.join(options)
lines.append(
f'**{id}**'
f' | {entry.name}'
f' |{tags_str}'
f' |{versions_str}'
f' | {options_str}')
lines.append('')
return '\n'.join(lines)
def main() -> None:
readme = README_PATH.read_text(encoding='utf-8')
if SPLIT_AT_STR not in readme:
raise ValueError(f"Couldn't find {SPLIT_AT_STR!r} in the readme")
new_readme = readme.split(SPLIT_AT_STR)[0] + make_table()
README_PATH.write_text(new_readme, encoding='utf-8')
if __name__ == '__main__':
main()