From cef9811dac46a9d54dab0f0d82ce5c3ae032fc7c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 4 Oct 2010 18:21:08 +0000 Subject: Initial import of lv2plug.in universe. --- lv2compatgen/lv2compatgen.py | 154 +++++++++++++++++++++++++++++++++++++++++++ lv2compatgen/style.css | 1 + lv2compatgen/template.html | 26 ++++++++ 3 files changed, 181 insertions(+) create mode 100755 lv2compatgen/lv2compatgen.py create mode 120000 lv2compatgen/style.css create mode 100644 lv2compatgen/template.html (limited to 'lv2compatgen') diff --git a/lv2compatgen/lv2compatgen.py b/lv2compatgen/lv2compatgen.py new file mode 100755 index 0000000..60bad70 --- /dev/null +++ b/lv2compatgen/lv2compatgen.py @@ -0,0 +1,154 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- +# +# lv2compatgen +# Generates compatiblity documentation for LV2 hosts and plugins. +# Copyright (c) 2009 David Robillard +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +__authors__ = "David Robillard" +__license__ = "MIT License " +__contact__ = "devel@lists.lv2plug.in" +__date__ = "2009-11-08" + +import os +import sys +import datetime +import re +import urllib +import RDF + +rdf = RDF.NS('http://www.w3.org/1999/02/22-rdf-syntax-ns#') +rdfs = RDF.NS('http://www.w3.org/2000/01/rdf-schema#') +owl = RDF.NS('http://www.w3.org/2002/07/owl#') +vs = RDF.NS('http://www.w3.org/2003/06/sw-vocab-status/ns#') +lv2 = RDF.NS('http://lv2plug.in/ns/lv2core#') +doap = RDF.NS('http://usefulinc.com/ns/doap#') +foaf = RDF.NS('http://xmlns.com/foaf/0.1/') + +def print_usage(): + print """ +Usage: lv2compatgen.py DATA + +DATA must be a Redland RDF store containing all relevant LV2 data +(a file would be too slow to parse). + +You can create one with something like this: + +find /usr/lib/lv2 /usr/local/lib/lv2 ~/.lv2 -name '*.ttl' >> lv2_files.txt +for i in `cat lv2_files.txt`; do + rapper -g $i -o turtle >> lv2_all.ttl; +done +rdfproc ./data parse lv2_all.ttl turtle +""" + +if len(sys.argv) != 2: + print_usage() + sys.exit(1) + +store_name = sys.argv[1] + +storage = RDF.HashStorage(store_name, options="hash-type='bdb'") +model = RDF.Model(storage=storage) + +class Plugin: + def __init__(self): + self.name = "" + self.optional = [] + self.required = [] + +class Feature: + def __init__(self): + self.name = "" + +# Find plugins and their required and optional features +plugins = {} +features = {} +for i in model.find_statements(RDF.Statement(None, rdf.type, lv2.Plugin)): + plug = Plugin() + for j in model.find_statements(RDF.Statement(i.subject, lv2.requiredFeature, None)): + plug.required += [j.object.uri] + if not j.object.uri in features: + features[j.object.uri] = Feature() + for j in model.find_statements(RDF.Statement(i.subject, lv2.optionalFeature, None)): + plug.optional += [j.object.uri] + if not j.object.uri in features: + features[j.object.uri] = Feature() + for j in model.find_statements(RDF.Statement(i.subject, doap.name, None)): + plug.name = str(j.object) + plugins[i.subject.uri] = plug + +# Find feature names +for uri, feature in features.items(): + for j in model.find_statements(RDF.Statement(uri, doap.name, None)): + feature.name = j.object.literal_value['string'] + for j in model.find_statements(RDF.Statement(uri, rdfs.label, None)): + print "LABEL:", j.object + +# Generate body +body = '' +for uri, feature in features.items(): + if feature.name != "": + body += '' % feature.name + else: + body += '' % uri + +for uri, plug in plugins.items(): + #body += '' % uri + body += '' % plug.name + for e in features.keys(): + if e in plug.required: + body += '' + elif e in plug.optional: + body += '' + else: + body += '' + body += '\n' +body += '
%s%s
%s
%sRequiredOptional
' + +# Load output template +temploc = 'template.html' +template = None +try: + f = open(temploc, "r") + template = f.read() +except Exception, e: + print 'Error reading template:', str(e) + sys.exit(2) + +# Load style +styleloc = 'style.css' +style = '' +try: + f = open(styleloc, "r") + style = f.read() +except Exception, e: + print "Error reading from style \"" + styleloc + "\": " + str(e) + usage() + +# Replace tokens in template +template = template.replace('@STYLE@', style) +template = template.replace('@BODY@', body) +template = template.replace('@TIME@', datetime.datetime.utcnow().strftime('%F %H:%M UTC')) + +# Write output +output = open('./compat.html', 'w') +print >>output, template +output.close() diff --git a/lv2compatgen/style.css b/lv2compatgen/style.css new file mode 120000 index 0000000..f320096 --- /dev/null +++ b/lv2compatgen/style.css @@ -0,0 +1 @@ +../doc/style.css \ No newline at end of file diff --git a/lv2compatgen/template.html b/lv2compatgen/template.html new file mode 100644 index 0000000..2948759 --- /dev/null +++ b/lv2compatgen/template.html @@ -0,0 +1,26 @@ + + + + LV2 Feature Support + + + + + +

LV2 Feature Support

+ + @BODY@ + +
+
+ Automatically generated + by lv2compatgen + at @TIME@ +
+ + + + -- cgit v1.2.1