-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild_doc
executable file
·63 lines (52 loc) · 1.64 KB
/
build_doc
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
#!/usr/bin/env python3
import os
import copy
import re
import subprocess
from alcf.cmds import CMDS
from alcf.cmds import main
MAN_FOOTER = '''
## COPYRIGHT
Copyright © 2019–2024 Peter Kuma, Adrian J. McDonald, Olaf Morgenstern, Richard
Querel, Israel Silber and Connor J. Flynn.
## BUG REPORTING
Report bugs to Peter Kuma (<[email protected]>).
## SEE ALSO
'''
def md_to_man(md, cmd, cmds):
man = md
man = re.sub(r'^[\*\-] `([^`]*)`: (.*)', r'* `\1`:\n\2\n', man, flags=re.M)
man = re.sub(r'^\#\# (.*)', lambda s: s.group(0).upper(), man, flags=re.M)
man = re.sub(r'^(.*)\n--+\n$', lambda s: s.group(0).upper(), man, flags=re.M)
man += MAN_FOOTER
man += ', '.join([
('alcf-%s(1)' % cmd2 if cmd2 != 'main' else 'alcf(1)')
for cmd2 in cmds if cmd2 != cmd
])
return man
def get_vars():
vars = {}
for k, cmd in CMDS.items():
vars['cmd_%s' % k] = cmd.__doc__
vars['cmd_main'] = main.run.__doc__
for file in os.listdir('doc'):
filename = os.path.join('doc', file)
if os.path.isfile(filename) and file.endswith('.md'):
vars[file[:-3]] = open(filename).read()
return vars
def build_cmds():
for k, cmd in {**CMDS, **{'main': main.run}}.items():
filename = os.path.join('docs/_includes', 'cmd_%s.md' % k)
print('-> %s' % filename)
with open(filename, 'w') as f:
f.write(cmd.__doc__)
if k == 'main':
filename = os.path.join('man', 'alcf.1.ronn')
else:
filename = os.path.join('man', 'alcf-%s.1.ronn' % k)
print('-> %s' % filename)
with open(filename, 'w') as f:
f.write(md_to_man(cmd.__doc__, k, ['main'] + sorted(CMDS)))
subprocess.run(['ronn', '-r', filename], check=True)
if __name__ == '__main__':
build_cmds()