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 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.
187 'inputencoding' : ['latin1'],
190 'latexpackages' : ['geometry'],
193 'latexoptions' : ['compat2'],
203 extra_fields = extra_init.keys ()
204 fields = layout_fields + extra_fields
212 # Output formats that lilypond should create
213 targets = ['DVI', 'LATEX', 'MIDI', 'TEX', 'PDF', 'PS']
215 track_dependencies_p = 0
216 dependency_files = []
219 def set_setting (dict, key, val):
221 val = string.atoi (val)
223 #ly.warning (_ ("invalid value: %s") % `val`)
226 if type(val) == type ('hoi'):
228 val = string.atof (val)
230 #ly.warning (_ ("invalid value: %s") % `val`)
234 dict[key].append (val)
236 ly.warning (_ ("no such setting: `%s'") % `key`)
240 def escape_shell (x):
241 return re.sub ("(\s|[`'\"\\\\])", r'\\\1',x)
244 def run_lilypond (files, dep_prefix):
245 def make_include_option (x):
246 return '-I %s' % escape_shell (x)
249 opts = opts + ' ' + string.join (map (make_include_option, include_path))
251 opts = opts + ' --output=lelie'
253 opts = opts + ' ' + string.join (map (lambda x : '-H ' + x,
256 opts = opts + ' --no-paper'
259 opts = opts + ' -f pdftex'
262 opts = opts + ' --safe-mode'
264 if track_dependencies_p:
265 opts = opts + " --dependencies"
267 opts = opts + ' --dep-prefix=%s' % dep_prefix
269 fs = string.join (map (escape_shell, files))
273 opts = opts + ' --verbose'
276 ly.print_environment ()
278 cmd = string.join ((lilypond_binary, opts, fs))
279 status = ly.system (cmd, ignore_error = 1, progress_p = 1)
280 signal = 0x0f & status
281 exit_status = status >> 8
283 # 2 == user interrupt.
284 if signal and signal != 2:
285 sys.stderr.write ('\n\n')
286 ly.error (_ ("LilyPond crashed (signal %d).") % signal)
287 ly.error (_ ("Please submit a bug report to bug-lilypond@gnu.org"))
291 global lilypond_error_p
292 sys.stderr.write ('\n')
294 ly.error (_ ("LilyPond failed on input file %s (exit status %d)") % (files[0], exit_status))
298 ly.error (_ ("LilyPond failed on an input file (exit status %d)") % exit_status)
299 ly.error (_ ("Continuing..."))
303 def analyse_lilypond_output (filename, extra):
306 '''Grep FILENAME for interesting stuff, and
307 put relevant info into EXTRA.'''
308 filename = filename + tex_extension
309 ly.progress (_ ("Analyzing %s...") % filename)
310 s = open (filename).read ()
312 # search only the first 10k
314 for x in extra_fields:
315 m = re.search (r'\\def\\lilypondpaper%s{([^}]*)}'%x, s)
317 set_setting (extra, x, m.group (1))
320 def find_tex_files_for_base (base, extra):
322 Find the \header fields dumped from BASE.
326 for f in layout_fields:
328 if os.path.exists (fn):
331 if os.path.exists (base +'.dep'):
332 dependency_files.append (base + '.dep')
334 for f in extra_fields:
336 if os.path.exists (fn):
337 extra[f].append (open (fn).read ())
339 return (base + tex_extension, headerfiles)
342 def find_tex_files (files, extra):
344 Find all .tex files whose prefixes start with some name in FILES.
353 fname = os.path.basename (f)
354 fname = ly.strip_extension (fname, '.ly')
356 fname = fname + '-%d' % x
358 if os.path.exists (fname + tex_extension):
359 tfiles.append (find_tex_files_for_base (fname, extra))
360 analyse_lilypond_output (fname, extra)
366 fstr = string.join (files, ', ')
367 ly.warning (_ ("no LilyPond output found for `%s'") % fstr)
370 def one_latex_definition (defn, first):
372 for (k,v) in defn[1].items ():
373 val = open (v).read ()
374 if (string.strip (val)):
375 s += r'''\def\lilypond%s{%s}''' % (k, val)
377 s += r'''\let\lilypond%s\relax''' % k
381 s += '\\def\\mustmakelilypondtitle{}\n'
383 s += '\\def\\mustmakelilypondpiecetitle{}\n'
385 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.
389 ly_paper_to_latexpaper = {
390 'letter' : 'letterpaper',
395 'legal' : 'legalpaper',
396 'tabloid' : 'papersize={11in,17in}',
399 #TODO: should set textheight (enlarge) depending on papersize.
400 def global_latex_preamble (extra):
401 '''construct preamble from EXTRA,'''
403 s += '% generation tag\n'
407 if extra['latexoptions']:
408 options = options + ',' + extra['latexoptions'][-1]
410 s += '\\documentclass[%s]{article}\n' % options
415 s += '\\usepackage{%s}\n' % string.join (extra['latexpackages'], ',')
417 if extra['language']:
418 s += r'\usepackage[%s]{babel}' % extra['language'][-1] + '\n'
420 if extra['fontencoding']:
421 s += '\\usepackage[%s]{fontenc}\n' % extra['fontencoding'][-1]
423 if extra['inputencoding']:
424 s += '\\usepackage[%s]{inputenc}\n' % extra['inputencoding'][-1]
426 if extra['latexheaders']:
427 s += '\\include{%s}\n' \
428 % string.join (extra['latexheaders'], '}\n\\include{')
430 unit = extra['unit'][-1]
433 if extra['papersize']:
435 papersize = ly_paper_to_latexpaper[extra['papersize'][0]] + ','
437 ly.warning (_ ("invalid value: `%s'") % `extra['papersize'][0]`)
441 if extra['textheight']:
442 textheight = ',textheight=%f%s' % (extra['textheight'][0], unit)
444 orientation = 'portrait'
445 if extra['orientation']:
446 orientation = extra['orientation'][0]
448 # set sane geometry width (a4-width) for linewidth = -1.
449 maxlw = max (extra['linewidth'] + [-1])
451 # who the hell is 597 ?
454 linewidth = '%d%s' % (maxlw, unit)
455 s += '\geometry{%swidth=%s%s,bottom=11mm,headsep=2mm,top=12mm,headheight=2mm,footskip=5mm,%s}\n' % (papersize, linewidth, textheight, orientation)
458 if 'twoside' in extra['latexoptions'] :
459 s += '\geometry{twosideshift=4mm}\n'
465 if extra['pagenumber'] and extra['pagenumber'][-1] and extra['pagenumber'][-1] != 'no':
466 s += '\setcounter{page}{%d}\n' % (extra['pagenumber'][-1])
467 s += '\\pagestyle{plain}\n'
469 s += '\\pagestyle{empty}\n'
475 def global_latex_definition (tfiles, extra):
476 '''construct preamble from EXTRA, dump Latex stuff for each
477 lily output file in TFILES after that, and return the Latex file constructed. '''
480 s = global_latex_preamble (extra) + '\\begin{document}\n'
481 s += '\\parindent 0pt\n'
482 s += '\\thispagestyle{firstpage}\n'
486 s += one_latex_definition (t, first)
490 s += '\n\\thispagestyle{lastpage}\n'
491 s += '\\end{document}'
495 def run_latex (files, outbase, extra):
497 '''Construct latex file, for FILES and EXTRA, dump it into
498 OUTBASE.latex. Run LaTeX on it.
505 latex_fn = outbase + '.latex'
507 wfs = find_tex_files (files, extra)
508 s = global_latex_definition (wfs, extra)
510 f = open (latex_fn, 'w')
514 cmd = latex_cmd + ' \\\\nonstopmode \\\\input %s' % latex_fn
516 # Ugh. (La)TeX writes progress and error messages on stdout
518 cmd = '(( %s >&2 ) >&- )' % cmd
519 status = ly.system (cmd, ignore_error = 1)
520 signal = 0xf & status
521 exit_status = status >> 8
527 logstr = open (outbase + '.log').read ()
528 m = re.search ("\n!", logstr)
530 logstr = logstr[start:start+200]
534 ly.error (_ ("LaTeX failed on the output file."))
535 ly.error (_ ("The error log is as follows:"))
536 sys.stderr.write (logstr + '\n')
540 # make a preview by rendering only the 1st line
542 for score in find_tex_files (files, extra):
543 preview_base = ly.strip_extension (score[0], '.tex')
544 preview_fn = preview_base + '.preview.tex'
545 s = global_latex_definition ((score,), extra)
546 s = re.sub ('thispagestyle{firstpage}',
547 r'''thispagestyle{empty}%
548 \\def\\interscoreline{\\endinput}''', s)
549 s = re.sub ('thispagestyle{lastpage}',
550 r'''thispagestyle{empty}%
551 \\def\\interscoreline{\\endinput}''', s)
552 f = open (preview_fn, 'w')
555 cmd = '%s \\\\nonstopmode \\\\input %s' \
556 % (latex_cmd, preview_fn)
560 def run_dvips (outbase, extra):
563 '''Run dvips using the correct options taken from EXTRA,
564 leaving a PS file in OUTBASE.ps
571 if extra['papersize']:
572 opts = opts + ' -t%s' % extra['papersize'][0]
574 if extra['orientation'] and extra['orientation'][0] == 'landscape':
575 opts = opts + ' -tlandscape'
579 where = ly.read_pipe ('kpsewhich feta20.pfa').strip()
584 pfa_file = open (where, 'r')
589 opts = opts + ' -Ppdf -G0 -u +lilypond.map'
591 ly.warning (_ ('''Trying create PDF, but no PFA fonts found.
592 Using bitmap fonts instead. This will look bad.'''))
594 cmd = 'dvips %s -o%s %s' % (opts, outbase + '.ps', outbase + '.dvi')
598 for score in find_tex_files (files, extra):
599 preview_base = ly.strip_extension (score[0], '.tex')
600 cmd = 'dvips -E -Ppdf -u+lilypond.map -o%s %s' \
601 % (preview_base + '.preview.ps',
602 preview_base + '.preview.dvi')
606 cmd = 'ps2pdf %s.ps %s.pdf' % (outbase , outbase)
609 def generate_dependency_file (depfile, outname):
610 df = open (depfile, 'w')
611 df.write (outname + ':' )
613 for d in dependency_files:
615 s = re.sub ('#[^\n]*\n', '', s)
616 s = re.sub (r'\\\n', ' ', s)
617 m = re.search ('.*:(.*)\n', s)
619 # ugh. Different targets?
621 df.write ( m.group (1) + ' ' )
626 def find_file_in_path (path, name):
627 for d in string.split (path, os.pathsep):
630 if name in os.listdir (d):
631 return os.path.join (d, name)
633 # Added as functionality to lilypond, because lilypond may well need to do this
636 def find_pfa_fonts (name):
637 s = open (name).read ()
638 if s[:len (PS)] != PS:
640 ly.error (_ ("not a PostScript file: `%s\'" % name))
643 m = re.match ('.*?/([-a-zA-Z]*(feta|parmesan)[-a-z0-9]+) +findfont', s[here:], re.DOTALL)
646 here = here + m.end (0)
647 pfa.append (m.group (1))
648 m = re.match ('.*?/([-a-zA-Z]*(feta|parmesan)[-a-z0-9]+) +findfont', s[here:], re.DOTALL)
652 def make_html_menu_file (html_file, files_found):
654 'pdf' : "Print (PDF, %s)",
655 'ps.gz' : "Print (gzipped PostScript, %s)",
656 'png' : "View (PNG, %s)",
657 'midi' : "Listen (MIDI, %s)",
658 'ly' : "View source code (%s)",
662 pages = filter (lambda x : re.search ('page[0-9]+.png', x),
664 rest = filter (lambda x : not re.search ('page[0-9]+.png', x),
667 preview = filter (lambda x: re.search ('.png$', x), rest)
669 html_str = '<img src="%s">' % preview[0]
672 page = re.sub ('.*page([0-9])+.*', 'View page \\1 (PNG picture, %s)\n', p)
673 page = page % 'unknown size'
675 html_str += '<li><a href="%s">%s</a>' % (p, page)
678 for e in ['pdf', 'ps.gz', 'midi', 'ly']:
679 fs = filter (lambda x: re.search ('.%s$' % e, x), rest)
681 entry = exts[e] % 'unknown size' # todo
682 html_str += '<li><a href="%s">%s</a>\n\n' % (f, entry)
684 html_str += "\n\n</li>"
685 ly.progress (_("Writing HTML menu `%s'") % html_file)
687 open (html_file, 'w').write (html_str)
689 ################################################################
691 ################################################################
693 (sh, long) = ly.getopt_args (option_definitions)
695 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
696 except getopt.error, s:
697 sys.stderr.write ('\n')
698 ly.error (_ ("getopt says: `%s\'" % s))
699 sys.stderr.write ('\n')
709 elif o == '--help' or o == '-h':
712 elif o == '--find-pfa' or o == '-f':
713 fonts = map (lambda x: x + '.pfa', find_pfa_fonts (a))
714 files = map (lambda x:
715 find_file_in_path (os.environ['GS_FONTPATH'], x),
717 print string.join (files, ' ')
719 elif o == '--include' or o == '-I':
720 include_path.append (a)
721 elif o == '--postscript' or o == '-P':
723 targets.remove ('PDF')
724 if 'PS' not in targets:
725 targets.append ('PS')
726 elif o == '--pdf' or o == '-p':
727 if 'PDF' not in targets:
728 targets.append ('PDF')
729 elif o == '--no-pdf':
731 targets.remove ('PDF')
734 targets.remove ('PS')
736 targets.remove ('PDF')
737 elif o == '--keep' or o == '-k':
742 elif o == '--no-lily':
744 elif o == '--preview':
746 if 'PNG' not in targets:
747 targets.append ('PNG')
748 elif o == '--preview-resolution':
749 preview_resolution = string.atoi (a)
750 elif o == '--no-paper' or o == '-m':
753 elif o == '--output' or o == '-o':
755 elif o == '--safe-mode' or o == '-s':
757 elif o == '--set' or o == '-S':
758 ss = string.split (a, '=')
759 set_setting (extra_init, ss[0], ss[1])
760 elif o == '--dependencies' or o == '-d':
761 track_dependencies_p = 1
762 elif o == '--verbose' or o == '-V':
764 elif o == '--version' or o == '-v':
765 ly.identify (sys.stdout)
767 elif o == '--pdftex':
768 latex_cmd = 'pdflatex'
769 targets.remove ('DVI')
770 targets.append ('PDFTEX')
772 tex_extension = '.pdftex'
773 elif o == '--warranty' or o == '-w':
774 status = os.system ('%s -w' % lilypond_binary)
782 if 'PNG' not in targets:
783 targets.append ('PNG')
785 unimplemented_option () # signal programming error
787 # Don't convert input files to abspath, rather prepend '.' to include
789 include_path.insert (0, '.')
791 # As a neat trick, add directory part of first input file
792 # to include path. That way you can do without the clumsy -I in:
794 # lilypond -I foe/bar/baz foo/bar/baz/baz.ly
795 if files and files[0] != '-' and os.path.dirname (files[0]) != '.':
796 include_path.append (os.path.dirname (files[0]))
798 include_path = map (ly.abspath, include_path)
800 if files and (files[0] == '-' or output_name == '-'):
803 output_name = 'lelie'
805 ly.progress (_ ("pseudo filter") + '\n')
808 ly.error (_ ("pseudo filter only for single input file"))
813 ly.error (_ ("no files specified on command line"))
817 ly.identify (sys.stderr)
818 ly.lilypond_version_check (lilypond_binary, '@TOPLEVEL_VERSION@')
820 original_output = output_name
822 # Ugh, maybe make a setup () function
823 files = map (lambda x: ly.strip_extension (x, '.ly'), files)
825 # hmmm. Wish I'd 've written comments when I wrote this.
826 # now it looks complicated.
828 (outdir, outbase) = ('','')
830 outbase = os.path.basename (files[0])
831 outdir = ly.abspath ('.')
832 elif output_name[-1] == os.sep:
833 outdir = ly.abspath (output_name)
834 outbase = os.path.basename (files[0])
836 (outdir, outbase) = os.path.split (ly.abspath (output_name))
838 for i in ('.dvi', '.latex', '.ly', '.ps', '.tex', '.pdftex'):
839 output_name = ly.strip_extension (output_name, i)
840 outbase = ly.strip_extension (outbase, i)
842 for i in files[:] + [output_name]:
843 b = os.path.basename (i)
844 if string.find (b, ' ') >= 0:
845 ly.error (_ ("filename should not contain spaces: `%s'") % b)
848 if os.path.dirname (output_name) != '.':
849 dep_prefix = os.path.dirname (output_name)
853 reldir = os.path.dirname (output_name)
854 if outdir != '.' and (track_dependencies_p or targets):
855 ly.mkdir_p (outdir, 0777)
857 tmpdir = ly.setup_temp ()
858 ly.setup_environment ()
860 os.environ['openout_any'] = 'p'
862 # to be sure, add tmpdir *in front* of inclusion path.
863 #os.environ['TEXINPUTS'] = tmpdir + ':' + os.environ['TEXINPUTS']
866 # We catch all exceptions, because we need to do stuff at exit:
867 # * copy any successfully generated stuff from tempdir and
868 # notify user of that
872 run_lilypond (files, dep_prefix)
874 ### ARGH. This also catches python programming errors.
875 ### this should only catch lilypond nonzero exit status
879 # TODO: friendly message about LilyPond setup/failing?
883 traceback.print_exc ()
885 ly.warning (_("Running LilyPond failed. Rerun with --verbose for a trace."))
887 # Our LilyPond pseudo filter always outputs to 'lelie'
888 # have subsequent stages and use 'lelie' output.
892 if 'PS.GZ' in targets:
893 targets.append ('PS')
895 if 'PNG' in targets and 'PS' not in targets:
896 targets.append ('PS')
897 if 'PS' in targets and 'DVI' not in targets:
898 targets.append('DVI')
902 run_latex (files, outbase, extra_init)
903 # unless: add --tex, or --latex?
904 targets.remove ('TEX')
905 targets.remove('LATEX')
907 # TODO: friendly message about TeX/LaTeX setup,
908 # trying to run tex/latex by hand
910 targets.remove ('DVI')
912 targets.remove ('PS')
914 traceback.print_exc ()
918 run_dvips (outbase, extra_init)
922 targets.remove ('PS')
924 traceback.print_exc ()
926 ly.warning (_("Failed to make PS file. Rerun with --verbose for a trace."))
929 for score in find_tex_files (files, extra_init):
930 preview_base = ly.strip_extension (score[0], '.tex')
931 ly.make_ps_images (preview_base + '.preview.ps',
932 resolution=preview_resolution
935 if 'PDFTEX' in targets:
937 run_latex (files, outbase, extra_init)
938 # unless: add --tex, or --latex?
939 targets.remove ('TEX')
940 targets.remove ('LATEX')
941 targets.remove ('PDFTEX')
942 if 'PDF' not in targets:
943 targets.append('PDF')
945 # TODO: friendly message about TeX/LaTeX setup,
946 # trying to run tex/latex by hand
947 if 'PDFTEX' in targets:
948 targets.remove ('PDFTEX')
950 targets.remove ('PDF')
952 targets.remove ('PS')
954 traceback.print_exc ()
956 ly.warning (_("Running LaTeX failed. Rerun with --verbose for a trace."))
959 ly.make_ps_images (outbase + '.ps' ,
960 resolution = preview_resolution
963 # add DEP to targets?
964 if track_dependencies_p:
965 depfile = os.path.join (outdir, outbase + '.dep')
966 generate_dependency_file (depfile, depfile)
967 if os.path.isfile (depfile):
968 ly.progress (_ ("dependencies output to `%s'...") %
974 for i in 'PDF', 'PS', 'PNG', 'DVI', 'LATEX':
979 ly.progress (_ ("%s output to <stdout>...") % i)
980 outname = outbase + '.' + string.lower (main_target)
981 if os.path.isfile (outname):
982 sys.stdout.write (open (outname).read ())
984 ly.warning (_ ("can't find file: `%s'") % outname)
988 if 'PS.GZ' in targets:
989 ly.system ("gzip *.ps")
990 targets.remove ('PS')
992 # Hmm, if this were a function, we could call it the except: clauses
995 ext = string.lower (i)
997 pattern = '%s.%s' % (outbase, ext)
1000 ls = glob.glob (pattern)
1002 ly.cp_to_dir ('.*\.%s$' % ext, outdir)
1006 names = string.join (map (lambda x: "`%s'" % x, ls))
1007 ly.progress (_ ("%s output to %s...") % (i, names))
1010 ly.warning (_ ("can't find file: `%s.%s'") % (outbase, ext))
1013 make_html_menu_file (os.path.join (outdir, outbase + ".html"),
1016 os.chdir (original_dir)
1019 sys.exit (lilypond_error_p)