Exit trap cleanup in docstheme-build-translated.sh
Add a catch-all `cleanup` exit trap to docstheme-build-translated.sh. The script creates interim artifacts in doc/source (which it arguably shouldn't do) like .pot files and .rst sources modified with index headers pointing to translations. Previously, if the doc build failed, these artifacts would be left behind, creating a mess for a developer attempting to make and commit doc changes locally. This patch accumulates the existing cleanups into an exit trap so they happen whether the script succeeds or fails. Developers of openstackdocstheme itself may disable this cleanup trap by setting the DOCSTHEME_BUILD_TRANSLATED__NO_CLEANUP environment variable to a nonempty value. Change-Id: If48c5705c34f940e78e3a34e602e48496a397629
This commit is contained in:
parent
e6576b1eea
commit
0b86d24dbd
|
@ -45,7 +45,6 @@ function prepare_language_index {
|
|||
# Global variables
|
||||
HAS_LANG=0
|
||||
LANG_INDEX=`mktemp`
|
||||
trap "rm -f -- $LANG_INDEX" EXIT
|
||||
|
||||
cat <<EOF >> $LANG_INDEX
|
||||
[
|
||||
|
@ -113,10 +112,27 @@ function add_language_index_to_original {
|
|||
|
||||
function recover_rst_files {
|
||||
for f in `find $DIRECTORY/source -name '*.rst'`; do
|
||||
mv $f.backup $f
|
||||
[ -f $f.backup ] && mv $f.backup $f
|
||||
done
|
||||
}
|
||||
|
||||
function remove_pot_files {
|
||||
# remove newly created pot files
|
||||
rm -f ${DIRECTORY}/source/locale/*.pot
|
||||
}
|
||||
|
||||
function cleanup {
|
||||
if [ $DOCSTHEME_BUILD_TRANSLATED__NO_CLEANUP ]; then
|
||||
echo "Skipping cleanup. Your repository is dirty."
|
||||
return
|
||||
fi
|
||||
[ $LANG_INDEX ] && rm -f -- $LANG_INDEX
|
||||
recover_rst_files
|
||||
remove_pot_files
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
sphinx-build -a -W -b gettext \
|
||||
-d ${DIRECTORY}/build/doctrees.gettext \
|
||||
${DIRECTORY}/source ${DIRECTORY}/source/locale/
|
||||
|
@ -201,8 +217,7 @@ for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do
|
|||
git checkout -q -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po
|
||||
done
|
||||
|
||||
# remove newly created pot files
|
||||
rm -f ${DIRECTORY}/source/locale/*.pot
|
||||
remove_pot_files
|
||||
|
||||
add_language_index_to_original
|
||||
|
||||
|
@ -210,5 +225,3 @@ add_language_index_to_original
|
|||
sphinx-build -a ${SPHINX_BUILD_OPTION_ENG} -b html \
|
||||
-d ${DIRECTORY}/build/doctrees \
|
||||
${DIRECTORY}/source ${DIRECTORY}/build/html/
|
||||
|
||||
recover_rst_files
|
||||
|
|
Loading…
Reference in New Issue