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)
32 def strip_extension (f, ext):
33 (p, e) = os.path.splitext (f)
40 nf.append (strip_extension (f, '.bib'))
44 tmpfile = tempfile.mkstemp ('bib2texi')[1]
46 #This writes a .aux file to the temporary directory.
47 #The .aux file contains the commands for bibtex
48 #PEH changed the bibstyle to allow a single template file in the parent directory
49 #The template filename is texi-*.bst, where * defaults to 'long' but can be a parameter
50 open (tmpfile + '.aux', 'w').write (r'''
54 \bibdata{%(files)s}''' % vars ())
56 tmpdir = tempfile.gettempdir ()
58 #The command line to invoke bibtex
59 cmd = "TEXMFOUTPUT=%s bibtex %s" % (tmpdir, tmpfile)
61 sys.stdout.write ("Invoking `%s'\n" % cmd)
63 stat = os.system (cmd)
67 #TODO: do tex -> itexi on output
68 # Following 2 lines copy tmpfile.bbl to the desired output file
69 bbl = open (tmpfile + '.bbl').read ()
71 open (output, 'w').write (bbl)
73 def cleanup (tmpfile):
74 for a in ['aux','bbl', 'blg']:
75 os.unlink (tmpfile + '.' + a)
79 #Following line added by PEH - script was leaving a dangling temporary file with no extension