* lily/main.cc (main_prog): print summary of failed files.
[lilypond.git] / buildscripts / bib2html.py
blob37bc4694fd35455014b39cfdbe9f17db8bc19241
1 #!@PYTHON@
2 import os
3 import sys
4 import getopt
5 import tempfile
6 import string
8 # usage:
9 def usage ():
10 print 'usage: %s [-s style] [-o <outfile>] BIBFILES...';
14 (options, files) = getopt.getopt(sys.argv[1:], 's:o:', [])
16 output = 'bib.html'
17 style = 'long'
18 for (o,a) in options:
19 if o == '-h' or o == '--help':
20 usage ()
21 sys.exit (0)
22 elif o == '-s' or o == '--style':
23 style = a
24 elif o == '-o' or o == '--output':
25 output = a
26 else:
27 raise 'unknown opt ', o
30 if style not in ['alpha','index','long','longp','long-pario','short','short-pario','split']:
31 sys.stderr.write ("Unknown style \`%s'\n" % style)
33 tempfile = tempfile.mktemp ('bib2html')
35 if not files:
36 usage ()
37 sys.exit (2)
40 def strip_extension (f, ext):
41 (p, e) = os.path.splitext (f)
42 if e == ext:
43 e = ''
44 return p + e
46 nf = []
47 for f in files:
48 nf.append (strip_extension(f, '.bib'))
50 files = string.join (nf,',')
52 open(tempfile + '.aux', 'w').write (r'''
53 \relax
54 \citation{*}
55 \bibstyle{html-%(style)s}
56 \bibdata{%(files)s}''' % vars ())
58 cmd = "bibtex %s" % tempfile;
60 sys.stdout.write ("Invoking `%s'\n" % cmd)
61 os.system (cmd)
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)