Rework install guide translation build tool

Sync translation build tool
with Change-Id: I3abcd7da3569bb8e9edbc02574dcb74c12752ede.

Change-Id: I45f66ba19d0946175dbace95082454bdd1187bf1
Closes-Bug: #1516079
This commit is contained in:
KATO Tomoyuki 2015-11-15 11:24:03 +09:00 committed by Andreas Jaeger
parent 926a7413ba
commit 9abcfea69c
2 changed files with 60 additions and 17 deletions

View File

@ -97,31 +97,70 @@ function build_rst {
elif [ ${book} = "install-guide" ] ; then
# Install Guide has several variations, build all of them
title_org=$(grep "title::" ${DOC_DIR}${book}/source/index.rst | \
awk '{print substr($0, index($0, "::")+3)}')
TAGS="obs rdo ubuntu debian"
trap "sed -i -e \"s/\.\. title::.*/.. title:: ${title_org}/\" \
${DOC_DIR}${book}/source/index.rst" EXIT
# For translation work, we should have only one index file,
# because our tools generate translation resources from
# only one index file.
# Therefore, this tool uses one combined index file
# while processing title and toctree for each distribution.
for tag in obs rdo ubuntu debian; do
title=$(grep -m 1 -A 5 ".. only:: ${tag}" \
${DOC_DIR}${book}/source/index.rst | \
# Save and restore the index file
cp -f ${INDEX} ${INDEX}.save
trap "mv -f ${INDEX}.save ${INDEX}" EXIT
for tag in $TAGS; do
# Because Sphinx uses the first heading as title regardless of
# only directive, replace title directive with the proper title
# for each distribution to set the title explicitly.
title=$(grep -m 1 -A 5 "^.. only:: ${tag}" ${INDEX} | \
sed -n 4p | sed -e 's/^ *//g')
sed -i -e "s/\.\. title::.*/.. title:: ${title}/" \
tox -evenv "sphinx-build -j $NUMBER_OF_CORES -q -E -t $tag -D language=${language} \
${DOC_DIR}${book}/source/ \
sed -i -e "s/\.\. title::.*/.. title:: ${title}/" ${INDEX}
# Sphinx builds the navigation before processing directives,
# so the conditional toctree does not work.
# We need to prepare toctree depending on distribution
# only with one toctree before exectuing sphinx-build.
# Get line number of each tag
lineno_start=$(grep -n "^Contents" ${INDEX} | sed -e 's/:.*//')
lineno_end=$(grep -n "^.. end of contents" ${INDEX} | sed -e 's/:.*//')
lineno_debian=$(grep -n "^.. only:: debian" ${INDEX} \
| tail -1 | sed -e 's/:.*//')
lineno_notdebian=$(grep -n "^.. only:: [^d]" ${INDEX} \
| tail -1 | sed -e 's/:.*//')
# Remove indent for pseudo only directive
sed -i "${lineno_start},${lineno_end} s/^ *\.\. toctree/.. toctree/" ${INDEX}
sed -i "${lineno_start},${lineno_end} s/^ */ /" ${INDEX}
# Remove unnecessary toctree for each distribution
if [[ "$tag" == "debian" ]]; then
sed -i "${lineno_notdebian},${lineno_debian}d" ${INDEX}
sed -i "${lineno_debian},$((${lineno_end}-1))d" ${INDEX}
sed -i "${lineno_notdebian}d" ${INDEX}
# Build the guide
tox -evenv "sphinx-build -j $NUMBER_OF_CORES -q -E -t $tag \
-D language=${language} ${DOC_DIR}${book}/source/ \
mkdir -p publish-docs/${language}/${book}-${tag}
rsync -a ${DOC_DIR}${book}/build-${tag}/html/ \
# Restore the index file
cp -f ${INDEX}.save ${INDEX}
# Remove Debian specific content from other guides
if [[ "$tag" != "debian" ]]; then
rm -rf publish-docs/${language}/{book}-$tag/debconf
# Debian Install Guide uses index-debian, we need to rename the file
if [ -f ${INSTALL_DEBIAN}/index-debian.html ] ; then
mv ${INSTALL_DEBIAN}/index-debian.html \
tox -evenv "sphinx-build -j $NUMBER_OF_CORES -q -E -D language=${language} \
${DOC_DIR}${book}/source/ \

View File

@ -0,0 +1,4 @@
- Rework install guide translation build tool
to process toctree for each distribution dynamically.