]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/bib2html.py
release: 1.4.10
[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
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 os.system (cmd) 
62
63
64 #TODO: do tex -> html on output 
65
66 bbl =open (tempfile + '.bbl').read ()
67
68 open (output, 'w').write  (bbl)
69
70
71 def cleanup (tempfile):
72     for a in ['aux','bbl', 'blg']:
73         os.unlink (tempfile + '.' + a)
74
75 cleanup(tempfile)
76
77
78
79
80
81
82
83
84
85
86