-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
add_old_links.py
41 lines (31 loc) · 1.5 KB
/
add_old_links.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
"""
Adds an entry to the table listing old versions on the documentation homepage.
"""
from operator import le
import pathlib
import sys
HERE = pathlib.Path(__file__).parent
INDEX = HERE / 'src' / 'index.qmd'
ROW = "| {major}.{minor} | [html](https://mc-stan.org/docs/{major}_{minor}/reference-manual/) [pdf](https://mc-stan.org/docs/{major}_{minor}/reference-manual-{major}_{minor}.pdf) | [html](https://mc-stan.org/docs/{major}_{minor}/stan-users-guide/) [pdf](https://mc-stan.org/docs/{major}_{minor}/stan-users-guide-{major}_{minor}.pdf) | [html](https://mc-stan.org/docs/{major}_{minor}/cmdstan-guide/) [pdf](https://mc-stan.org/docs/{major}_{minor}/cmdstan-guide-{major}_{minor}.pdf) | [html](https://mc-stan.org/docs/{major}_{minor}/functions-reference/) [pdf](https://mc-stan.org/docs/{major}_{minor}/functions-reference-{major}_{minor}.pdf) |"
if __name__ == '__main__':
if len(sys.argv) != 3:
print('Usage: python add_old_links.py <version>')
sys.exit(1)
major = sys.argv[1]
minor = sys.argv[2]
row = ROW.format(major=major, minor=minor)
index = INDEX.read_text()
if row in index:
print('Row already exists')
sys.exit(1)
new_index = []
added = False
for line in index.splitlines():
new_index.append(line)
if not added and line.startswith('|---------|'):
new_index.append(row)
added = True
if not added:
print('Failed to add row')
sys.exit(1)
INDEX.write_text('\n'.join(new_index))