-
Notifications
You must be signed in to change notification settings - Fork 38
/
build_docs.py
executable file
·68 lines (54 loc) · 2.57 KB
/
build_docs.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import extern
import logging
import argparse
import os
def remove_before(marker, string_to_process):
splitter = '\n' + marker + '\n'
return splitter + string_to_process.split(splitter)[1]
if __name__ == '__main__':
parent_parser = argparse.ArgumentParser(add_help=False)
# parent_parser.add_argument('--debug', help='output debug information', action="store_true")
# parent_parser.add_argument('--version', help='output version information and quit', action='version', version=repeatm.__version__)
parent_parser.add_argument('--quiet', help='only output errors', action="store_true")
args = parent_parser.parse_args()
# Setup logging
debug = True
if args.quiet:
loglevel = logging.ERROR
else:
loglevel = logging.DEBUG
logging.basicConfig(level=loglevel, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
for subcommand in ['get', 'extract', 'annotate']:
logging.info("Gathering doc for {}".format(subcommand))
cmd_stub = "bin/kingfisher {} --full-help-roff |pandoc - -t markdown-multiline_tables-simple_tables-grid_tables -f man |sed 's/\\\\\\[/[/g; s/\\\\\\]/]/g; s/^: //'".format(
subcommand)
man_usage = extern.run(cmd_stub)
subcommand_prelude = 'docs/usage/{}_prelude.md'.format(subcommand)
if os.path.exists(subcommand_prelude):
# Remove everything before the options section
splitters = {
'pipe': 'COMMON OPTIONS',
'data': 'OPTIONS',
'summarise': 'INPUT',
'makedb': 'REQUIRED ARGUMENTS',
'appraise': 'INPUT OTU TABLE OPTIONS',
}
man_usage = remove_before(splitters[subcommand], man_usage)
with open('docs/usage/{}.md'.format(subcommand), 'w') as f:
f.write('---\n')
f.write('title: Kingfisher {}\n'.format(subcommand))
f.write('---\n')
f.write('# kingfisher {}\n'.format(subcommand))
with open(subcommand_prelude) as f2:
f.write(f2.read())
f.write(man_usage)
else:
man_usage = remove_before('# DESCRIPTION', man_usage)
with open('docs/usage/{}.md'.format(subcommand), 'w') as f:
f.write('---\n')
f.write('title: Kingfisher {}\n'.format(subcommand))
f.write('---\n')
f.write('# kingfisher {}\n'.format(subcommand))
f.write(man_usage)
extern.run("doctave build")