#!/usr/bin/env python # -*- coding: utf-8 -*- # # lv2docgen, a documentation generator for LV2 plugins # Copyright 2012 David Robillard # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. __date__ = '2012-03-27' __version__ = '0.0.0' __authors__ = 'David Robillard' __license__ = 'ISC License ' __contact__ = 'devel@lists.lv2plug.in' import errno import os import sys try: import rdflib except ImportError: sys.exit('Error importing rdflib') doap = rdflib.Namespace('http://usefulinc.com/ns/doap#') lv2 = rdflib.Namespace('http://lv2plug.in/ns/lv2core#') rdf = rdflib.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#') rdfs = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#') def uri_to_path(uri): path = uri[uri.find(':'):] while not path[0].isalpha(): path = path[1:] return path def get_doc(model, subject): comment = model.value(subject, rdfs.comment, None) if comment: return '

%s

' % comment return '' def port_doc(model, port): name = model.value(port, lv2.name, None) comment = model.value(port, rdfs.comment, None) html = '

%s

' % name html += get_doc(model, port) html += '
' return html def plugin_doc(model, plugin, style_uri): uri = str(plugin) name = model.value(plugin, doap.name, None) html = ''' ''' % uri html += ''' %s ''' % (name, style_uri) html += ''' ''' % (name, uri, uri, '0.0.0') html += get_doc(model, plugin) ports_html = '' for p in model.triples([plugin, lv2.port, None]): ports_html += port_doc(model, p[2]) if len(ports_html): html += '''

Ports

%s
''' % ports_html html += ' ' return html if __name__ == '__main__': 'LV2 plugin documentation generator' if len(sys.argv) < 2: print('Usage: %s OUTDIR FILE...' % sys.argv[0]) sys.exit(1) outdir = sys.argv[1] files = sys.argv[2:] model = rdflib.ConjunctiveGraph() for f in files: model.parse(f, format='n3') style_uri = os.path.abspath(os.path.join(outdir, 'style.css')) for p in model.triples([None, rdf.type, lv2.Plugin]): plugin = p[0] html = plugin_doc(model, plugin, style_uri) path = uri_to_path(plugin) outpath = os.path.join(outdir, path + '.html') try: os.makedirs(os.path.dirname(outpath)) except OSError: e = sys.exc_info()[1] if e.errno == errno.EEXIST: pass else: raise print 'Writing <%s> documentation to %s' % (plugin, outpath) out = open(outpath, 'w') out.write(html) out.close() d='n47' href='#n47'>47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169