diff options
author | David Robillard <d@drobilla.net> | 2011-11-04 16:42:35 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-11-04 16:42:35 +0000 |
commit | ea4adcfc99e54f76df37665e1cfe904c6bb102f1 (patch) | |
tree | bd35d5dee930578c59d4314e196b730d95269edc | |
parent | d45e469b43b6ec467e458f719b0dc3b4c8c4a900 (diff) | |
download | lv2-ea4adcfc99e54f76df37665e1cfe904c6bb102f1.tar.xz |
Call lv2specgen as a module rather than spawning a new process.
This significantly speeds up overall runtime of gendoc.py.
-rwxr-xr-x | gendoc.py | 57 | ||||
-rwxr-xr-x | lv2specgen/lv2specgen.py | 40 |
2 files changed, 47 insertions, 50 deletions
@@ -1,13 +1,17 @@ #!/usr/bin/env python +import datetime +import glob import os +import re import shutil import subprocess -import glob -import re -import datetime -import xml.dom.minidom +import sys import xml.dom +import xml.dom.minidom + +sys.path.append("./lv2specgen") +import lv2specgen out_base = os.path.join('build', 'ns') try: @@ -85,18 +89,18 @@ shutil.copy('core.lv2/lv2.ttl', lv2_outdir) shutil.copy('core.lv2/manifest.ttl', lv2_outdir) shutil.copy('doc/index.php', lv2_outdir) -def gendoc(specgen_dir, bundle_dir, ttl_filename, html_filename): - subprocess.call([os.path.join(specgen_dir, 'lv2specgen.py'), - os.path.join(bundle_dir, ttl_filename), - specgen_dir, - - STYLEURI, - os.path.join(out_base, html_filename), - os.path.join('..', '..'), - TAGFILE, - '-i']) - -gendoc('./lv2specgen', 'core.lv2', 'lv2.ttl', 'lv2core/lv2core.html') +oldcwd = os.getcwd() +os.chdir(lv2_outdir) +print(' * Running lv2specgen for lv2core in ' + os.getcwd()) +lv2specgen.save('lv2.html', + lv2specgen.specgen('../../../core.lv2/lv2.ttl', + '../../../lv2specgen', + os.path.join('..', '..', 'ns', 'doc'), + STYLEURI, + os.path.join('..', '..'), + os.path.join('..', '..', '..', TAGFILE), + instances=True)) +os.chdir(oldcwd) footer = open('./lv2specgen/footer.html', 'r') @@ -173,15 +177,18 @@ SELECT ?rev FROM <%s.lv2/%s.ttl> WHERE { <%s> doap:release [ doap:revision ?rev specgendir = '../../../lv2specgen/' if (os.access(outdir + '/%s.lv2/%s.ttl' % (b, b), os.R_OK)): - print(' * Calling lv2specgen for %s%s/%s' %(URIPREFIX, dir, b)) - subprocess.call([specgendir + 'lv2specgen.py', - '%s.lv2/%s.ttl' % (b, b), - specgendir, - STYLEURI, - '%s.lv2/%s.html' % (b, b), - os.path.join('..', '..', '..'), - os.path.join('..', '..', '..', TAGFILE), - '-i'], cwd=outdir); + oldcwd = os.getcwd() + os.chdir(outdir) + print(' * Running lv2specgen for %s in %s' % (b, os.getcwd())) + lv2specgen.save('%s.lv2/%s.html' % (b, b), + lv2specgen.specgen('%s.lv2/%s.ttl' % (b, b), + specgendir, + os.path.join('..', '..', '..', 'ns', 'doc'), + STYLEURI, + os.path.join('..', '..', '..'), + os.path.join('..', '..', '..', TAGFILE), + instances=True)) + os.chdir(oldcwd) li = '<li>' if minor == '0' or (int(micro) % 2) != 0: diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py index 949ec08..8138654 100755 --- a/lv2specgen/lv2specgen.py +++ b/lv2specgen/lv2specgen.py @@ -867,24 +867,14 @@ def specgen(specloc, indir, docdir, style_uri, doc_base, doclinks, instances=Fal # Template temploc = os.path.join(indir, "template.html") template = None - try: - f = open(temploc, "r") - template = f.read() - except Exception: - e = sys.exc_info()[1] - print("Error reading from template \"" + temploc + "\": " + str(e)) - usage() + f = open(temploc, "r") + template = f.read() # Footer footerloc = os.path.join(indir, "footer.html") footer = '' - try: - f = open(footerloc, "r") - footer = f.read() - except Exception: - e = sys.exc_info()[1] - print("Error reading from footer \"" + footerloc + "\": " + str(e)) - usage() + f = open(footerloc, "r") + footer = f.read() template = template.replace('@FOOTER@', footer) @@ -896,15 +886,10 @@ def specgen(specloc, indir, docdir, style_uri, doc_base, doclinks, instances=Fal os.path.join(doc_base, url), sym) m = rdflib.ConjunctiveGraph() - try: - base = specloc[0:specloc.rfind('/')] - manifest_path = os.path.join(base, 'manifest.ttl') - m.parse(manifest_path, format='n3') - m.parse(specloc, format='n3') - except: - e = sys.exc_info()[1] - print('Error reading ontology: ' + str(e)) - return None + base = specloc[0:specloc.rfind('/')] + manifest_path = os.path.join(base, 'manifest.ttl') + m.parse(manifest_path, format='n3') + m.parse(specloc, format='n3') spec_url = getOntologyNS(m) @@ -997,8 +982,6 @@ def specgen(specloc, indir, docdir, style_uri, doc_base, doclinks, instances=Fal header = basename + '.h' other_files += ', <a href="%s">%s</a>' % (header, header) - #other_files += '<li><a href="%s">Ontology</a> %s</li>\n' % (filename, filename) - abs_bundle_path = os.path.abspath(bundle_path) see_also_files = specProperties(m, spec_url, rdfs.seeAlso) for f in see_also_files: @@ -1122,4 +1105,11 @@ if __name__ == "__main__": i += 1 i += 1 + try: save(dest, specgen(specloc, indir, docdir, style_uri, doc_base, doc_links, instances=instances)) + except: + e = sys.exc_info()[1] + print('error: ' + str(e)) + sys.exit(1) + + sys.exit(0) |