diff --git a/tools/generatepot b/tools/generatepot new file mode 100755 index 00000000..b11ea8ff --- /dev/null +++ b/tools/generatepot @@ -0,0 +1,91 @@ +#!/usr/bin/env python +''' +Created on 2012-7-3 + +@author: daisy +''' +import os, sys +from xml2po import Main +from xml2po.modes.docbook import docbookXmlMode + +class myDocbookXmlMode(docbookXmlMode): + def __init__(self): + self.lists = ['itemizedlist', 'orderedlist', 'variablelist', + 'segmentedlist', 'simplelist', 'calloutlist', 'varlistentry', 'userinput', + 'computeroutput','prompt','command','screen'] + self.objects = [ 'figure', 'textobject', 'imageobject', 'mediaobject', + 'screenshot','literallayout', 'programlisting' ] + +default_mode = 'docbook' +operation = 'pot' +options = { + 'mark_untranslated' : False, + 'expand_entities' : True, + 'expand_all_entities' : False, +} + +ignore_folder = {} +ignore_file = {} + +root = "./doc" + +def generatePoT (folder): + if (folder==None) : + path = root + else : + generateSinglePoT(folder) + return + + if (not os.path.isdir(path)) : + return + + files = os.listdir(path) + for aFile in files : + if (not (aFile in ignore_folder)): + generateSinglePoT (aFile) + +def generateSinglePoT(folder): + xmlfiles = [] + abspath = os.path.join(root, folder) + if (os.path.isdir(abspath)) : + os.path.walk(abspath, get_all_xml, xmlfiles) + else: + return + + if len(xmlfiles)>0 : + output = os.path.join(abspath,"locale") + if (not os.path.exists(output)) : + os.mkdir(output) + output = os.path.join(output, folder+".pot") + try: + xml2po_main = Main(default_mode, operation, output, options) + xml2po_main.current_mode = myDocbookXmlMode() + except IOError: + print "Error: cannot open aFile %s for writing." % (output) + sys.exit(5) + #print(xmlfiles) + #print(">>>outout: %s ", output) + xml2po_main.to_pot(xmlfiles) + +def get_all_xml (sms, dr, flst): + if ((flst == "target") or (flst == "wadls")) : + return + if (dr.find("target")>-1) : + return + if (dr.find("wadls")>-1) : + return + + for f in flst: + if (f.endswith(".xml") and (f != "pom.xml") and (not (f in ignore_file))) : + sms.append(os.path.join(dr,f)) + +def main(): + try: + folder = sys.argv[1] + except: + folder = None + generatePoT(folder) + +if __name__ == '__main__': + main() + diff --git a/tools/test-languages.sh b/tools/test-languages.sh new file mode 100755 index 00000000..c8be4aa4 --- /dev/null +++ b/tools/test-languages.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +function setup_directory { + SET_LANG=$1 + shift + for BOOK_DIR in "$@" ; do + echo " $BOOK_DIR" + openstack-generate-docbook -l $SET_LANG -b $BOOK_DIR + done +} + + +function setup_lang { + SET_LANG=$1 + shift + echo "Setting up files for $SET_LANG" + echo "=======================" + echo " Directories:" + setup_directory $SET_LANG "$@" +} + +function test_ja { + setup_lang 'ja' + + setup_directory 'ja' 'training-guides' + case "$PURPOSE" in + test) + openstack-doc-test -v --check-build -l ja + RET=$? + ;; + publish) + openstack-doc-test -v --publish --check-build -l ja + RET=$? + ;; + esac + if [ "$RET" -eq "0" ] ; then + echo "... succeeded" + else + echo "... failed" + BUILD_FAIL=1 + fi +} + +function test_language () { + + case "$language" in + all) + # Currently no language added since there's nothing + # translated yet. Japenese is just shown as an example. + ;; + ja) + test_ja + ;; + *) + BUILD_FAIL=1 + echo "Language $language not handled" + ;; + esac +} + +function usage () { + echo "Call the script as: " + echo "$0 PURPOSE LANGUAGE1 LANGUAGE2..." + echo "PURPOSE is either 'test' or 'publish'." + echo "LANGUAGE can also be 'all'." +} + +if [ "$#" -lt 2 ] ; then + usage + exit 1 +fi +if [ "$1" = "test" ] ; then + PURPOSE="test" +elif [ "$1" = "publish" ] ; then + PURPOSE="publish" +else + usage + exit 1 +fi +shift +BUILD_FAIL=0 +for language in "$@" ; do + echo + echo "Building for language $language" + echo + test_language "$language" +done + +exit $BUILD_FAIL diff --git a/tox.ini b/tox.ini index 80cd2c41..65bdfbf5 100644 --- a/tox.ini +++ b/tox.ini @@ -43,45 +43,27 @@ commands = # We only publish changed manuals. openstack-doc-test --check-build --publish -#[testenv:checklang] +[testenv:checklang] # Generatedocbook needs xml2po which cannot be installed # in the venv. Since it's installed in the system, let's # use sitepackages. -#sitepackages=True -#whitelist_externals = bash -#commands = bash tools/test-languages.sh +sitepackages=True +whitelist_externals = bash +commands = bash tools/test-languages.sh test all -#[testenv:buildlang-install] -# Run as "tox -e buildlang-install -- $LANG" +[testenv:buildlang] +# Run as "tox -e buildlang -- $LANG" # Generatedocbook needs xml2po which cannot be installed # in the venv. Since it's installed in the system, let's # use sitepackages. -#sitepackages=True -#whitelist_externals = bash -#commands = -# openstack-generate-docbook -l {posargs} -b common -# openstack-generate-docbook -l {posargs} -b glossary -# openstack-generate-docbook -l {posargs} -b install-guide -# # tox 1.7 does not parse the following line: -# # cp doc/pom.xml generated/{posargs}/pom.xml -# # Thus replaced by the next one: -# bash ./tools/copy_pom {posargs} -# openstack-doc-test --check-build --publish -l {posargs} --only-book install-guide +sitepackages=True +whitelist_externals = bash +commands = bash tools/test-languages.sh test all -#[testenv:buildlang-misc] -# Run as "tox -e buildlang-misc -- $LANG" +[testenv:publishlang] # Generatedocbook needs xml2po which cannot be installed # in the venv. Since it's installed in the system, let's # use sitepackages. -#sitepackages=True -#whitelist_externals = bash -#commands = -# openstack-generate-docbook -l {posargs} -b common -# openstack-generate-docbook -l {posargs} -b glossary -# openstack-generate-docbook -l {posargs} -b security-guide -# openstack-generate-docbook -l {posargs} -b high-availability-guide -# # tox 1.7 does not parse the following line: -# # cp doc/pom.xml generated/{posargs}/pom.xml -# # Thus replaced by the next one: -# bash ./tools/copy_pom {posargs} -# openstack-doc-test --check-build --publish -l {posargs} --only-book security-guide --only-book high-availability-guide +sitepackages=True +whitelist_externals = bash +commands = bash tools/test-languages.sh publish all