X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fbuild%2Fbib2texi.py;h=b76a171a09263bd64c9ba1970a1b0439845aa3ac;hb=HEAD;hp=dd896fa8b00b096bd3cec9bcd31b135908cfe7e9;hpb=b503d2c54e1c3c6bf1677226b2c2aaab94e8aba8;p=lilypond.git diff --git a/scripts/build/bib2texi.py b/scripts/build/bib2texi.py index dd896fa8b0..b76a171a09 100644 --- a/scripts/build/bib2texi.py +++ b/scripts/build/bib2texi.py @@ -6,12 +6,14 @@ import tempfile # usage: def usage (): - print 'usage: %s [-s style] [-o ] BIBFILES...' + print 'usage: bib2texi.py [-s style] [-o ] [-q] BIBFILES...' + print '-q suppresses most output' -(options, files) = getopt.getopt (sys.argv[1:], 's:o:', []) +(options, files) = getopt.getopt (sys.argv[1:], 's:o:hq', []) output = 'bib.itexi' style = 'long' +show_output = True for (o,a) in options: if o == '-h' or o == '--help': @@ -21,6 +23,8 @@ for (o,a) in options: style = a elif o == '-o' or o == '--output': output = a + elif o == '-q': + show_output = False else: raise Exception ('unknown option: %s' % o) @@ -28,6 +32,11 @@ if not files: usage () sys.exit (2) +marker = """@c This file was autogenerated +@c from: %s +@c by: %s + +""" % (", ".join(files), sys.argv[0]) def strip_extension (f, ext): (p, e) = os.path.splitext (f) @@ -55,20 +64,35 @@ open (tmpfile + '.aux', 'w').write (r''' tmpdir = tempfile.gettempdir () +if (show_output): + quiet_flag = '' +else: + quiet_flag = ' -terse ' + #The command line to invoke bibtex -cmd = "TEXMFOUTPUT=%s bibtex %s" % (tmpdir, tmpfile) +cmd = "TEXMFOUTPUT=%s bibtex %s %s" % (tmpdir, quiet_flag, tmpfile) -sys.stdout.write ("Invoking `%s'\n" % cmd) +if (show_output): + sys.stdout.write ("Running bibtex on %s\n" % files) + sys.stdout.write (cmd) #And invoke it stat = os.system (cmd) if stat <> 0: - sys.exit(1) + sys.stderr.write ("Bibtex exited with nonzero exit status!") + sys.exit (1) #TODO: do tex -> itexi on output -# Following 2 lines copy tmpfile.bbl to the desired output file +# Following lines copy tmpfile.bbl to the desired output file bbl = open (tmpfile + '.bbl').read () -open (output, 'w').write (bbl) +if bbl.strip () == '': + sys.stderr.write ("Bibtex generated an empty file!") + sys.exit (1) + +fout = open (output, 'w') +fout.write (marker) +fout.write (bbl) +fout.close () def cleanup (tmpfile): for a in ['aux','bbl', 'blg']: