Better RDF library abstraction (just use URIs, don't depend on node object style).
[lv2.git] / gendoc.py
blob00a7cae245aebdd8bc9467ccf4ccb9c20f44b93f
1 #!/usr/bin/env python
3 import os
4 import shutil
5 import subprocess
6 import glob
7 import re
8 import datetime
10 out_base = os.path.join('build', 'default', 'doc')
11 try:
12 shutil.rmtree(out_base)
13 except:
14 pass
16 os.makedirs(out_base)
18 URIPREFIX = 'http://lv2plug.in/ns/'
19 SPECGENDIR = './specgen'
21 release_dir = os.path.join('build', 'default', 'spec')
22 try:
23 os.mkdir(release_dir)
24 except:
25 pass
27 print '** Generating core documentation'
29 lv2_outdir = os.path.join(out_base, 'lv2core')
30 os.mkdir(lv2_outdir)
31 shutil.copy('core.lv2/lv2.h', lv2_outdir)
32 shutil.copy('core.lv2/lv2.ttl', lv2_outdir)
33 shutil.copy('core.lv2/manifest.ttl', lv2_outdir)
34 shutil.copy('doc/index.php', lv2_outdir)
36 devnull = open(os.devnull, 'w')
38 def gendoc(specgen_dir, bundle_dir, ttl_filename, html_filename):
39 subprocess.call([os.path.join(specgen_dir, 'lv2specgen.py'),
40 os.path.join(bundle_dir, ttl_filename),
41 os.path.join(specgen_dir, 'template.html'),
42 os.path.join(specgen_dir, 'style.css'),
43 os.path.join(out_base, html_filename),
44 os.path.join('..', 'doc'),
45 '-i'])
47 gendoc('./lv2specgen', 'core.lv2', 'lv2.ttl', 'lv2core/lv2core.html')
49 style = open('./lv2specgen/style.css', 'r')
50 footer = open('./lv2specgen/footer.html', 'r')
52 # Generate main (ontology) documentation and indices
53 for dir in ['ext', 'extensions']:
54 print "** Generating %s%s documentation" % (URIPREFIX, dir)
56 outdir = os.path.join(out_base, dir)
58 shutil.copytree(dir, outdir, ignore = lambda src, names: '.svn')
60 index_html = """<?xml version="1.0" encoding="utf-8"?>
61 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
62 <html xmlns="http://www.w3.org/1999/xhtml">
63 <head>
64 <meta http-equiv="Content-Type" content="application/xhtml+xml;charset=utf-8"/>
65 <title>LV2 Extensions</title>
66 <style type="text/css">
67 """
69 index_html += style.read()
71 index_html += """
72 </style></head>
73 <body><h1>LV2 Extensions</h1>
74 <h2>""" + URIPREFIX + dir + "/</h2><ul>\n"
76 extensions = []
78 for bundle in glob.glob(os.path.join(dir, '*.lv2')):
79 b = bundle.replace('.lv2', '')
80 b = b[b.find('/') + 1:]
82 # Get extension URI
83 ext = subprocess.Popen(['roqet', '-q', '-e', """
84 PREFIX lv2: <http://lv2plug.in/ns/lv2core#>
85 SELECT ?ext FROM <%s.lv2/%s.ttl> WHERE { ?ext a lv2:Specification }
86 """ % (os.path.join(dir, b), b)], stdout=subprocess.PIPE).communicate()[0]
88 if ext == "":
89 continue
91 ext = re.sub('^result: \[ext=uri<', '', ext)
92 ext = re.sub('>\]$', '', ext).strip()
94 # Get revision
95 query = """
96 PREFIX lv2: <http://lv2plug.in/ns/lv2core#>
97 PREFIX doap: <http://usefulinc.com/ns/doap#>
98 SELECT ?rev FROM <%s.lv2/%s.ttl> WHERE { <%s> doap:release [ doap:revision ?rev ] }
99 """ % (os.path.join(dir, b), b, ext)
101 rev = subprocess.Popen(['roqet', '-q', '-e', query],
102 stdout=subprocess.PIPE).communicate()[0]
104 if rev != '':
105 rev = re.sub('^result: \[rev=string\("', '', rev)
106 rev = re.sub('"\)\]$', '', rev).strip()
107 else:
108 rev = '0'
110 if rev != '0':
111 path = os.path.join(release_dir, 'lv2-%s-%s.0.tar.gz' % (b, rev))
112 subprocess.call(['tar', '-czf', path, os.path.join(outdir, '%s.lv2' % b)])
114 specgendir = '../../../../lv2specgen/'
115 if (os.access(outdir + '/%s.lv2/%s.ttl' % (b, b), os.R_OK)):
116 print ' * Calling lv2specgen for %s%s/%s' %(URIPREFIX, dir, b)
117 subprocess.call([specgendir + 'lv2specgen.py',
118 '%s.lv2/%s.ttl' % (b, b),
119 specgendir + 'template.html',
120 specgendir + 'style.css',
121 '%s.lv2/%s.html' % (b, b),
122 os.path.join('..', '..', 'doc'),
123 '-i'], cwd=outdir);
125 li = '<li>'
126 if rev == '0':
127 li += '<span style="color: red;">Experimental: </span>'
128 li += '<a rel="rdfs:seeAlso" href="%s">%s</a>' % (b, b)
129 li += '</li>'
131 extensions.append(li)
133 shutil.copy('doc/index.php', os.path.join(outdir, b + '.lv2', 'index.php'))
135 # Remove .lv2 suffix from bundle name (to make URI resolvable)
136 os.rename(outdir + '/%s.lv2' % b, outdir + '/%s' % b)
138 extensions.sort()
139 for i in extensions:
140 index_html += i + '\n'
142 index_html += '</ul>\n'
144 index_html += '<div class="footer">'
145 index_html += '<span class="footer-text">Generated on '
146 index_html += datetime.datetime.utcnow().strftime('%F %H:%M UTC')
147 index_html += ' by LV2 gendoc.py</span>'
148 index_html += footer.read() + '</div>'
150 index_html += '</body></html>\n'
152 index_file = open(os.path.join(outdir, 'index.html'), 'w')
153 print >>index_file, index_html
154 index_file.close()
156 # Generate code (headers) documentation
157 print "** Generating header documentation"
158 #shutil.copy('Doxyfile', os.path.join('upload', 'Doxyfile'))
159 print ' * Calling doxygen in ' + os.getcwd()
160 subprocess.call('doxygen', stdout=devnull)
162 devnull.close()
163 style.close()
164 footer.close()