]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/build/bib2texi.py
Merge branch 'master' into lilypond/translation
[lilypond.git] / scripts / build / bib2texi.py
index 51b7d7b6f470d6dbeb836d82ea3cbf221ed821c1..ab8a6b902be6752e2a0aedb1298c3baf3428d340 100644 (file)
@@ -6,12 +6,14 @@ import tempfile
 
 # usage:
 def usage ():
-    print 'usage: %s [-s style] [-o <outfile>] BIBFILES...'
+    print 'usage: %s [-s style] [-o <outfile>] [-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,13 +23,11 @@ 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)
 
-
-if style not in ['alpha','index','long','longp','long-pario','short','short-pario','split']:
-    sys.stderr.write ("Unknown style \`%s'\n" % style)
-
 if not files:
    usage ()
    sys.exit (2)
@@ -47,32 +47,45 @@ files = ','.join (nf)
 
 tmpfile = tempfile.mkstemp ('bib2texi')[1]
 
+#This writes a .aux file to the temporary directory.
+#The .aux file contains the commands for bibtex
+#PEH changed the bibstyle to allow a single template file in the parent directory
+#The template filename is texi-*.bst, where * defaults to 'long' but can be a parameter
 open (tmpfile + '.aux', 'w').write (r'''
 \relax
 \citation{*}
-\bibstyle{texi-%(style)s}
+\bibstyle{%(style)s}
 \bibdata{%(files)s}''' % vars ())
 
 tmpdir = tempfile.gettempdir ()
 
-cmd = "TEXMFOUTPUT=%s bibtex %s" % (tmpdir, tmpfile)
+if (show_output):
+    quiet_flag = ''
+else:
+    quiet_flag = ' -terse '
 
-sys.stdout.write ("Invoking `%s'\n" % cmd)
+#The command line to invoke bibtex
+cmd = "TEXMFOUTPUT=%s bibtex %s %s" % (tmpdir, quiet_flag, tmpfile)
+
+if (show_output):
+    sys.stdout.write ("Running bibtex on %s\n" % files)
+#And invoke it
 stat = os.system (cmd)
 if stat <> 0:
     sys.exit(1)
 
-
 #TODO: do tex -> itexi on output
-
+# Following 2 lines copy tmpfile.bbl to the desired output file
 bbl = open (tmpfile + '.bbl').read ()
 
 open (output, 'w').write  (bbl)
 
-
 def cleanup (tmpfile):
     for a in ['aux','bbl', 'blg']:
         os.unlink (tmpfile + '.' + a)
 
+
 cleanup (tmpfile)
+#Following line added by PEH - script was leaving a dangling temporary file with no extension
+os.unlink (tmpfile)