3 # lilypond.py -- Run LilyPond, add titles to bare score, generate printable
5 # Invokes: lilypond-bin, latex (or pdflatex), dvips, ps2pdf, gs
7 # source file of the GNU LilyPond music typesetter
9 # (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 # Jan Nieuwenhuizen <janneke@gnu.org>
12 # This is the third incarnation of ly2dvi, now renamed lilypond.
14 # Earlier incarnations of lilypond were written by
15 # Jeffrey B. Reed<daboys@austin.rr.com> (Python version)
16 # Jan Arne Fagertun <Jan.A.Fagertun@@energy.sintef.no> (Bourne shell script)
19 # Note: gettext work best if we use ' for program/docstrings and "
20 # for gettextable strings.
21 # USE ''' for docstrings.
27 * figure out which set of command line options should make lilypond:
30 na: create latex only?
31 na: create tex and latex
32 default: create dvi only
33 na: create tex, latex and dvi
40 * move versatile taglines,
43 beginfooter=\mutopiaPD
44 endfooter=\tagline -> 'lily was here <version>'
47 lilytagline (->lily was here), usertagline, copyright, lily-version
50 * head/header tagline/endfooter
52 * dvi from lilypond .tex output? This is hairy, because we create dvi
53 from lilypond .tex *and* header output.
55 * multiple \score blocks?
57 * Introduce verbosity levels
59 0 = QUIET: mute all command output, no lilypond progress
60 1 = BRIEF: mute all command output, only lilypond progress
61 2a = NORMAL: show only LilyPond command output, show lilypond progress
62 2b = NORMAL: show command output, show lilypond progress
63 3 = VERBOSE: show command output, run lilypond --verbose
64 4 = DEBUGGING: show all command output, run lilypond --verbose, print
65 environment and all kinds of client side debugging stuff
67 Currently, we only have 1 and 4, but we kludge to have 2a and 4.
76 ################################################################
77 # Users of python modules should include this snippet
78 # and customize variables below.
80 # We'll suffer this path init stuff as long as we don't install our
81 # python packages in <prefix>/lib/pythonx.y (and don't kludge around
82 # it as we do with teTeX on Red Hat Linux: set some environment var
83 # (PYTHONPATH) in profile)
85 # If set, LILYPONDPREFIX must take prevalence
86 # if datadir is not set, we're doing a build and LILYPONDPREFIX
87 import getopt, os, sys
88 datadir = '@local_lilypond_datadir@'
89 if not os.path.isdir (datadir):
90 datadir = '@lilypond_datadir@'
91 if os.environ.has_key ('LILYPONDPREFIX') :
92 datadir = os.environ['LILYPONDPREFIX']
93 while datadir[-1] == os.sep:
97 sys.path.insert (0, os.path.join (datadir, 'python'))
100 #if __name__ == '__main__':
107 program_name = 'lilypond'
108 program_version = '@TOPLEVEL_VERSION@'
111 original_dir = os.getcwd ()
112 temp_dir = os.path.join (original_dir, '%s.dir' % program_name)
114 preview_resolution = 90
118 ## do -P or -p by default?
119 ##help_summary = _ ("Run LilyPond using LaTeX for titling")
120 help_summary = _ ("Run LilyPond, add titles, generate printable document.")
121 copyright = ('Han-Wen Nienhuys <hanwen@cs.uu.nl',
122 'Jan Nieuwenhuizen <janneke@gnu.org')
124 option_definitions = [
125 ('', 'd', 'dependencies',
126 _ ("write Makefile dependencies for every input file")),
127 ('', 'h', 'help', _ ("print this help")),
128 ('', '', 'debug', _ ("print even more output")),
129 (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")),
130 ('','', 'html', _("make HTML file with links to all output")),
131 (_ ("DIR"), 'I', 'include', _ ("add DIR to LilyPond's search path")),
133 _ ("keep all output, output to directory %s.dir") % program_name),
134 ('', '', 'no-lily', _ ("don't run LilyPond")),
135 ('', 'm', 'no-paper', _ ("produce MIDI output only")),
136 (_ ("FILE"), 'o', 'output', _ ("write output to FILE")),
137 (_ ('RES'), '', 'preview-resolution',
138 _ ("set the resolution of the preview to RES")),
139 ('', '', 'no-pdf', _ ("do not generate PDF output")),
140 ('', '', 'no-ps', _ ("do not generate PostScript output")),
141 ('', 'p', 'pdf', _ ("generate PDF output")),
142 ('', 'P', 'postscript', _ ("generate PostScript output")),
143 ('', '', 'pdftex', _ ("use pdflatex to generate a PDF output")),
144 ('', '', 'png', _("generate PNG page images")),
145 ('', '', 'preview', _ ("make a picture of the first system")),
146 ('', '', 'psgz', _ ("generate PS.GZ")),
147 ('', 's', 'safe-mode', _ ("run in safe-mode")),
148 (_ ("KEY=VAL"), 'S', 'set', _ ("change global setting KEY to VAL")),
149 ('', 'V', 'verbose', _ ("be verbose")),
150 ('', 'v', 'version', _ ("print version number")),
151 ('', 'w', 'warranty', _ ("show warranty and copyright")),
166 tex_extension = '.tex' ## yuk.
168 #lilypond_binary = 'valgrind --suppressions=%(home)s/usr/src/guile-1.6.supp --num-callers=10 %(home)s/usr/src/lilypond/lily/out/lilypond '% { 'home' : '/home/hanwen' }
170 lilypond_binary = os.path.join ('@bindir@', 'lilypond-bin')
172 # only use installed binary when we're installed too.
173 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
174 lilypond_binary = 'lilypond-bin'
177 layout_fields = ['dedication', 'title', 'subtitle', 'subsubtitle',
178 'footer', 'head', 'composer', 'arranger', 'instrument',
179 'opus', 'piece', 'metre', 'meter', 'poet', 'texttranslator']
182 # init to empty; values here take precedence over values in the file
184 ## TODO: change name.
188 'latexpackages' : ['geometry'],
191 'latexoptions' : ['compat2'],
201 extra_fields = extra_init.keys ()
202 fields = layout_fields + extra_fields
210 # Output formats that lilypond should create
211 targets = ['DVI', 'LATEX', 'MIDI', 'TEX', 'PDF', 'PS']
213 track_dependencies_p = 0
214 dependency_files = []
217 def set_setting (dict, key, val):
219 val = string.atoi (val)
221 #ly.warning (_ ("invalid value: %s") % `val`)
224 if type(val) == type ('hoi'):
226 val = string.atof (val)
228 #ly.warning (_ ("invalid value: %s") % `val`)
232 dict[key].append (val)
234 ly.warning (_ ("no such setting: `%s'") % `key`)
238 def escape_shell (x):
239 return re.sub ("(\s|[`'\"\\\\])", r'\\\1',x)
242 def run_lilypond (files, dep_prefix):
243 def make_include_option (x):
244 return '-I %s' % escape_shell (x)
247 opts = opts + ' ' + string.join (map (make_include_option, include_path))
249 opts = opts + ' --output=lelie'
251 opts = opts + ' ' + string.join (map (lambda x : '-H ' + x,
254 opts = opts + ' --no-paper'
257 opts = opts + ' -f pdftex'
260 opts = opts + ' --safe-mode'
262 if track_dependencies_p:
263 opts = opts + " --dependencies"
265 opts = opts + ' --dep-prefix=%s' % dep_prefix
267 fs = string.join (map (escape_shell, files))
271 opts = opts + ' --verbose'
274 ly.print_environment ()
276 cmd = string.join ((lilypond_binary, opts, fs))
277 status = ly.system (cmd, ignore_error = 1, progress_p = 1)
278 signal = 0x0f & status
279 exit_status = status >> 8
281 # 2 == user interrupt.
282 if signal and signal != 2:
283 sys.stderr.write ('\n\n')
284 ly.error (_ ("LilyPond crashed (signal %d).") % signal)
285 ly.error (_ ("Please submit a bug report to bug-lilypond@gnu.org"))
289 sys.stderr.write ('\n')
291 ly.error (_ ("LilyPond failed on input file %s (exit status %d)") % (files[0], exit_status))
294 ly.error (_ ("LilyPond failed on an input file (exit status %d)") % exit_status)
295 ly.error (_ ("Continuing..."))
296 global lilypond_error_p
300 def analyse_lilypond_output (filename, extra):
303 '''Grep FILENAME for interesting stuff, and
304 put relevant info into EXTRA.'''
305 filename = filename + tex_extension
306 ly.progress (_ ("Analyzing %s...") % filename)
307 s = open (filename).read ()
309 # search only the first 10k
311 for x in extra_fields:
312 m = re.search (r'\\def\\lilypondpaper%s{([^}]*)}'%x, s)
314 set_setting (extra, x, m.group (1))
317 def find_tex_files_for_base (base, extra):
319 Find the \header fields dumped from BASE.
323 for f in layout_fields:
325 if os.path.exists (fn):
328 if os.path.exists (base +'.dep'):
329 dependency_files.append (base + '.dep')
331 for f in extra_fields:
333 if os.path.exists (fn):
334 extra[f].append (open (fn).read ())
336 return (base + tex_extension, headerfiles)
339 def find_tex_files (files, extra):
341 Find all .tex files whose prefixes start with some name in FILES.
350 fname = os.path.basename (f)
351 fname = ly.strip_extension (fname, '.ly')
353 fname = fname + '-%d' % x
355 if os.path.exists (fname + tex_extension):
356 tfiles.append (find_tex_files_for_base (fname, extra))
357 analyse_lilypond_output (fname, extra)
363 fstr = string.join (files, ', ')
364 ly.warning (_ ("no LilyPond output found for `%s'") % fstr)
367 def one_latex_definition (defn, first):
369 for (k,v) in defn[1].items ():
370 val = open (v).read ()
371 if (string.strip (val)):
372 s = s + r'''\def\lilypond%s{%s}''' % (k, val)
374 s = s + r'''\let\lilypond%s\relax''' % k
378 s = s + '\\def\\mustmakelilypondtitle{}\n'
380 s = s + '\\def\\mustmakelilypondpiecetitle{}\n'
382 s = s + '\\input %s\n' % defn[0] # The final \n seems important here. It ensures that the footers and taglines end up on the right page.
386 ly_paper_to_latexpaper = {
387 'letter' : 'letterpaper',
392 'legal' : 'legalpaper',
393 'tabloid' : 'papersize={11in,17in}',
396 #TODO: should set textheight (enlarge) depending on papersize.
397 def global_latex_preamble (extra):
398 '''construct preamble from EXTRA,'''
400 s = s + '% generation tag\n'
404 if extra['latexoptions']:
405 options = options + ',' + extra['latexoptions'][-1]
407 s = s + '\\documentclass[%s]{article}\n' % options
410 s = s + '\\nofiles\n'
412 if extra['language']:
413 s = s + r'\usepackage[%s]{babel}' \
414 % extra['language'][-1] + '\n'
416 s = s + '\\usepackage{%s}\n' \
417 % string.join (extra['latexpackages'], ',')
419 if extra['latexheaders']:
420 s = s + '\\include{%s}\n' \
421 % string.join (extra['latexheaders'], '}\n\\include{')
423 unit = extra['unit'][-1]
427 if extra['papersize']:
429 papersize = ly_paper_to_latexpaper[extra['papersize'][0]] + ','
431 ly.warning (_ ("invalid value: `%s'") % `extra['papersize'][0]`)
435 if extra['textheight']:
436 textheight = ',textheight=%f%s' % (extra['textheight'][0], unit)
438 orientation = 'portrait'
439 if extra['orientation']:
440 orientation = extra['orientation'][0]
442 # set sane geometry width (a4-width) for linewidth = -1.
443 maxlw = max (extra['linewidth'] + [-1])
445 # who the hell is 597 ?
448 linewidth = '%d%s' % (maxlw, unit)
449 s = s + '\geometry{%swidth=%s%s,bottom=11mm,headsep=2mm,top=12mm,headheight=2mm,footskip=5mm,%s}\n' % (papersize, linewidth, textheight, orientation)
452 if 'twoside' in extra['latexoptions'] :
453 s = s + '\geometry{twosideshift=4mm}\n'
456 \usepackage[latin1]{inputenc}
460 if extra['pagenumber'] and extra['pagenumber'][-1] and extra['pagenumber'][-1] != 'no':
461 s = s + '\setcounter{page}{%d}\n' % (extra['pagenumber'][-1])
462 s = s + '\\pagestyle{plain}\n'
464 s = s + '\\pagestyle{empty}\n'
470 def global_latex_definition (tfiles, extra):
471 '''construct preamble from EXTRA, dump Latex stuff for each
472 lily output file in TFILES after that, and return the Latex file constructed. '''
475 s = global_latex_preamble (extra) + '\\begin{document}\n'
476 s = s + '\\parindent 0pt\n'
477 s = s + '\\thispagestyle{firstpage}\n'
481 s = s + one_latex_definition (t, first)
485 s = s + '\n\\thispagestyle{lastpage}\n'
486 s = s + '\\end{document}'
490 def run_latex (files, outbase, extra):
492 '''Construct latex file, for FILES and EXTRA, dump it into
493 OUTBASE.latex. Run LaTeX on it.
500 latex_fn = outbase + '.latex'
502 wfs = find_tex_files (files, extra)
503 s = global_latex_definition (wfs, extra)
505 f = open (latex_fn, 'w')
509 cmd = latex_cmd + ' \\\\nonstopmode \\\\input %s' % latex_fn
511 # Ugh. (La)TeX writes progress and error messages on stdout
513 cmd = '(( %s >&2 ) >&- )' % cmd
514 status = ly.system (cmd, ignore_error = 1)
515 signal = 0xf & status
516 exit_status = status >> 8
522 logstr = open (outbase + '.log').read ()
523 m = re.search ("\n!", logstr)
525 logstr = logstr[start:start+200]
529 ly.error (_ ("LaTeX failed on the output file."))
530 ly.error (_ ("The error log is as follows:"))
531 sys.stderr.write (logstr + '\n')
535 # make a preview by rendering only the 1st line
537 for score in find_tex_files (files, extra):
538 preview_base = ly.strip_extension (score[0], '.tex')
539 preview_fn = preview_base + '.preview.tex'
540 s = global_latex_definition ((score,), extra)
541 s = re.sub ('thispagestyle{firstpage}',
542 r'''thispagestyle{empty}%
543 \\def\\interscoreline{\\endinput}''', s)
544 s = re.sub ('thispagestyle{lastpage}',
545 r'''thispagestyle{empty}%
546 \\def\\interscoreline{\\endinput}''', s)
547 f = open (preview_fn, 'w')
550 cmd = '%s \\\\nonstopmode \\\\input %s' \
551 % (latex_cmd, preview_fn)
555 def run_dvips (outbase, extra):
558 '''Run dvips using the correct options taken from EXTRA,
559 leaving a PS file in OUTBASE.ps
566 if extra['papersize']:
567 opts = opts + ' -t%s' % extra['papersize'][0]
569 if extra['orientation'] and extra['orientation'][0] == 'landscape':
570 opts = opts + ' -tlandscape'
574 where = ly.read_pipe ('kpsewhich feta20.pfa').strip()
579 pfa_file = open (where, 'r')
584 opts = opts + ' -Ppdf -G0 -u +lilypond.map'
586 ly.warning (_ ('''Trying create PDF, but no PFA fonts found.
587 Using bitmap fonts instead. This will look bad.'''))
589 cmd = 'dvips %s -o%s %s' % (opts, outbase + '.ps', outbase + '.dvi')
593 for score in find_tex_files (files, extra):
594 preview_base = ly.strip_extension (score[0], '.tex')
595 cmd = 'dvips -E -Ppdf -u+lilypond.map -o%s %s' \
596 % (preview_base + '.preview.ps',
597 preview_base + '.preview.dvi')
601 cmd = 'ps2pdf %s.ps %s.pdf' % (outbase , outbase)
604 def generate_dependency_file (depfile, outname):
605 df = open (depfile, 'w')
606 df.write (outname + ':' )
608 for d in dependency_files:
610 s = re.sub ('#[^\n]*\n', '', s)
611 s = re.sub (r'\\\n', ' ', s)
612 m = re.search ('.*:(.*)\n', s)
614 # ugh. Different targets?
616 df.write ( m.group (1) + ' ' )
621 def find_file_in_path (path, name):
622 for d in string.split (path, os.pathsep):
623 if name in os.listdir (d):
624 return os.path.join (d, name)
626 # Added as functionality to lilypond, because lilypond may well need to do this
629 def find_pfa_fonts (name):
630 s = open (name).read ()
631 if s[:len (PS)] != PS:
633 ly.error (_ ("not a PostScript file: `%s\'" % name))
636 m = re.match ('.*?/(feta[-a-z0-9]+) +findfont', s[here:], re.DOTALL)
640 pfa.append (m.group (1))
641 m = re.match ('.*?/(feta[-a-z0-9]+) +findfont', s[here:], re.DOTALL)
645 def make_html_menu_file (html_file, files_found):
647 'pdf' : "Print (PDF, %s)",
648 'ps.gz' : "Print (gzipped PostScript, %s)",
649 'png' : "View (PNG, %s)",
650 'midi' : "Listen (MIDI, %s)",
651 'ly' : "View source code (%s)",
655 pages = filter (lambda x : re.search ('page[0-9]+.png', x),
657 rest = filter (lambda x : not re.search ('page[0-9]+.png', x),
660 preview = filter (lambda x: re.search ('.png$', x), rest)
662 html_str = '<img src="%s">' % preview[0]
665 page = re.sub ('.*page([0-9])+.*', 'View page \\1 (PNG picture, %s)\n', p)
666 page = page % 'unknown size'
668 html_str += '<li><a href="%s">%s</a>' % (p, page)
671 for e in ['pdf', 'ps.gz', 'midi', 'ly']:
672 fs = filter (lambda x: re.search ('.%s$' % e, x), rest)
674 entry = exts[e] % 'unknown size' # todo
675 html_str += '<li><a href="%s">%s</a>\n\n' % (f, entry)
677 html_str += "\n\n</li>"
678 ly.progress (_("Writing HTML menu `%s'") % html_file)
680 open (html_file, 'w').write (html_str)
682 ################################################################
684 ################################################################
686 (sh, long) = ly.getopt_args (option_definitions)
688 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
689 except getopt.error, s:
690 sys.stderr.write ('\n')
691 ly.error (_ ("getopt says: `%s\'" % s))
692 sys.stderr.write ('\n')
702 elif o == '--help' or o == '-h':
705 elif o == '--find-pfa' or o == '-f':
706 fonts = map (lambda x: x + '.pfa', find_pfa_fonts (a))
707 files = map (lambda x:
708 find_file_in_path (os.environ['GS_FONTPATH'], x),
710 print string.join (files, ' ')
712 elif o == '--include' or o == '-I':
713 include_path.append (a)
714 elif o == '--postscript' or o == '-P':
716 targets.remove ('PDF')
717 if 'PS' not in targets:
718 targets.append ('PS')
719 elif o == '--pdf' or o == '-p':
720 if 'PDF' not in targets:
721 targets.append ('PDF')
722 elif o == '--no-pdf':
724 targets.remove ('PDF')
727 targets.remove ('PS')
729 targets.remove ('PDF')
730 elif o == '--keep' or o == '-k':
735 elif o == '--no-lily':
737 elif o == '--preview':
739 if 'PNG' not in targets:
740 targets.append ('PNG')
741 elif o == '--preview-resolution':
742 preview_resolution = string.atoi (a)
743 elif o == '--no-paper' or o == '-m':
746 elif o == '--output' or o == '-o':
748 elif o == '--safe-mode' or o == '-s':
750 elif o == '--set' or o == '-S':
751 ss = string.split (a, '=')
752 set_setting (extra_init, ss[0], ss[1])
753 elif o == '--dependencies' or o == '-d':
754 track_dependencies_p = 1
755 elif o == '--verbose' or o == '-V':
757 elif o == '--version' or o == '-v':
758 ly.identify (sys.stdout)
760 elif o == '--pdftex':
761 latex_cmd = 'pdflatex'
762 targets.remove ('DVI')
763 targets.append ('PDFTEX')
765 tex_extension = '.pdftex'
766 elif o == '--warranty' or o == '-w':
767 status = os.system ('%s -w' % lilypond_binary)
775 if 'PNG' not in targets:
776 targets.append ('PNG')
778 targets.append ('PS.GZ')
779 if 'PS' not in targets:
780 targets.append ('PS')
782 unimplemented_option () # signal programming error
784 # Don't convert input files to abspath, rather prepend '.' to include
786 include_path.insert (0, '.')
788 # As a neat trick, add directory part of first input file
789 # to include path. That way you can do without the clumsy -I in:
791 # lilypond -I foe/bar/baz foo/bar/baz/baz.ly
792 if files and files[0] != '-' and os.path.dirname (files[0]) != '.':
793 include_path.append (os.path.dirname (files[0]))
795 include_path = map (ly.abspath, include_path)
797 if files and (files[0] == '-' or output_name == '-'):
800 output_name = 'lelie'
802 ly.progress (_ ("pseudo filter") + '\n')
805 ly.error (_ ("pseudo filter only for single input file"))
810 ly.error (_ ("no files specified on command line"))
814 ly.identify (sys.stderr)
815 ly.lilypond_version_check (lilypond_binary, '@TOPLEVEL_VERSION@')
817 original_output = output_name
819 # Ugh, maybe make a setup () function
820 files = map (lambda x: ly.strip_extension (x, '.ly'), files)
822 # hmmm. Wish I'd 've written comments when I wrote this.
823 # now it looks complicated.
825 (outdir, outbase) = ('','')
827 outbase = os.path.basename (files[0])
828 outdir = ly.abspath ('.')
829 elif output_name[-1] == os.sep:
830 outdir = ly.abspath (output_name)
831 outbase = os.path.basename (files[0])
833 (outdir, outbase) = os.path.split (ly.abspath (output_name))
835 for i in ('.dvi', '.latex', '.ly', '.ps', '.tex', '.pdftex'):
836 output_name = ly.strip_extension (output_name, i)
837 outbase = ly.strip_extension (outbase, i)
839 for i in files[:] + [output_name]:
840 b = os.path.basename (i)
841 if string.find (b, ' ') >= 0:
842 ly.error (_ ("filename should not contain spaces: `%s'") % b)
845 if os.path.dirname (output_name) != '.':
846 dep_prefix = os.path.dirname (output_name)
850 reldir = os.path.dirname (output_name)
851 if outdir != '.' and (track_dependencies_p or targets):
852 ly.mkdir_p (outdir, 0777)
854 tmpdir = ly.setup_temp ()
855 ly.setup_environment ()
857 os.environ['openout_any'] = 'p'
859 # to be sure, add tmpdir *in front* of inclusion path.
860 #os.environ['TEXINPUTS'] = tmpdir + ':' + os.environ['TEXINPUTS']
863 # We catch all exceptions, because we need to do stuff at exit:
864 # * copy any successfully generated stuff from tempdir and
865 # notify user of that
869 run_lilypond (files, dep_prefix)
871 ### ARGH. This also catches python programming errors.
872 ### this should only catch lilypond nonzero exit status
876 # TODO: friendly message about LilyPond setup/failing?
880 traceback.print_exc ()
882 ly.warning (_("Running LilyPond failed. Rerun with --verbose for a trace."))
884 # Our LilyPond pseudo filter always outputs to 'lelie'
885 # have subsequent stages and use 'lelie' output.
889 if 'PS.GZ' in targets:
890 targets.append ('PS')
892 if 'PNG' in targets and 'PS' not in targets:
893 targets.append ('PS')
894 if 'PS' in targets and 'DVI' not in targets:
895 targets.append('DVI')
899 run_latex (files, outbase, extra_init)
900 # unless: add --tex, or --latex?
901 targets.remove ('TEX')
902 targets.remove('LATEX')
904 # TODO: friendly message about TeX/LaTeX setup,
905 # trying to run tex/latex by hand
907 targets.remove ('DVI')
909 targets.remove ('PS')
911 traceback.print_exc ()
915 run_dvips (outbase, extra_init)
919 targets.remove ('PS')
921 traceback.print_exc ()
923 ly.warning (_("Failed to make PS file. Rerun with --verbose for a trace."))
926 for score in find_tex_files (files, extra_init):
927 preview_base = ly.strip_extension (score[0], '.tex')
928 ly.make_ps_images (preview_base + '.preview.ps',
929 resolution=preview_resolution
932 if 'PDFTEX' in targets:
934 run_latex (files, outbase, extra_init)
935 # unless: add --tex, or --latex?
936 targets.remove ('TEX')
937 targets.remove ('LATEX')
938 targets.remove ('PDFTEX')
939 if 'PDF' not in targets:
940 targets.append('PDF')
942 # TODO: friendly message about TeX/LaTeX setup,
943 # trying to run tex/latex by hand
944 if 'PDFTEX' in targets:
945 targets.remove ('PDFTEX')
947 targets.remove ('PDF')
949 targets.remove ('PS')
951 traceback.print_exc ()
953 ly.warning (_("Running LaTeX failed. Rerun with --verbose for a trace."))
956 ly.make_ps_images (outbase + '.ps' ,
957 resolution = preview_resolution
960 # add DEP to targets?
961 if track_dependencies_p:
962 depfile = os.path.join (outdir, outbase + '.dep')
963 generate_dependency_file (depfile, depfile)
964 if os.path.isfile (depfile):
965 ly.progress (_ ("dependencies output to `%s'...") %
971 for i in 'PDF', 'PS', 'PNG', 'DVI', 'LATEX':
976 ly.progress (_ ("%s output to <stdout>...") % i)
977 outname = outbase + '.' + string.lower (main_target)
978 if os.path.isfile (outname):
979 sys.stdout.write (open (outname).read ())
981 ly.warning (_ ("can't find file: `%s'") % outname)
985 if 'PS.GZ' in targets:
986 ly.system ("gzip *.ps")
987 targets.remove ('PS')
989 # Hmm, if this were a function, we could call it the except: clauses
992 ext = string.lower (i)
994 pattern = '%s.%s' % (outbase, ext)
997 ls = glob.glob (pattern)
999 ly.cp_to_dir ('.*\.%s$' % ext, outdir)
1003 names = string.join (map (lambda x: "`%s'" % x, ls))
1004 ly.progress (_ ("%s output to %s...") % (i, names))
1007 ly.warning (_ ("can't find file: `%s.%s'") % (outbase, ext))
1010 make_html_menu_file (os.path.join (outdir, outbase + ".html"),
1013 os.chdir (original_dir)
1016 sys.exit (lilypond_error_p)