-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauto-sphinx.sh
More file actions
executable file
·139 lines (115 loc) · 4.45 KB
/
auto-sphinx.sh
File metadata and controls
executable file
·139 lines (115 loc) · 4.45 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
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
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
#How to use this shell script:
# This shell script will auto generate sphinx documentation.
# To generate entirely new documentation make sure that the
# working directory contains only a directory containing the code
# that is to be documented (hapi), the sphinx-answers
# file and this script. If this is what is required the directory
# should look like this:
# [sean@eigg sphinx_hapi]$ ls
# acq400_hapi auto-sphinx.sh sphinx-answers
# This works, but be careful:
# ls | grep -v hapi | grep -v auto-sphinx.sh | grep -v sphinx-answers | xargs rm -rf
# If documentation has already been created then this
# script can be used to generate new documentation without
# the need to rerun sphinx-quickstart. Just run this script and
# new html will be generated. Note that this will not change
# the project name inside conf.py.
# Terminal Example: source auto-sphinx.sh
# The following parameter is taken by this script.
which_docs_to_build=$1 # Take the first arg from the command line
if [ "$which_docs_to_build" = "" ]; then
echo "Please specify which docs you wish to build."
echo "Relevant commands to build docs:"
echo "./auto-sphinx acq400_hapi"
echo "./auto-sphinx user_apps"
exit
fi
SDIR=$(dirname $0)
ANS=$SDIR/sphinx-answers
find_hapi_dirs()
{
# find_hapi_dirs looks in the directory that this script is run
# from and checks if a hapi or hapi_tests directory exists.
# If both hapi and hapi_tests exist then it will choose hapi by default
if [ "$which_docs_to_build" = "acq400_hapi" ]; then
echo "DEBUG 1"
sed '3s/.*/acq400_hapi/' $ANS > $ANS.active
docs_name="acq400_hapi"
elif [ "$which_docs_to_build" = "user_apps" ]; then
echo "DEBUG 2"
sed '3s/.*/user_apps/' $ANS > $ANS.active
docs_name="user_apps"
fi
}
run_sphinx_quickstart()
{
# run_sphinx_quickstart will check if a sphinx conf.py file
# exists and if one does not then the sphinx-quickstart utility
# will be run.
if [ -f "conf.py" ]; then
echo "Sphinx conf found. Skipping sphinx-quickstart."
else
echo "Sphinx conf not found. Running sphinx-quickstart now!"
sphinx-quickstart < $ANS.active
fi
}
run_sphinx_build()
{
# run_sphinx_build will always execute when this script is
# called from the command line. It removes any default html and
# rst files, makes sure that the correct paramters exist inside conf.py
# and runs sphinx-apidoc and sphinx-build.
echo ""
echo "Sphinx Build Starting"
echo ""
rm -rf ./html
mkdir html
rm -rf ./rst
mkdir rst
sed -i -e '19 i\smartquotes = False' ./conf.py
sed -i -e 's/alabaster/default/g' ./conf.py
sed -i -e 's/# import os/import os/g' ./conf.py
sed -i -e 's/# import sys/import sys/g' ./conf.py
if [ "$which_docs_to_build" = "user_apps" ]; then
sed -i -e 's|# sys.path.insert(0, os.path.abspath('"'"'.'"'"'))|for path in [x[0] for x in os.walk("'$current_dir'/acq400_hapi/user_apps/")]: sys.path.insert(0, path)|g' ./conf.py
fi
if [ "$which_docs_to_build" = "acq400_hapi" ]; then
sed -i -e 's:# sys.path.insert(0, os.path.abspath('"'"'.'"'"')):sys.path.insert(0, os.path.abspath('"'"''$current_dir'/acq400_hapi/acq400_hapi/'"'"')):g' ./conf.py
fi
make html
if [ "$which_docs_to_build" = "acq400_hapi" ]; then
sphinx-apidoc -o ./rst ./acq400_hapi/$docs_name/acq400_hapi
cp rst/modules.rst rst/index.rst
elif [ "$which_docs_to_build" = "user_apps" ]; then
sphinx-apidoc -o ./rst/ ./acq400_hapi/$docs_name/acq400
cat ./rst/modules.rst >> ./rst/index.rst; rm ./rst/modules.rst
sphinx-apidoc -o ./rst/ ./acq400_hapi/$docs_name/acq1001
cat ./rst/modules.rst >> ./rst/index.rst; rm ./rst/modules.rst
sphinx-apidoc -o ./rst/ ./acq400_hapi/$docs_name/acq2106
cat ./rst/modules.rst >> ./rst/index.rst; rm ./rst/modules.rst
sphinx-apidoc -o ./rst/ ./acq400_hapi/$docs_name/acq1014
cat ./rst/modules.rst >> ./rst/index.rst; rm ./rst/modules.rst
sphinx-apidoc -o ./rst/ ./acq400_hapi/$docs_name/special
cat ./rst/modules.rst >> ./rst/index.rst; rm ./rst/modules.rst
sphinx-apidoc -o ./rst/ ./acq400_hapi/$docs_name/analysis
cat ./rst/modules.rst >> ./rst/index.rst; rm ./rst/modules.rst
sphinx-apidoc -o ./rst/ ./acq400_hapi/$docs_name/hil
cat ./rst/modules.rst >> ./rst/index.rst; rm ./rst/modules.rst
sphinx-apidoc -o ./rst/ ./acq400_hapi/$docs_name/utils
cat ./rst/modules.rst >> ./rst/index.rst; rm ./rst/modules.rst
fi
cd rst
cp ../conf.py .
mkdir _static
cd ..
sphinx-build -b html ./rst ./html
echo ""
echo "Sphinx Build Finished"
echo ""
}
current_dir=`pwd`
export PYTHONPATH=$current_dir/acq400_hapi/
find_hapi_dirs
run_sphinx_quickstart
run_sphinx_build