Merge "Enhance generatepot-rst for reuse"

This commit is contained in:
Jenkins 2015-10-07 20:16:55 +00:00 committed by Gerrit Code Review
commit 3d06856621
2 changed files with 59 additions and 33 deletions

View File

@ -13,48 +13,66 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
DOCNAME=$1 REPOSITORY=$1
USE_DOC=$2
DOCNAME=$3
if [ -z "$DOCNAME" ] ; then if [ $# -lt 3 ] ; then
echo "usage $0 DOCNAME" echo "usage $0 REPOSITORY USE_DOC DOCNAME"
exit 1 exit 1
fi fi
DIRECTORY=$DOCNAME
TOPDIR=""
if [ "$USE_DOC" = "1" ] ; then
DIRECTORY="doc/$DOCNAME"
TOPDIR="doc/"
fi
# We're not doing anything for this directory. But we need to handle # We're not doing anything for this directory. But we need to handle
# it by this script so that the common-rst.pot file gets registered. # it by this script so that the common-rst.pot file gets registered.
if [[ "$DOCNAME" = "common-rst" ]] ; then if [[ "$DOCNAME" = "common-rst" ]] ; then
exit 0 exit 0
fi fi
# Build Glossary if [ "$REPOSITORY" = "openstack-manuals" ] ; then
tools/glossary2rst.py doc/common-rst/glossary.rst # Build Glossary
tools/glossary2rst.py doc/common-rst/glossary.rst
fi
# First remove the old pot file, otherwise the new file will contain # First remove the old pot file, otherwise the new file will contain
# old references # old references
rm -f doc/$DOCNAME/source/locale/$DOCNAME.pot rm -f ${DIRECTORY}/source/locale/$DOCNAME.pot
# We need to extract all strings, so add all supported tags # We need to extract all strings, so add all supported tags
TAG="" TAG=""
if [ ${DOCNAME} = "install-guide" ] ; then if [ ${DOCNAME} = "install-guide" ] ; then
TAG="-t obs -t rdo -t ubuntu -t debian" TAG="-t obs -t rdo -t ubuntu -t debian"
fi fi
sphinx-build -b gettext $TAG doc/$DOCNAME/source/ doc/$DOCNAME/source/locale/ if [ ${DOCNAME} = "firstapp" ] ; then
TAG="-t libcloud -t dotnet -t fog -t pkgcloud -t shade"
fi
sphinx-build -b gettext $TAG ${DIRECTORY}/source/ \
${DIRECTORY}/source/locale/
# Update common if [ "$REPOSITORY" = "openstack-manuals" ] ; then
sed -i -e 's/^"Project-Id-Version: [a-zA-Z0-9\. ]+\\n"$/"Project-Id-Version: \\n"/' \ # Update common
doc/$DOCNAME/source/locale/common.pot sed -i -e 's/^"Project-Id-Version: [a-zA-Z0-9\. ]+\\n"$/"Project-Id-Version: \\n"/' \
# Create the common pot file ${DIRECTORY}/source/locale/common.pot
msgcat --sort-by-file doc/common-rst/source/locale/common-rst.pot \ # Create the common pot file
doc/$DOCNAME/source/locale/common.pot | \ msgcat --sort-by-file ${TOPDIR}common-rst/source/locale/common-rst.pot \
sed -e 's/^"Project-Id-Version: [a-zA-Z0-9\. ]+\\n"$/"Project-Id-Version: \\n"/' | \ ${DIRECTORY}/source/locale/common.pot | \
awk '$0 !~ /^\# [a-z0-9]+$/' | awk '$0 !~ /^\# \#-\#-\#-\#-\# /' \ sed -e 's/^"Project-Id-Version: [a-zA-Z0-9\. ]+\\n"$/"Project-Id-Version: \\n"/' | \
> doc/$DOCNAME/source/locale/common-rst.pot awk '$0 !~ /^\# [a-z0-9]+$/' | awk '$0 !~ /^\# \#-\#-\#-\#-\# /' \
mv -f doc/$DOCNAME/source/locale/common-rst.pot doc/common-rst/source/locale/common-rst.pot > ${DIRECTORY}/source/locale/common-rst.pot
rm -f doc/$DOCNAME/source/locale/common.pot mv -f ${DIRECTORY}/source/locale/common-rst.pot \
${TOPDIR}common-rst/source/locale/common-rst.pot
rm -f ${DIRECTORY}/source/locale/common.pot
# Simplify metadata # Simplify metadata
rm -f doc/common-rst/source/locale/dummy.po rm -f ${TOPDIR}common-rst/source/locale/dummy.po
cat << EOF > doc/common-rst/source/locale/dummy.po cat << EOF > ${TOPDIR}common-rst/source/locale/dummy.po
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
@ -67,16 +85,24 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
EOF EOF
msgmerge -N doc/common-rst/source/locale/dummy.po \ msgmerge -N ${TOPDIR}common-rst/source/locale/dummy.po \
doc/common-rst/source/locale/common-rst.pot > doc/common-rst/source/locale/tmp.pot ${TOPDIR}common-rst/source/locale/common-rst.pot \
mv -f doc/common-rst/source/locale/tmp.pot doc/common-rst/source/locale/common-rst.pot > ${TOPDIR}common-rst/source/locale/tmp.pot
rm -f doc/common-rst/source/locale/dummy.po mv -f ${TOPDIR}common-rst/source/locale/tmp.pot \
${TOPDIR}common-rst/source/locale/common-rst.pot
rm -f ${TOPDIR}common-rst/source/locale/dummy.po
else
# common-rst is translated as part of openstack-manuals, do not
# include the file in the combined tree.
rm ${DIRECTORY}/source/locale/common.pot
fi
# Take care of deleting all temporary files so that git add # Take care of deleting all temporary files so that
# doc/$DOCNAME/source/locale will only add the single pot file. # "git add ${DIRECTORY}/source/locale" will only add the
# single pot file.
# Remove UUIDs, those are not necessary and change too often # Remove UUIDs, those are not necessary and change too often
msgcat --sort-by-file doc/$DOCNAME/source/locale/*.pot | \ msgcat --sort-by-file ${DIRECTORY}/source/locale/*.pot | \
awk '$0 !~ /^\# [a-z0-9]+$/' > doc/$DOCNAME/source/$DOCNAME.pot awk '$0 !~ /^\# [a-z0-9]+$/' > ${DIRECTORY}/source/$DOCNAME.pot
rm doc/$DOCNAME/source/locale/*.pot rm ${DIRECTORY}/source/locale/*.pot
rm -rf doc/$DOCNAME/source/locale/.doctrees/ rm -rf ${DIRECTORY}/source/locale/.doctrees/
mv doc/$DOCNAME/source/$DOCNAME.pot doc/$DOCNAME/source/locale/$DOCNAME.pot mv ${DIRECTORY}/source/$DOCNAME.pot ${DIRECTORY}/source/locale/$DOCNAME.pot

View File

@ -109,7 +109,7 @@ commands =
[testenv:generatepot-rst] [testenv:generatepot-rst]
# Generate POT files for translation, needs {posargs} like: # Generate POT files for translation, needs {posargs} like:
# tox -e generatepot-rst -- user-guide # tox -e generatepot-rst -- user-guide
commands = {toxinidir}/tools/generatepot-rst.sh {posargs} commands = {toxinidir}/tools/generatepot-rst.sh openstack-manuals 1 {posargs}
[doc8] [doc8]
# Settings for doc8: # Settings for doc8: