Skip to content

Commit e5db7fb

Browse files
committed
Better trap errors
1 parent 39676d3 commit e5db7fb

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

mkdoc.sh

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,28 @@ pydoc -w ${ALL_MODS}
114114

115115
note_action "Preparing 'doc' dir\n"
116116
mkdir -p doc
117-
rm -f doc/index.html
118117

119-
note_action "Converting absolute local paths to relative web-safe paths...\n"
118+
python -c "import AdvancedHTMLParser"
119+
HAS_ADVANCED_HTML_PARSER_MOD=$?
120+
121+
if [ ${HAS_ADVANCED_HTML_PARSER_MOD} -ne 0 ];
122+
then
123+
note_failure "Python module AdvancedHTMLParser is not found!\n"
124+
note_failure " Cannot convert local paths to relative web-safe paths or other cleanup tasks.\n\n"
125+
else
126+
note_action "Converting absolute local paths to relative web-safe paths...\n"
127+
fi
128+
129+
# TASK: Iterate through each generated file, clean up (assuming AdvancedHTMLParser is present),
130+
# and move into "doc" directory.
131+
120132
for fnamePy in ${ALL_FILES};
121133
do
122134
fname="$(echo "${fnamePy}" | sed 's/.py$/.html/g' | tr '/' '.' | sed 's/\.__init__//g' )"
123-
python <<EOT
135+
136+
if [ "${HAS_ADVANCED_HTML_PARSER_MOD}" -eq 0 ];
137+
then
138+
python <<EOT
124139
125140
import AdvancedHTMLParser
126141
import sys
@@ -156,19 +171,33 @@ if __name__ == '__main__':
156171
f.write(parser.getHTML())
157172
158173
EOT
159-
RET=$?
174+
RET=$?
160175

161-
if [ "${RET}" -ne 0 ];
162-
then
163-
note_failure "Failed to clean up \"%s\" (from \"%s\"). Exit code: %d\n" "${fname}" "${fnamePy}" "${RET}"
176+
if [ "${RET}" -ne 0 ];
177+
then
178+
note_failure "Failed to clean up \"%s\" (from \"%s\"). Exit code: %d\n" "${fname}" "${fnamePy}" "${RET}"
179+
fi
164180
fi
165181

166182
mv "${fname}" 'doc/'
183+
if [ $? -ne 0 ];
184+
then
185+
note_failure "Failed to move \"%s\" into \"doc\" directory.\n" "${fname}"
186+
fi
167187

168188
done
169189

190+
# TASK: prepare to be ready to zip up for upload by symlinking index.html to main module pydoc
191+
170192
pushd "doc" >/dev/null 2>&1
171193

172-
ln -s ${PROJECT_NAME}.html index.html
194+
rm -f index.html
195+
if [ $? -ne 0 ];
196+
then
197+
note_failure "Failed to remove doc/index.html in order to re-link\n"
198+
else
199+
ln -s ${PROJECT_NAME}.html index.html
200+
fi
201+
173202

174203
popd >/dev/null 2>&1

0 commit comments

Comments
 (0)