From 4e5114b3c919215a54d65aa32dff6d0547c6dbe6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 8 Feb 2012 18:37:44 +0000 Subject: Move Doxygen tag reading into lv2specgen and avoid intermediary file. --- Doxyfile | 2 +- gendoc.py | 47 +++------------------------------ lv2specgen/lv2specgen.py | 69 +++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 61 insertions(+), 57 deletions(-) diff --git a/Doxyfile b/Doxyfile index 3aa1c07..0776204 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1315,7 +1315,7 @@ TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create # a tag file that is based on the input files it reads. -GENERATE_TAGFILE = c_tags +GENERATE_TAGFILE = tags # If the ALLEXTERNALS tag is set to YES all external classes will be listed # in the class index. If set to NO only the inherited external classes diff --git a/gendoc.py b/gendoc.py index 67c68c2..cfa7b3b 100755 --- a/gendoc.py +++ b/gendoc.py @@ -7,8 +7,6 @@ import rdflib import shutil import subprocess import sys -import xml.dom -import xml.dom.minidom sys.path.append("./lv2specgen") import lv2specgen @@ -19,7 +17,7 @@ except: pass # Copy bundles (less build files) to build directory -shutil.copytree('lv2/ns', 'build/ns', +shutil.copytree('lv2/lv2plug.in/ns', 'build/ns', ignore=shutil.ignore_patterns('.*', 'waf', 'wscript', '*.in')) try: @@ -34,7 +32,7 @@ URIPREFIX = 'http://lv2plug.in/ns/' DOXPREFIX = 'ns/doc/html/' SPECGENDIR = os.path.abspath('lv2specgen') STYLEPATH = os.path.abspath('build/aux/style.css') -TAGFILE = os.path.abspath('build/doclinks') +TAGFILE = os.path.abspath('build/tags') BUILDDIR = os.path.abspath('build') doap = rdflib.Namespace('http://usefulinc.com/ns/doap#') @@ -54,45 +52,6 @@ print('## Generating header documentation with doxygen ##') shutil.copy('../doc/doxy-style.css', './doxy-style.css') subprocess.call(['doxygen', '../Doxyfile'], stdout=devnull) -def rescue_tags(in_path, out_path): - "Rescue Doxygen tag file from XML hell." - - def getChildText(elt, tagname): - "Return the content of the first child node with a certain tag name." - elements = elt.getElementsByTagName(tagname) - for e in elements: - if e.parentNode == elt: - return e.firstChild.nodeValue - return '' - - tagdoc = xml.dom.minidom.parse(in_path) - root = tagdoc.documentElement - bettertags = open(out_path, 'w') - for cn in root.childNodes: - if cn.nodeType == xml.dom.Node.ELEMENT_NODE and cn.tagName == 'compound': - if cn.getAttribute('kind') == 'page': - continue - name = getChildText(cn, 'name') - filename = getChildText(cn, 'filename') - # Sometimes the .html is there, sometimes it isn't... - if not filename.endswith('.html'): - filename += '.html' - bettertags.write('%s %s%s\n' % (name, DOXPREFIX, filename)) - if cn.getAttribute('kind') == 'file': - prefix = '' - else: - prefix = name + '::' - members = cn.getElementsByTagName('member') - for m in members: - mname = prefix + getChildText(m, 'name') - mafile = getChildText(m, 'anchorfile') - manchor = getChildText(m, 'anchor') - bettertags.write('%s %s%s#%s\n' % (mname, DOXPREFIX, \ - mafile, manchor)) - bettertags.close() - -rescue_tags('c_tags', TAGFILE) - def subst_file(template, output, dict): i = open(template, 'r') o = open(output, 'w') @@ -224,7 +183,7 @@ extensions.sort() for i in extensions: index_rows += i + '\n' -subst_file('../lv2/ns/index.html.in', 'ns/index.html', +subst_file('../lv2/lv2plug.in/ns/index.html.in', 'ns/index.html', { '@ROWS@': index_rows, '@TIME@': datetime.datetime.utcnow().strftime('%F %H:%M UTC') }) diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py index bac9cd5..6b4b7c6 100755 --- a/lv2specgen/lv2specgen.py +++ b/lv2specgen/lv2specgen.py @@ -45,6 +45,8 @@ import os import re import sys import xml.sax.saxutils +import xml.dom +import xml.dom.minidom try: from lxml import etree @@ -972,8 +974,54 @@ def getInstances(model, classes, properties): instances.append(getSubject(i)) return instances +def load_tags(path, doc_base): + "Build a (symbol => URI) map from a Doxygen tag file." -def specgen(specloc, indir, docdir, style_uri, doc_base, doclinks, instances=False, mode="spec"): + def getChildText(elt, tagname): + "Return the content of the first child node with a certain tag name." + for e in elt.childNodes: + if e.nodeType == xml.dom.Node.ELEMENT_NODE and e.tagName == tagname: + return e.firstChild.nodeValue + return '' + + def linkTo(sym, url): + #print "LINK: ", '%s' % (doc_base, url, sym) + return '%s' % (doc_base, url, sym) + + # FIXME: Parameterize + DOXPREFIX = 'ns/doc/html/' + + tagdoc = xml.dom.minidom.parse(path) + root = tagdoc.documentElement + linkmap = {} + for cn in root.childNodes: + if (cn.nodeType == xml.dom.Node.ELEMENT_NODE + and cn.tagName == 'compound' + and cn.getAttribute('kind') != 'page' + and cn.getAttribute('kind') != 'file'): + + name = getChildText(cn, 'name') + filename = getChildText(cn, 'filename') + + linkmap[name] = linkTo(name, DOXPREFIX + filename) + + prefix = '' + if cn.getAttribute('kind') != 'file': + prefix = name + '::' + + members = cn.getElementsByTagName('member') + for m in members: + mname = prefix + getChildText(m, 'name') + mafile = getChildText(m, 'anchorfile') + manchor = getChildText(m, 'anchor') + linkmap[mname] = linkTo( + mname, '%s%s#%s' % (DOXPREFIX, mafile, manchor)) + + #import pprint + #pprint.pprint(linkmap) + return linkmap + +def specgen(specloc, indir, docdir, style_uri, doc_base, tags, instances=False, mode="spec"): """The meat and potatoes: Everything starts here.""" global spec_url @@ -982,6 +1030,7 @@ def specgen(specloc, indir, docdir, style_uri, doc_base, doclinks, instances=Fal global spec_pre global ns_list global specgendir + global linkmap specgendir = os.path.abspath(indir) @@ -991,12 +1040,8 @@ def specgen(specloc, indir, docdir, style_uri, doc_base, doclinks, instances=Fal f = open(temploc, "r") template = f.read() - # Build a symbol -> link mapping for external links - dlfile = open(doclinks, 'r') - for line in dlfile: - sym, _, url = line.rstrip().partition(' ') - linkmap[sym] = '%s' % ( - os.path.join(doc_base, url), sym) + # Load code documentation link map from tags file + linkmap = load_tags(tags, doc_base) m = rdflib.ConjunctiveGraph() manifest_path = os.path.join(os.path.dirname(specloc), 'manifest.ttl') @@ -1195,14 +1240,14 @@ def getOntologyNS(m): def usage(): script = os.path.basename(sys.argv[0]) - print("""Usage: %s ONTOLOGY INDIR STYLE OUTPUT [FLAGS] + print("""Usage: %s ONTOLOGY INDIR STYLE OUTPUT BASE TAGS [FLAGS] ONTOLOGY : Path to ontology file INDIR : Input directory containing template.html and style.css STYLE : Stylesheet URI OUTPUT : HTML output path BASE : Documentation output base URI - DOCLINKS : Doxygen links file + TAGS : Doxygen tags file Optional flags: -i : Document class/property instances (disabled by default) @@ -1237,8 +1282,8 @@ if __name__ == "__main__": # Doxygen documentation directory doc_base = args[4] - # C symbol -> doxygen link mapping - doc_links = args[5] + # Doxygen tags file + doc_tags = args[5] docdir = os.path.join(doc_base, 'ns', 'doc') @@ -1256,7 +1301,7 @@ if __name__ == "__main__": i += 1 try: - save(dest, specgen(specloc, indir, docdir, style_uri, doc_base, doc_links, instances=instances)) + save(dest, specgen(specloc, indir, docdir, style_uri, doc_base, tags, instances=instances)) except: e = sys.exc_info()[1] print('error: ' + str(e)) -- cgit v1.2.1