]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/bib2html.py
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / buildscripts / bib2html.py
1 #!@PYTHON@
2 import os
3 import sys
4 import getopt
5 import tempfile
6 import string
7
8 # usage:
9 def usage ():
10   print 'usage: %s [-s style] [-o <outfile>] BIBFILES...';
11
12 #print os.environ['BSTINPUTS']
13
14 (options, files) = getopt.getopt(sys.argv[1:], 's:o:', [])
15
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
28
29
30 if style not in ['alpha','index','long','longp','long-pario','short','short-pario','split']:
31   sys.stderr.write ("Unknown style \`%s'\n" % style)
32
33 tempfile = tempfile.mktemp ('bib2html')
34
35 if not files:
36   usage ()
37   sys.exit (2)
38
39
40 def strip_extension (f, ext):
41     (p, e) = os.path.splitext (f)
42     if e == ext:
43         e = ''
44     return p + e
45
46 nf = []
47 for f in files:
48   nf.append (strip_extension(f, '.bib'))
49
50 files = string.join (nf,',')
51
52 open(tempfile + '.aux', 'w').write (r'''
53 \relax 
54 \citation{*}
55 \bibstyle{html-%(style)s}
56 \bibdata{%(files)s}''' % vars ()) 
57
58 cmd = "bibtex %s" % tempfile;
59
60 sys.stdout.write ("Invoking `%s'\n" % cmd)
61 stat = os.system (cmd)
62 if stat <> 0:
63   sys.exit(1)
64
65
66 #TODO: do tex -> html on output 
67
68 bbl = open (tempfile + '.bbl').read ()
69
70 open (output, 'w').write  (bbl)
71
72
73 def cleanup (tempfile):
74   for a in ['aux','bbl', 'blg']:
75     os.unlink (tempfile + '.' + a)
76
77 cleanup(tempfile)
78
79
80
81
82
83
84
85
86
87
88