aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-10-14 19:42:42 -0400
committerDavid Robillard <d@drobilla.net>2016-10-14 19:43:08 -0400
commitb40d155aa5cf1b281db88b500580deefbad93883 (patch)
treeceb821346c98732cd8d82aae1d5443b0bcc16ec0
parentc681ba78e34b85b032077fe50d56bf9e2e3c1654 (diff)
downloadlv2-b40d155aa5cf1b281db88b500580deefbad93883.tar.xz
Simplify command line use of lv2specgen
-rwxr-xr-xlv2specgen/lv2specgen.py85
-rw-r--r--wscript9
2 files changed, 56 insertions, 38 deletions
diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py
index ec7b987..11647f2 100755
--- a/lv2specgen/lv2specgen.py
+++ b/lv2specgen/lv2specgen.py
@@ -80,6 +80,7 @@ spec_url = None
spec_ns_str = None
spec_ns = None
spec_pre = None
+spec_bundle = None
specgendir = None
ns_list = {
"http://www.w3.org/1999/02/22-rdf-syntax-ns#" : "rdf",
@@ -148,6 +149,10 @@ def isLiteral(n):
def niceName(uri):
+ global spec_bundle
+ if uri.startswith(spec_bundle):
+ return uri[len(spec_bundle):]
+
regexp = re.compile("^(.*[/#])([^/#]+)$")
rez = regexp.search(uri)
if not rez:
@@ -1109,7 +1114,7 @@ def load_tags(path, docdir):
return linkmap
-def writeIndex(model, index_path):
+def writeIndex(model, specloc, index_path, root_path):
# Get extension URI
ext_node = model.value(None, rdf.type, lv2.Specification)
if not ext_node:
@@ -1155,7 +1160,7 @@ def writeIndex(model, index_path):
name = name[4:]
# Specification (comment is to act as a sort key)
- target = os.path.relpath(path, root_path)
+ target = os.path.relpath(os.path.dirname(specloc), root_path)
if not options.online_docs:
target += '/%s.html' % b
row = '<tr><!-- %s --><td><a rel="rdfs:seeAlso" href="%s">%s</a></td>' % (
@@ -1195,9 +1200,10 @@ def writeIndex(model, index_path):
index.close()
-def specgen(specloc, indir, style_uri, docdir, tags, opts, instances=False, root_link=None, index_path=None):
+def specgen(specloc, indir, style_uri, docdir, tags, opts, instances=False, root_link=None, index_path=None, root_path=None):
"""The meat and potatoes: Everything starts here."""
+ global spec_bundle
global spec_url
global spec_ns_str
global spec_ns
@@ -1206,6 +1212,7 @@ def specgen(specloc, indir, style_uri, docdir, tags, opts, instances=False, root
global specgendir
global linkmap
+ spec_bundle = "file://%s/" % os.path.abspath(os.path.dirname(specloc))
specgendir = os.path.abspath(indir)
# Template
@@ -1355,7 +1362,10 @@ def specgen(specloc, indir, style_uri, docdir, tags, opts, instances=False, root
template = template.replace('@VERSION@', version_string)
- content_links = '<li><a href="%s">API</a></li>' % os.path.join(docdir, 'group__%s.html' % basename)
+ content_links = ''
+ if docdir is not None:
+ content_links = '<li><a href="%s">API</a></li>' % os.path.join(docdir, 'group__%s.html' % basename)
+
template = template.replace('@CONTENT_LINKS@', content_links)
comment = getComment(m, rdflib.URIRef(spec_url), classlist, proplist, instalist)
@@ -1367,8 +1377,9 @@ def specgen(specloc, indir, style_uri, docdir, tags, opts, instances=False, root
template = template.replace('@DATE@', datetime.datetime.utcnow().strftime('%F'))
template = template.replace('@TIME@', datetime.datetime.utcnow().strftime('%F %H:%M UTC'))
+ # Write index row
if index_path is not None:
- writeIndex(m, index_path)
+ writeIndex(m, specloc, index_path, root_path)
return template
@@ -1411,55 +1422,55 @@ def getOntologyNS(m):
def usage():
script = os.path.basename(sys.argv[0])
- return """Usage: %s ONTOLOGY INDIR STYLE OUTPUT [INDEX_PATH DOCDIR TAGS] [FLAGS]
-
- ONTOLOGY : Path to ontology file
- INDIR : Input directory containing template.html and style.css
- STYLE : Stylesheet URI
- OUTPUT : HTML output path
- DOCDIR : Doxygen HTML directory
- TAGS : Doxygen tags file
-
-Example:
- %s lv2_foos.ttl template.html style.css lv2_foos.html ../doc -i -p foos
-""" % (script, script)
+ return "Usage: %s ONTOLOGY_TTL OUTPUT_HTML [OPTION]..." % script
if __name__ == "__main__":
"""Ontology specification generator tool"""
+ indir = os.path.abspath(os.path.dirname(sys.argv[0]))
+ if not os.path.exists(os.path.join(indir, 'template.html')):
+ indir = os.path.join(os.path.dirname(indir), 'share', 'lv2specgen')
+
opt = optparse.OptionParser(usage=usage(),
description='Write HTML documentation for an RDF ontology.')
opt.add_option('--list-email', type='string', dest='list_email',
help='Mailing list email address')
opt.add_option('--list-page', type='string', dest='list_page',
help='Mailing list info page address')
- opt.add_option('-r', '--root', type='string', dest='root', default='', help='Root path')
+ opt.add_option('--template-dir', type='string', dest='template_dir', default=indir,
+ help='Template directory')
+ opt.add_option('--style-uri', type='string', dest='style_uri', default='style.css',
+ help='Stylesheet URI')
+ opt.add_option('--docdir', type='string', dest='docdir', default=None,
+ help='Doxygen output directory')
+ opt.add_option('--index', type='string', dest='index_path', default=None,
+ help='Index row output file')
+ opt.add_option('--tags', type='string', dest='tags', default=None,
+ help='Doxygen tags file')
+ opt.add_option('-r', '--root', type='string', dest='root', default='',
+ help='Root path')
opt.add_option('-p', '--prefix', type='string', dest='prefix',
help='Specification Turtle prefix')
opt.add_option('-i', '--instances', action='store_true', dest='instances',
help='Document instances')
+ opt.add_option('--copy-style', action='store_true', dest='copy_style',
+ help='Copy style from template directory to output directory')
opt.add_option('--online', action='store_true', dest='online_docs',
help='Generate online documentation')
(options, args) = opt.parse_args()
opts = vars(options)
- if (len(args) < 3):
- print(usage())
+ if len(args) < 2:
+ opt.print_help()
sys.exit(-1)
spec_pre = options.prefix
ontology = "file:" + str(args[0])
- indir = args[1]
- style = args[2]
- output = args[3]
- index_path = None
- docdir = None
- tags = None
- if len(args) > 5:
- index_path = args[4]
- docdir = args[5]
- tags = args[6]
+ output = args[1]
+ index_path = options.index_path
+ docdir = options.docdir
+ tags = options.tags
out = '.'
spec = args[0]
@@ -1475,21 +1486,27 @@ if __name__ == "__main__":
# Root link
root_path = opts['root']
- root_link = os.path.relpath(root_path, path)
+ root_link = os.path.relpath(root_path, path) if root_path else '.'
if not options.online_docs:
root_link = os.path.join(root_link, 'index.html')
# Generate spec documentation
specdoc = specgen(
- os.path.abspath(spec),
+ spec,
indir,
- style,
+ opts['style_uri'],
docdir,
tags,
opts,
instances=True,
root_link=root_link,
- index_path=index_path)
+ index_path=index_path,
+ root_path=root_path)
# Save to HTML output file
save(output, specdoc)
+
+ if opts['copy_style']:
+ import shutil
+ shutil.copyfile(os.path.join(indir, 'style.css'),
+ os.path.join(os.path.dirname(output), 'style.css'))
diff --git a/wscript b/wscript
index 001eb19..44c7fa2 100644
--- a/wscript
+++ b/wscript
@@ -346,10 +346,11 @@ def build(bld):
bld(rule = '../lv2specgen/lv2specgen.py --root=' + root_path +
' --list-email=devel@lists.lv2plug.in'
' --list-page=http://lists.lv2plug.in/listinfo.cgi/devel-lv2plug.in'
- ' ${SRC} ../lv2specgen ' +
- os.path.relpath('aux/style.css', out_bundle) +
- ' ${TGT} %s doc/tags' %
- os.path.relpath('doc/html', os.path.dirname(html_path)),
+ ' --style-uri=' + os.path.relpath('aux/style.css', out_bundle) +
+ ' --docdir=' + os.path.relpath('doc/html', os.path.dirname(html_path)) +
+ ' --tags=doc/tags' +
+ ' --index=' + index_file +
+ ' ${SRC} ${TGT}',
source = os.path.join(i.srcpath(), name + '.ttl'),
target = [html_path, index_file])