blob: 5c5c4a2941469b9be776f3bd65c1e37dc49f7b6f [file] [log] [blame]
#!/usr/bin/python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
from __future__ import print_function
from generate import *
import uuid
from xml.etree import ElementTree
def gen_broker_j_books(release, source_dir, output_dir):
toplevel_pom = join(source_dir, "pom.xml")
input_dir = join(source_dir, "doc")
cpp_broker_book_url = "/releases/qpid-cpp-{{current_cpp_release}}/cpp-broker/book/"
jms_client010_book_url = "/releases/qpid-jms-amqp-0-x-{{current_jms_amqp_0_x_release}}/jms-client-0-10/book/"
call("mvn -f {} -pl doc -amd -Ddoc=true package -DqpidCppBook={} -DqpidJmsClient010Book={}",
toplevel_pom,
cpp_broker_book_url,
jms_client010_book_url)
java_broker_input_dir = join(input_dir, "java-broker", "target", "docbkx")
java_broker_book_dir = join(output_dir, "book")
remove(java_broker_book_dir)
copy(java_broker_input_dir, java_broker_book_dir)
for path in find(output_dir, "*.html"):
print(path)
tree = ElementTree.parse(path)
elem = tree.find(".//{http://www.w3.org/1999/xhtml}body")
elem.tag = "div"
elem.set("class", "docbook")
remove_namespace(elem, "http://www.w3.org/1999/xhtml")
# A hack to preserve docbook's empty anchors in an
# IE-compatible way
target = str(uuid.uuid4())
for a in tree.iter("a"):
if a.text is None:
a.text = target
content = ElementTree.tostring(elem)
content = content.replace(target, "")
write("{}.in".format(path), content)
remove(path)
# From http://homework.nwsnet.de/releases/45be/
def remove_namespace(doc, namespace):
"""Remove namespace in the passed document in place."""
ns = u'{%s}' % namespace
nsl = len(ns)
for elem in doc.getiterator():
if elem.tag.startswith(ns):
elem.tag = elem.tag[nsl:]
## Now do stuff ##
release, issues_release, source_release, release_dir, checkout_dir = setup_release_script()
source_dir = checkout_dir or fetch_source("broker-j", source_release)
gen_broker_j_books(release, source_dir, release_dir)
notice("Docs generated")