IR corrections and proofreading.
[lilypond.git] / buildscripts / bib2html.py
blobc16f21cce28c9b91512bf08cf6393172bb96036a
1 #!@PYTHON@
2 import os
3 import sys
4 import getopt
5 import tempfile
7 # usage:
8 def usage ():
9 print 'usage: %s [-s style] [-o <outfile>] BIBFILES...'
11 (options, files) = getopt.getopt (sys.argv[1:], 's:o:', [])
13 output = 'bib.html'
14 style = 'long'
16 for (o,a) in options:
17 if o == '-h' or o == '--help':
18 usage ()
19 sys.exit (0)
20 elif o == '-s' or o == '--style':
21 style = a
22 elif o == '-o' or o == '--output':
23 output = a
24 else:
25 raise Exception ('unknown option: %s' % o)
28 if style not in ['alpha','index','long','longp','long-pario','short','short-pario','split']:
29 sys.stderr.write ("Unknown style \`%s'\n" % style)
31 tempfile = tempfile.mktemp ('bib2html')
33 if not files:
34 usage ()
35 sys.exit (2)
38 def strip_extension (f, ext):
39 (p, e) = os.path.splitext (f)
40 if e == ext:
41 e = ''
42 return p + e
44 nf = []
45 for f in files:
46 nf.append (strip_extension (f, '.bib'))
48 files = ','.join (nf)
50 open (tempfile + '.aux', 'w').write (r'''
51 \relax
52 \citation{*}
53 \bibstyle{html-%(style)s}
54 \bibdata{%(files)s}''' % vars ())
56 cmd = "bibtex %s" % tempfile
58 sys.stdout.write ("Invoking `%s'\n" % cmd)
59 stat = os.system (cmd)
60 if stat <> 0:
61 sys.exit(1)
64 #TODO: do tex -> html on output
66 bbl = open (tempfile + '.bbl').read ()
68 open (output, 'w').write (bbl)
71 def cleanup (tempfile):
72 for a in ['aux','bbl', 'blg']:
73 os.unlink (tempfile + '.' + a)
75 cleanup (tempfile)