LEFT | RIGHT |
(no file at all) | |
1 #!@PYTHON@ | 1 #!@PYTHON@ |
2 import os | 2 import os |
3 import sys | 3 import sys |
4 import getopt | 4 import getopt |
5 import tempfile | 5 import tempfile |
6 | 6 |
7 # usage: | 7 # usage: |
8 def usage (): | 8 def usage (): |
9 print 'usage: %s [-s style] [-o <outfile>] BIBFILES...' | 9 print 'usage: %s [-s style] [-o <outfile>] [-q] BIBFILES...' |
| 10 print '-q suppresses most output' |
10 | 11 |
11 (options, files) = getopt.getopt (sys.argv[1:], 's:o:', []) | 12 (options, files) = getopt.getopt (sys.argv[1:], 's:o:hq', []) |
12 | 13 |
13 output = 'bib.itexi' | 14 output = 'bib.itexi' |
14 style = 'long' | 15 style = 'long' |
| 16 suppress_output = '' |
15 | 17 |
16 for (o,a) in options: | 18 for (o,a) in options: |
17 if o == '-h' or o == '--help': | 19 if o == '-h' or o == '--help': |
18 usage () | 20 usage () |
19 sys.exit (0) | 21 sys.exit (0) |
20 elif o == '-s' or o == '--style': | 22 elif o == '-s' or o == '--style': |
21 style = a | 23 style = a |
22 elif o == '-o' or o == '--output': | 24 elif o == '-o' or o == '--output': |
23 output = a | 25 output = a |
| 26 elif o == '-q': |
| 27 suppress_output = ' -terse ' |
24 else: | 28 else: |
25 raise Exception ('unknown option: %s' % o) | 29 raise Exception ('unknown option: %s' % o) |
26 | 30 |
27 if not files: | 31 if not files: |
28 usage () | 32 usage () |
29 sys.exit (2) | 33 sys.exit (2) |
30 | 34 |
31 | 35 |
32 def strip_extension (f, ext): | 36 def strip_extension (f, ext): |
33 (p, e) = os.path.splitext (f) | 37 (p, e) = os.path.splitext (f) |
(...skipping 15 matching lines...) Expand all Loading... |
49 #The template filename is texi-*.bst, where * defaults to 'long' but can be a pa
rameter | 53 #The template filename is texi-*.bst, where * defaults to 'long' but can be a pa
rameter |
50 open (tmpfile + '.aux', 'w').write (r''' | 54 open (tmpfile + '.aux', 'w').write (r''' |
51 \relax | 55 \relax |
52 \citation{*} | 56 \citation{*} |
53 \bibstyle{%(style)s} | 57 \bibstyle{%(style)s} |
54 \bibdata{%(files)s}''' % vars ()) | 58 \bibdata{%(files)s}''' % vars ()) |
55 | 59 |
56 tmpdir = tempfile.gettempdir () | 60 tmpdir = tempfile.gettempdir () |
57 | 61 |
58 #The command line to invoke bibtex | 62 #The command line to invoke bibtex |
59 cmd = "TEXMFOUTPUT=%s bibtex %s" % (tmpdir, tmpfile) | 63 cmd = "TEXMFOUTPUT=%s bibtex %s %s" % (tmpdir, suppress_output, tmpfile) |
60 | 64 |
61 sys.stdout.write ("Invoking `%s'\n" % cmd) | 65 if (suppress_output != ' -terse '): |
| 66 sys.stdout.write ("Running bibtex on %s\n" % files) |
62 #And invoke it | 67 #And invoke it |
63 stat = os.system (cmd) | 68 stat = os.system (cmd) |
64 if stat <> 0: | 69 if stat <> 0: |
65 sys.exit(1) | 70 sys.exit(1) |
66 | 71 |
67 #TODO: do tex -> itexi on output | 72 #TODO: do tex -> itexi on output |
68 # Following 2 lines copy tmpfile.bbl to the desired output file | 73 # Following 2 lines copy tmpfile.bbl to the desired output file |
69 bbl = open (tmpfile + '.bbl').read () | 74 bbl = open (tmpfile + '.bbl').read () |
70 | 75 |
71 open (output, 'w').write (bbl) | 76 open (output, 'w').write (bbl) |
72 | 77 |
73 def cleanup (tmpfile): | 78 def cleanup (tmpfile): |
74 for a in ['aux','bbl', 'blg']: | 79 for a in ['aux','bbl', 'blg']: |
75 os.unlink (tmpfile + '.' + a) | 80 os.unlink (tmpfile + '.' + a) |
76 | 81 |
77 | 82 |
78 cleanup (tmpfile) | 83 cleanup (tmpfile) |
79 #Following line added by PEH - script was leaving a dangling temporary file with
no extension | 84 #Following line added by PEH - script was leaving a dangling temporary file with
no extension |
80 os.unlink (tmpfile) | 85 os.unlink (tmpfile) |
81 | 86 |
LEFT | RIGHT |