Fix generation of ha localized guide

The generatedocbook tool only works on XML files.
For the high-availability guide, we first need to generate the XML file
and then integrate translations - and take care that the build job not
regenerates the XML file.

Change-Id: Iab7a72d2819b4fc5d0bac53b8a9ccba2ba9ef0ef
This commit is contained in:
Andreas Jaeger 2014-05-13 06:22:52 -04:00 committed by Gauvain Pocentek
parent fa80be3495
commit 9622f376cb
4 changed files with 58 additions and 5 deletions

View File

@ -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
----

View File

@ -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

View File

@ -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('<book lang="" ', '<book ')
open(bk_ha, 'wb').write(newxml)
def generatePoT(folder, root):

View File

@ -21,5 +21,6 @@ asciidoc -b docbook -d book -o - ha-guide.txt | \
xsltproc -o - $DB_UPGRADE - | \
xmllint --format - | \
sed -e 's,<book,<book xml:id="bk-ha-guide",' | \
sed -e 's,<!-- Converted by db4-upgrade version 1.0 -->,' |\
sed -e 's,<info,<?rax pdf.url="../openstack-ha-guide-trunk.pdf"?><info,' \
> bk-ha-guide.xml