diff --git a/README.rst b/README.rst index 0504e2a0..334dfd6d 100644 --- a/README.rst +++ b/README.rst @@ -103,10 +103,12 @@ Release notes * ``openstack-auto-commands``: Improved screen generation and swift subcommand xml output. * ``openstack-doc-tools``: Warn about non-breaking space, enhance - -v output. + -v output, special case building of localized high-availability + guide. * New command ``openstack-jsoncheck`` to check for niceness of JSON files and reformat them. + 0.13 ---- diff --git a/os_doc_tools/doctest.py b/os_doc_tools/doctest.py index 561a50d9..85dfb4ed 100755 --- a/os_doc_tools/doctest.py +++ b/os_doc_tools/doctest.py @@ -819,10 +819,14 @@ def build_book(book, publish_path, log_path): # Success base_book = "install-guide (for Debian, Fedora, openSUSE, Ubuntu)" elif base_book == "high-availability-guide": - output = subprocess.check_output( - ["bash", os.path.join(SCRIPTS_DIR, 'build-ha-guide.sh'), ], - stderr=subprocess.STDOUT - ) + # generatedocbook already calls build-ha-guide.sh, do not + # call it again here for translated languages. + if not cfg.CONF.language: + output = subprocess.check_output( + ["bash", os.path.join(SCRIPTS_DIR, + 'build-ha-guide.sh'), ], + stderr=subprocess.STDOUT + ) output = subprocess.check_output( ["mvn", "generate-sources", comments, release, "-B"], stderr=subprocess.STDOUT diff --git a/os_doc_tools/handle_pot.py b/os_doc_tools/handle_pot.py index a7db0301..f3ba11e0 100644 --- a/os_doc_tools/handle_pot.py +++ b/os_doc_tools/handle_pot.py @@ -23,6 +23,7 @@ import codecs import optparse import os import shutil +import subprocess import sys import tempfile import xml.dom.minidom @@ -30,6 +31,9 @@ import xml.dom.minidom from xml2po import Main # noqa from xml2po.modes.docbook import docbookXmlMode # noqa +OS_DOC_TOOLS_DIR = os.path.dirname(__file__) +SCRIPTS_DIR = os.path.join(OS_DOC_TOOLS_DIR, 'scripts') + class myDocbookXmlMode(docbookXmlMode): def __init__(self): @@ -123,6 +127,7 @@ def changeXMLLangSetting(xmlFile, language): for node in nodelists: if node.hasAttribute("href"): node.setAttribute("xlink:href", node.getAttribute("href")) + node.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink") if node.hasAttribute("title"): node.setAttribute("xlink:title", node.getAttribute("title")) @@ -147,6 +152,28 @@ def get_default_book(root): return os.listdir(root)[0] +# NOTE(berendt): check_output as provided in Python 2.7.5 to make script +# usable with Python < 2.7 +def check_output(*popenargs, **kwargs): + """Run command with arguments and return its output as a byte string. + + If the exit code was non-zero it raises a CalledProcessError. The + CalledProcessError object will have the return code in the returncode + attribute and output in the output attribute. + """ + if 'stdout' in kwargs: + raise ValueError('stdout argument not allowed, it will be overridden.') + process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs) + output, unused_err = process.communicate() + retcode = process.poll() + if retcode: + cmd = kwargs.get("args") + if cmd is None: + cmd = popenargs[0] + raise subprocess.CalledProcessError(retcode, cmd, output=output) + return output + + def generatedocbook(): global IGNORE_FOLDER, IGNORE_FILE @@ -196,8 +223,27 @@ def generatedocbook(): if os.path.exists(destfolder): shutil.rmtree(destfolder) + # Build the XML original location first + if folder == 'high-availability-guide': + try: + curr = os.getcwd() + os.chdir(sourcepath) + subprocess.check_output( + ["bash", os.path.join(SCRIPTS_DIR, 'build-ha-guide.sh'), ], + stderr=subprocess.STDOUT + ) + os.chdir(curr) + except subprocess.CalledProcessError as e: + print("build-ha-guide.sh failed: %s" % e) + sys.exit(1) os.system("cp -r %s %s" % (sourcepath, destpath)) mergeback(folder, language, root) + # Somehow a lang="" is in the xml and breaks build, remove it + if folder == 'high-availability-guide': + bk_ha = os.path.join(destfolder, "bk-ha-guide.xml") + with open(bk_ha) as bk_ha_file: + newxml = bk_ha_file.read().replace(',' |\ sed -e 's, bk-ha-guide.xml