forked from GeoscienceAustralia/shakemap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
makedocs.py
executable file
·129 lines (111 loc) · 5.64 KB
/
makedocs.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python
import argparse
import os.path
import sys
import pathlib
from impactutils.io.cmd import get_command_output
def main(args):
# -------------------------------------------------------------
# Some additional useful directories
# -------------------------------------------------------------
REPO_DIR = os.path.dirname(os.path.abspath(__file__))
SHAKEMAP_PACKAGE_DIR = os.path.join(REPO_DIR, 'shakemap')
SHAKELIB_PACKAGE_DIR = os.path.join(REPO_DIR, 'shakelib')
DOC_SRC_DIR = os.path.join(REPO_DIR, 'doc_source')
SHAKEMAP_API_DIR = os.path.join(DOC_SRC_DIR, 'apidoc')
SHAKELIB_API_DIR = os.path.join(DOC_SRC_DIR, 'shakelib')
DOCS_DIR = os.path.join(REPO_DIR, 'docs')
# -------------------------------------------------------------
# get the human-friendly version of the ShakeMap version
# -------------------------------------------------------------
verstr = '4.0a'
# -------------------------------------------------------------
# what is the package called and who are the authors
# -------------------------------------------------------------
SHAKEMAP_PACKAGE = "ShakeMap 4.0a API"
SHAKELIB_PACKAGE = "ShakeLib API"
AUTHORS = 'Bruce Worden, Eric Thompson, Mike Hearne'
# -------------------------------------------------------------
# run the api doc command; this creates the .rst files
# -------------------------------------------------------------
# First clear out the apidoc and shakelib directory
for f in os.listdir(SHAKEMAP_API_DIR):
fpath = os.path.join(SHAKEMAP_API_DIR, f)
if os.path.isfile(fpath):
os.unlink(fpath)
for f in os.listdir(SHAKELIB_API_DIR):
fpath = os.path.join(SHAKELIB_API_DIR, f)
if os.path.isfile(fpath):
os.unlink(fpath)
sys.stderr.write('Building shakemap API documentation (REST)...\n')
sphinx_cmd = 'sphinx-apidoc -o %s -f -e -d 12 -H "%s" -A "%s"'\
' -V %s -T %s' % (SHAKEMAP_API_DIR, SHAKEMAP_PACKAGE,
AUTHORS, verstr,
SHAKEMAP_PACKAGE_DIR)
res, stdout, stderr = get_command_output(sphinx_cmd)
if not res:
raise Exception('Could not build ShakeMap API documentation'
' - error "%s".' % stderr.decode())
if args.verbose:
print(stdout.decode('utf-8'))
print(stderr.decode('utf-8'))
sys.stderr.write('Building shakelib API documentation (REST)...\n')
sphinx_cmd = 'sphinx-apidoc -o %s -f -e -d 12 -H "%s" -A "%s"'\
' -V %s -T %s shakelib/rupture/gc2\.py' % \
(SHAKELIB_API_DIR, SHAKELIB_PACKAGE, AUTHORS, verstr,
SHAKELIB_PACKAGE_DIR)
res, stdout, stderr = get_command_output(sphinx_cmd)
if not res:
raise Exception('Could not build ShakeLib API documentation'
' - error "%s".' % stderr.decode())
if args.verbose:
print(stdout.decode('utf-8'))
print(stderr.decode('utf-8'))
# --------------------------------------------
# try to clean up some of the excess labeling
# --------------------------------------------
clean_cmd = "sed -e 's/ module//g' -i '' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % SHAKEMAP_API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
clean_cmd = "sed -e 's/ package//g' -i '' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % SHAKEMAP_API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
clean_cmd = "sed -e '/Subpackages/d' -i '' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % SHAKEMAP_API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
clean_cmd = "sed -e '/-.*-/d' -i '' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % SHAKEMAP_API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
clean_cmd = "sed -e 's/ module//g' -i '' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % SHAKELIB_API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
clean_cmd = "sed -e 's/ package//g' -i '' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % SHAKELIB_API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
clean_cmd = "sed -e '/Subpackages/d' -i '' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % SHAKELIB_API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
clean_cmd = "sed -e '/-.*-/d' -i '' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % SHAKELIB_API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
# -------------------------------------------------------------
# Go to the api directory and build the html
# -------------------------------------------------------------
sys.stderr.write('Building shakemap manual (HTML)...\n')
res, stdout, stderr = get_command_output('sphinx-build -a -E %s %s'
% (DOC_SRC_DIR, DOCS_DIR))
if not res:
raise Exception('Could not build HTML. - '
'error "%s"' % stderr.decode())
if args.verbose:
print(stdout.decode('utf-8'))
print(stderr.decode('utf-8'))
pathlib.Path(os.path.join(DOCS_DIR, '.nojekyll')).touch(exist_ok=True)
if __name__ == '__main__':
desc = 'Create API documentation for ShakeMap and optionally post '\
'HTML output to GitHub.'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='Produce more output to the screen. ')
pargs = parser.parse_args()
main(pargs)