diff options
author | David Robillard <d@drobilla.net> | 2010-10-06 00:28:23 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-10-06 00:28:23 +0000 |
commit | 613067cfb1d2c5e1868de1bec78775698951f47e (patch) | |
tree | 5631c01b0e4aeccaab35c843ab7d6c172c1f7dbb /lv2includegen/lv2includegen.py | |
parent | 46aa9f16d92b8c3ca3b03a36bf54f18721725963 (diff) | |
download | lv2-613067cfb1d2c5e1868de1bec78775698951f47e.tar.xz |
Clean up and document as a proper Python module.
Diffstat (limited to 'lv2includegen/lv2includegen.py')
-rwxr-xr-x | lv2includegen/lv2includegen.py | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/lv2includegen/lv2includegen.py b/lv2includegen/lv2includegen.py index a27f1cd..ffca0e8 100755 --- a/lv2includegen/lv2includegen.py +++ b/lv2includegen/lv2includegen.py @@ -1,8 +1,25 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# lv2includegen, a tool to generate directory trees for including -# extension headers from source code. + +"""A program (and Python module) to generate a tree of symlinks to LV2 +extension bundles, where the path of the symlink corresponds to the URI of +the extension. This allows including extension headers in code without using +the bundle name. Including extension headers in this way is much better, +since there is no dependency on the (meaningless and non-persistent) bundle +name in the code using the header. + +For example, after running lv2includegen (and setting the compiler include +path appropriately), LV2 headers could be included like so: + +#include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/lv2plug.in/ns/ext/event/event.h" +#include "lv2/example.org/foo/foo.h" + +Where the initial "lv2" is arbitrary; in this case lv2includegen's output +directory was "lv2", and that directory's parent was added to the compiler +include search path. It is a good idea to use such a prefix directory so +domain names do not conflict with anything else in the include path. +""" __authors__ = 'David Robillard' __license = 'GNU GPL v3 or later <http://www.gnu.org/licenses/gpl.html>' @@ -21,7 +38,7 @@ rdf = RDF.NS('http://www.w3.org/1999/02/22-rdf-syntax-ns#') lv2 = RDF.NS('http://lv2plug.in/ns/lv2core#') def lv2_path(): - "Return the LV2 search path (LV2_PATH)." + "Return the LV2 search path (LV2_PATH in the environment, or a default)." if 'LV2_PATH' in os.environ: return os.environ['LV2_PATH'] else: @@ -29,15 +46,15 @@ def lv2_path(): print 'LV2_PATH unset, using default ' + ret return ret -def lv2_bundles(search_path): - "Return a list of all LV2 bundles found in a search path." +def bundles(search_path): + "Return a list of all LV2 bundles found in search_path." dirs = search_path.split(os.pathsep) bundles = [] for dir in dirs: bundles += glob.glob(os.path.join(dir, '*.lv2')) return bundles -def usage(): +def __usage(): script = os.path.basename(sys.argv[0]) print """Usage: %s OUTDIR @@ -48,7 +65,7 @@ Example: %s /usr/local/include/lv2 """ % (script, script) -def mkdir_p(path): +def __mkdir_p(path): "Equivalent of UNIX mkdir -p" try: os.makedirs(path) @@ -58,9 +75,10 @@ def mkdir_p(path): else: raise -def lv2includegen(bundles): - """Build a directory tree of symlinks to LV2 extension bundles - for including header files using URI-like paths.""" +def gen(bundles, outdir): + """Build a directory tree under outdir containing symlinks to all LV2 + extensions found in bundles, such that the symlink paths correspond to + the extension URIs.""" for bundle in bundles: # Load manifest into model manifest = RDF.Model() @@ -75,7 +93,7 @@ def lv2includegen(bundles): ext_dir = os.path.join(outdir, ext_path) # Make parent directories - mkdir_p(os.path.dirname(ext_dir)) + __mkdir_p(os.path.dirname(ext_dir)) # Remove existing symlink if necessary if os.access(ext_dir, os.F_OK): @@ -97,4 +115,4 @@ if __name__ == "__main__": outdir = args[0] print "Building LV2 include tree at", outdir - lv2includegen(lv2_bundles(lv2_path())) + gen(bundles(lv2_path()), outdir) |