9 print 'usage: %s [-s style] [-o <outfile>] BIBFILES...'
11 (options, files) = getopt.getopt (sys.argv[1:], 's:o:', [])
17 if o == '-h' or o == '--help':
20 elif o == '-s' or o == '--style':
22 elif o == '-o' or o == '--output':
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)
36 def strip_extension (f, ext):
37 (p, e) = os.path.splitext (f)
44 nf.append (strip_extension (f, '.bib'))
48 tmpfile = tempfile.mkstemp ('bib2texi')[1]
50 open (tmpfile + '.aux', 'w').write (r'''
53 \bibstyle{texi-%(style)s}
54 \bibdata{%(files)s}''' % vars ())
56 tmpdir = tempfile.gettempdir ()
58 cmd = "TEXMFOUTPUT=%s bibtex %s" % (tmpdir, tmpfile)
60 sys.stdout.write ("Invoking `%s'\n" % cmd)
61 stat = os.system (cmd)
66 #TODO: do tex -> itexi on output
68 bbl = open (tmpfile + '.bbl').read ()
70 open (output, 'w').write (bbl)
73 def cleanup (tmpfile):
74 for a in ['aux','bbl', 'blg']:
75 os.unlink (tmpfile + '.' + a)