[rtems-docs commit] waf: Create an XML Catalogue.

Chris Johns chrisj at rtems.org
Mon Jan 9 12:14:33 UTC 2017


Module:    rtems-docs
Branch:    master
Commit:    1a9b02e20dbc89d69ca4b4a64c69659b918a480d
Changeset: http://git.rtems.org/rtems-docs/commit/?id=1a9b02e20dbc89d69ca4b4a64c69659b918a480d

Author:    Chris Johns <chrisj at rtems.org>
Date:      Mon Jan  9 23:13:02 2017 +1100

waf: Create an XML Catalogue.

---

 common/waf.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wscript       |  6 +++++
 2 files changed, 84 insertions(+)

diff --git a/common/waf.py b/common/waf.py
index 33fff4d..9eb7173 100644
--- a/common/waf.py
+++ b/common/waf.py
@@ -86,6 +86,15 @@ def build_dir_setup(ctx, buildtype):
     output_node = ctx.path.get_bld().make_node(buildtype)
     output_dir = output_node.abspath()
     doctrees = os.path.join(os.path.dirname(output_dir), 'doctrees', buildtype)
+    #
+    # Gather the data for the catalogue
+    #
+    if build_dir not in ctx.catalogue:
+        ctx.catalogue[build_dir] = {
+            'builddir': build_dir,
+            'buildtype': []
+        }
+    ctx.catalogue[build_dir]['buildtype'].append(buildtype)
     return build_dir, output_node, output_dir, doctrees
 
 def pdf_resources(ctx, buildtype):
@@ -313,6 +322,75 @@ def cmd_configure_path(ctx):
 
     cmd_configure(ctx)
 
+def xml_catalogue(ctx):
+    #
+    # Read the conf.py files in each directory to gather the doc details.
+    #
+    sp = sys.path[:]
+    for t in ctx.cur_tasks:
+        if t.get_cwd().is_src():
+            doc = os.path.basename(t.get_cwd().get_src().abspath())
+            sys.path.insert(0, str(t.get_cwd()))
+            #
+            # Import using the imp API so the module is reloaded for us.
+            #
+            import imp
+            mf = imp.find_module('conf')
+            try:
+                bconf = imp.load_module('bconf', mf[0], mf[1], mf[2])
+            finally:
+                mf[0].close()
+            sys.path = sp[:]
+            if doc in ctx.catalogue:
+                ctx.catalogue[doc]['title'] = bconf.project
+                ctx.catalogue[doc]['version'] = bconf.version
+                ctx.catalogue[doc]['release'] = bconf.release
+                ctx.catalogue[doc]['latex'] = bconf.latex_documents[0][1]
+            bconf = None
+
+    import xml.dom.minidom as xml
+    cat = xml.Document()
+
+    root = cat.createElement('rtems-docs')
+    root.setAttribute('date', 'today')
+    cat.appendChild(root)
+
+    for d in ctx.catalogue:
+        doc = cat.createElement('doc')
+        name = cat.createElement('name')
+        text = cat.createTextNode(d)
+        name.appendChild(text)
+        title = cat.createElement('title')
+        text = cat.createTextNode(ctx.catalogue[d]['title'])
+        title.appendChild(text)
+        release = cat.createElement('release')
+        text = cat.createTextNode(ctx.catalogue[d]['release'])
+        release.appendChild(text)
+        version = cat.createElement('version')
+        text = cat.createTextNode(ctx.catalogue[d]['version'])
+        version.appendChild(text)
+        doc.appendChild(name)
+        doc.appendChild(title)
+        doc.appendChild(release)
+        doc.appendChild(version)
+        for b in ctx.catalogue[d]['buildtype']:
+            if b == 'latex':
+                b = 'pdf'
+                ref = ctx.catalogue[d]['latex'].replace('.tex', '.pdf')
+            elif b == 'html':
+                ref = '%s/index.html' % (d)
+            else:
+                ref = 'undefined'
+            output = cat.createElement(b)
+            text = cat.createTextNode(ref)
+            output.appendChild(text)
+            doc.appendChild(output)
+        root.appendChild(doc)
+
+    catnode = ctx.path.get_bld().make_node('catalogue.xml')
+    catnode.write(cat.toprettyxml(indent = ' ' * 2, newl = os.linesep))
+
+    cat.unlink()
 
 CONF_FRAG = """
 sys.path.append(os.path.abspath('../../common/'))
diff --git a/wscript b/wscript
index f7dd224..2147c5b 100644
--- a/wscript
+++ b/wscript
@@ -30,9 +30,15 @@ def configure(conf):
         conf.recurse(b)
     conf.env['BUILD_FROM_TOP'] = 'yes'
 
+def xml_catalogue(ctx):
+    docs_waf.xml_catalogue(ctx)
+
 def build(ctx):
+    ctx.catalogue = {}
+    ctx.add_post_fun(xml_catalogue)
     for b in building:
         ctx.recurse(b)
+    ctx.install_files('${PREFIX}', 'catalogue.xml')
 
 def install(ctx):
     for b in building:



More information about the vc mailing list