9 print 'usage: %s [-s style] [-o <outfile>] [-q] BIBFILES...'
10 print '-q suppresses most output'
12 (options, files) = getopt.getopt (sys.argv[1:], 's:o:hq', [])
19 if o == '-h' or o == '--help':
22 elif o == '-s' or o == '--style':
24 elif o == '-o' or o == '--output':
29 raise Exception ('unknown option: %s' % o)
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 #This writes a .aux file to the temporary directory.
51 #The .aux file contains the commands for bibtex
52 #PEH changed the bibstyle to allow a single template file in the parent directory
53 #The template filename is texi-*.bst, where * defaults to 'long' but can be a parameter
54 open (tmpfile + '.aux', 'w').write (r'''
58 \bibdata{%(files)s}''' % vars ())
60 tmpdir = tempfile.gettempdir ()
65 quiet_flag = ' -terse '
67 #The command line to invoke bibtex
68 cmd = "TEXMFOUTPUT=%s bibtex %s %s" % (tmpdir, quiet_flag, tmpfile)
71 sys.stdout.write ("Running bibtex on %s\n" % files)
73 stat = os.system (cmd)
77 #TODO: do tex -> itexi on output
78 # Following 2 lines copy tmpfile.bbl to the desired output file
79 bbl = open (tmpfile + '.bbl').read ()
81 open (output, 'w').write (bbl)
83 def cleanup (tmpfile):
84 for a in ['aux','bbl', 'blg']:
85 os.unlink (tmpfile + '.' + a)
89 #Following line added by PEH - script was leaving a dangling temporary file with no extension