| #!/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. |
| # |
| |
| import uuid |
| |
| from generate import * |
| from xml.etree import ElementTree |
| |
| def gen_cpp_apis(release, source_dir, release_dir): |
| component_dir = join(release_dir, "messaging-api") |
| |
| remove(component_dir) |
| |
| gen_cpp_messaging_api(release, source_dir, component_dir) |
| |
| def gen_cpp_messaging_api(release, source_dir, component_dir): |
| include_dir = join(source_dir, "include") |
| input_paths = ( |
| join(source_dir, "cpp", "docs", "api", "doxygen_mainpage.h"), |
| join(include_dir, "qpid", "messaging"), |
| join(include_dir, "qpid", "types"), |
| ) |
| output_dir = join(component_dir, "cpp", "api") |
| |
| gen_doxygen(release=release, |
| title="Qpid C++ Messaging API", |
| input_paths=input_paths, |
| strip_paths=(include_dir,), |
| output_dir=output_dir) |
| |
| def gen_cpp_books(release, source_dir, output_dir): |
| input_dir = join(source_dir, "docs", "book") |
| |
| stylesheet = """<?xml version='1.0'?> |
| <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> |
| <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/xhtml/chunk.xsl"/> |
| </xsl:stylesheet>""" |
| |
| write(join(input_dir, "xsl", "html-custom.xsl"), stylesheet) |
| |
| call("make -C {} clean all", input_dir) |
| |
| cpp_broker_input_dir = join(input_dir, "build", "AMQP-Messaging-Broker-CPP-Book") |
| cpp_broker_output_dir = join(output_dir, "cpp-broker") |
| |
| messaging_input_dir = join(input_dir, "build", "Qpid-Messaging-API") |
| messaging_output_dir = join(output_dir, "messaging-api") |
| |
| remove(cpp_broker_output_dir) |
| remove(join(messaging_output_dir, "book")) |
| |
| copy(join(cpp_broker_input_dir, "html"), join(cpp_broker_output_dir, "book")) |
| copy(join(messaging_input_dir, "html"), join(messaging_output_dir, "book")) |
| |
| copy(join(cpp_broker_input_dir, "pdf", "AMQP-Messaging-Broker-CPP-Book.pdf"), |
| join(cpp_broker_output_dir, "cpp-broker-book.pdf")) |
| copy(join(messaging_input_dir, "pdf", "Qpid-Messaging-API.pdf"), |
| join(messaging_output_dir, "qpid-messaging-api-book.pdf")) |
| |
| output_dirs = [cpp_broker_output_dir, join(messaging_output_dir, "book")] |
| |
| for dir in output_dirs: |
| for path in find(dir, "*.html"): |
| 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:] |
| |
| def gen_cpp_examples(release, source_dir, release_dir): |
| component_dir = join(release_dir, "messaging-api") |
| |
| gen_cpp_messaging_examples(release, source_dir, component_dir) |
| |
| def gen_cpp_messaging_examples(release, source_dir, component_dir): |
| input_dir = join(source_dir, "examples", "messaging") |
| output_dir = join(component_dir, "cpp", "examples") |
| |
| release_url = get_git_release_branch_url("cpp", release) |
| readme_url = "https://gitbox.apache.org/repos/asf?p=qpid-cpp.git;a=blob_plain;f=examples/README.txt;hb=refs/heads/{}".format("main") |
| source_url = "https://gitbox.apache.org/repos/asf?p=qpid-cpp.git;a=tree;f=examples/messaging;hb=refs/heads/{}".format("main") |
| |
| input_names = list_dir(input_dir, "*.cpp", "*.h") |
| |
| gen_examples(release=release, |
| lang="cpp", |
| title="C++ Messaging API Examples", |
| input_dir=input_dir, |
| input_names=input_names, |
| output_dir=output_dir, |
| readme_url=readme_url, |
| source_url=source_url) |
| |
| ## Now do stuff ## |
| |
| release, issues_release, source_release, release_dir, checkout_dir = setup_release_script() |
| source_dir = checkout_dir or fetch_source("cpp", source_release) |
| |
| gen_cpp_apis(release, source_dir, release_dir) |
| gen_cpp_books(release, source_dir, release_dir) |
| gen_cpp_examples(release, source_dir, release_dir) |
| |
| notice("Docs generated") |