3 # lilypond.py -- Run LilyPond, add titles to bare score, generate printable
5 # Invokes: lilypond, latex (or pdflatex), dvips, ps2pdf, gs
7 # source file of the GNU LilyPond music typesetter
9 # (c) 1998--2003 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 ly2dvi 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 docstrings and "
20 # for gettextable strings.
21 # --> DO NOT 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 ly2dvi progress
60 1 = BRIEF: mute all command output, only ly2dvi progress
61 2a = NORMAL: show only LilyPond command output, show ly2dvi progress
62 2b = NORMAL: show command output, show ly2dvi 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 ## ly2dvi: silly name?
119 ## do -P or -p by default?
120 ##help_summary = _ ("Run LilyPond using LaTeX for titling")
121 help_summary = _ ("Run LilyPond, add titles, generate printable document.")
122 copyright = ('Han-Wen Nienhuys <hanwen@cs.uu.nl',
123 'Jan Nieuwenhuizen <janneke@gnu.org')
125 option_definitions = [
126 ('', 'd', 'dependencies',
127 _ ("write Makefile dependencies for every input file")),
128 ('', 'h', 'help', _ ("print this help")),
129 ('', '', 'debug', _ ("print even more output")),
130 (_ ("DIR"), 'I', 'include', _ ("add DIR to LilyPond's search path")),
132 _ ("keep all output, output to directory %s.dir") % program_name),
133 ('', '', 'no-lily', _ ("don't run LilyPond")),
134 ('', 'm', 'no-paper', _ ("produce MIDI output only")),
135 (_ ("FILE"), 'o', 'output', _ ("write output to FILE")),
136 (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")),
137 (_ ('RES'), '', 'preview-resolution',
138 _ ("set the resolution of the preview to RES")),
139 ('', 'P', 'postscript', _ ("generate PostScript output")),
140 ('', '', 'png', _("generate PNG page images")),
141 ('', '', 'psgz', _("generate PS.GZ")),
142 # separate options for PDF / PS / DVI ?
143 ('', '', 'pdftex', _ ("use pdflatex to generate a PDF output")),
144 # FIXME: preview, picture; to indicate creation of a PNG?
145 ('', '', 'preview', _ ("make a picture of the first system")),
146 ('','', 'html', _("make HTML file with links to all output")),
147 (_ ("KEY=VAL"), 's', 'set', _ ("change global setting KEY to VAL")),
148 ('', 'V', 'verbose', _ ("be verbose")),
149 ('', 'v', 'version', _ ("print version number")),
150 ('', 'w', 'warranty', _ ("show warranty and copyright")),
164 tex_extension = '.tex' ## yuk.
166 #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' }
168 lilypond_binary = os.path.join ('@bindir@', 'lilypond-bin')
170 # only use installed binary when we're installed too.
171 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
172 lilypond_binary = 'lilypond-bin'
175 layout_fields = ['dedication', 'title', 'subtitle', 'subsubtitle',
176 'footer', 'head', 'composer', 'arranger', 'instrument',
177 'opus', 'piece', 'metre', 'meter', 'poet', 'texttranslator']
180 # init to empty; values here take precedence over values in the file
182 ## TODO: change name.
186 'latexpackages' : ['geometry'],
189 'latexoptions' : ['compat2'],
199 extra_fields = extra_init.keys ()
200 fields = layout_fields + extra_fields
208 # Output formats that ly2dvi should create
209 targets = ['DVI', 'LATEX', 'MIDI', 'TEX', 'PDF', 'PS']
211 track_dependencies_p = 0
212 dependency_files = []
215 def set_setting (dict, key, val):
217 val = string.atoi (val)
219 #ly.warning (_ ("invalid value: %s") % `val`)
222 if type(val) == type ('hoi'):
224 val = string.atof (val)
226 #ly.warning (_ ("invalid value: %s") % `val`)
230 dict[key].append (val)
232 ly.warning (_ ("no such setting: `%s'") % `key`)
237 return re.sub ('([ \n\t\\\\])', r'\\\1',x)
239 def run_lilypond (files, dep_prefix):
240 def make_include_option (x):
241 return '-I %s' % escape_path (x)
244 opts = opts + ' ' + string.join (map (make_include_option, include_path))
246 opts = opts + ' --output=lelie'
248 opts = opts + ' ' + string.join (map (lambda x : '-H ' + x,
251 opts = opts + ' --no-paper'
254 opts = opts + ' -f pdftex'
256 if track_dependencies_p:
257 opts = opts + " --dependencies"
259 opts = opts + ' --dep-prefix=%s' % dep_prefix
261 fs = string.join (map (escape_path, files))
265 opts = opts + ' --verbose'
268 ly.print_environment ()
270 cmd = string.join ((lilypond_binary, opts, fs))
271 status = ly.system (cmd, ignore_error = 1, progress_p = 1)
272 signal = 0x0f & status
273 exit_status = status >> 8
275 # 2 == user interrupt.
276 if signal and signal != 2:
277 sys.stderr.write ('\n\n')
278 ly.error (_ ("LilyPond crashed (signal %d).") % signal)
279 ly.error (_ ("Please submit a bug report to bug-lilypond@gnu.org"))
283 sys.stderr.write ('\n')
285 ly.error (_ ("LilyPond failed on input file %s (exit status %d)") % (files[0], exit_status))
288 ly.error (_ ("LilyPond failed on an input file (exit status %d)") % exit_status)
289 ly.error (_ ("Continuing..."))
290 global lilypond_error_p
294 def analyse_lilypond_output (filename, extra):
297 '''Grep FILENAME for interesting stuff, and
298 put relevant info into EXTRA.'''
299 filename = filename + tex_extension
300 ly.progress (_ ("Analyzing %s...") % filename)
301 s = open (filename).read ()
303 # search only the first 10k
305 for x in extra_fields:
306 m = re.search (r'\\def\\lilypondpaper%s{([^}]*)}'%x, s)
308 set_setting (extra, x, m.group (1))
311 def find_tex_files_for_base (base, extra):
313 Find the \header fields dumped from BASE.
317 for f in layout_fields:
319 if os.path.exists (fn):
322 if os.path.exists (base +'.dep'):
323 dependency_files.append (base + '.dep')
325 for f in extra_fields:
327 if os.path.exists (fn):
328 extra[f].append (open (fn).read ())
330 return (base + tex_extension, headerfiles)
333 def find_tex_files (files, extra):
335 Find all .tex files whose prefixes start with some name in FILES.
344 fname = os.path.basename (f)
345 fname = ly.strip_extension (fname, '.ly')
347 fname = fname + '-%d' % x
349 if os.path.exists (fname + tex_extension):
350 tfiles.append (find_tex_files_for_base (fname, extra))
351 analyse_lilypond_output (fname, extra)
357 fstr = string.join (files, ', ')
358 ly.warning (_ ("no LilyPond output found for `%s'") % fstr)
361 def one_latex_definition (defn, first):
363 for (k,v) in defn[1].items ():
364 val = open (v).read ()
365 if (string.strip (val)):
366 s = s + r'''\def\lilypond%s{%s}''' % (k, val)
368 s = s + r'''\let\lilypond%s\relax''' % k
372 s = s + '\\def\\mustmakelilypondtitle{}\n'
374 s = s + '\\def\\mustmakelilypondpiecetitle{}\n'
376 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.
380 ly_paper_to_latexpaper = {
381 'letter' : 'letterpaper',
388 #TODO: should set textheight (enlarge) depending on papersize.
389 def global_latex_preamble (extra):
390 '''construct preamble from EXTRA,'''
392 s = s + '% generation tag\n'
397 if extra['papersize']:
399 options = ly_paper_to_latexpaper[extra['papersize'][0]]
401 ly.warning (_ ("invalid value: `%s'") % `extra['papersize'][0]`)
404 if extra['latexoptions']:
405 options = options + ',' + extra['latexoptions'][-1]
407 s = s + '\\documentclass[%s]{article}\n' % options
409 if extra['language']:
410 s = s + r'\usepackage[%s]{babel}' % extra['language'][-1] + '\n'
413 s = s + '\\usepackage{%s}\n' \
414 % string.join (extra['latexpackages'], ',')
416 if extra['latexheaders']:
417 s = s + '\\include{%s}\n' \
418 % string.join (extra['latexheaders'], '}\n\\include{')
420 unit = extra['unit'][-1]
423 if extra['textheight']:
424 textheight = ',textheight=%f%s' % (extra['textheight'][0], unit)
426 orientation = 'portrait'
427 if extra['orientation']:
428 orientation = extra['orientation'][0]
430 # set sane geometry width (a4-width) for linewidth = -1.
431 maxlw = max (extra['linewidth'] + [-1])
433 # who the hell is 597 ?
436 linewidth = '%d%s' % (maxlw, unit)
437 s = s + '\geometry{width=%s%s,headheight=2mm,footskip=2mm,%s}\n' % (linewidth, textheight, orientation)
440 if 'twoside' in extra['latexoptions'] :
441 s = s + '\geometry{twosideshift=4mm}\n'
444 \usepackage[latin1]{inputenc}
448 if extra['pagenumber'] and extra['pagenumber'][-1] and extra['pagenumber'][-1] != 'no':
449 s = s + '\setcounter{page}{%d}\n' % (extra['pagenumber'][-1])
450 s = s + '\\pagestyle{plain}\n'
452 s = s + '\\pagestyle{empty}\n'
458 def global_latex_definition (tfiles, extra):
459 '''construct preamble from EXTRA, dump Latex stuff for each
460 lily output file in TFILES after that, and return the Latex file constructed. '''
463 s = global_latex_preamble (extra) + '\\begin{document}\n'
464 s = s + '\\parindent 0pt\n'
465 s = s + '\\thispagestyle{firstpage}\n'
469 s = s + one_latex_definition (t, first)
473 s = s + '\\thispagestyle{lastpage}\n'
474 s = s + '\\end{document}'
478 def run_latex (files, outbase, extra):
480 '''Construct latex file, for FILES and EXTRA, dump it into
481 OUTBASE.latex. Run LaTeX on it.
488 latex_fn = outbase + '.latex'
490 wfs = find_tex_files (files, extra)
491 s = global_latex_definition (wfs, extra)
493 f = open (latex_fn, 'w')
497 cmd = latex_cmd + ' \\\\nonstopmode \\\\input %s' % latex_fn
499 # Ugh. (La)TeX writes progress and error messages on stdout
501 cmd = '(( %s >&2 ) >&- )' % cmd
502 status = ly.system (cmd, ignore_error = 1)
503 signal = 0xf & status
504 exit_status = status >> 8
510 logstr = open (outbase + '.log').read ()
511 m = re.search ("\n!", logstr)
513 logstr = logstr[start:start+200]
517 ly.error (_ ("LaTeX failed on the output file."))
518 ly.error (_ ("The error log is as follows:"))
519 sys.stderr.write (logstr + '\n')
523 # make a preview by rendering only the 1st line
525 for score in find_tex_files (files, extra):
526 preview_base = ly.strip_extension (score[0], '.tex')
527 preview_fn = preview_base + '.preview.tex'
528 s = global_latex_definition ((score,), extra)
529 s = re.sub ('thispagestyle{firstpage}',
530 r'''thispagestyle{empty}%
531 \\def\\interscoreline{\\endinput}''', s)
532 s = re.sub ('thispagestyle{lastpage}',
533 r'''thispagestyle{empty}%
534 \\def\\interscoreline{\\endinput}''', s)
535 f = open (preview_fn, 'w')
538 cmd = '%s \\\\nonstopmode \\\\input %s' \
539 % (latex_cmd, preview_fn)
543 def run_dvips (outbase, extra):
546 '''Run dvips using the correct options taken from EXTRA,
547 leaving a PS file in OUTBASE.ps
554 if extra['papersize']:
555 opts = opts + ' -t%s' % extra['papersize'][0]
557 if extra['orientation'] and extra['orientation'][0] == 'landscape':
558 opts = opts + ' -tlandscape'
562 where = ly.read_pipe ('kpsewhich feta20.pfa').strip()
567 pfa_file = open (where, 'r')
572 opts = opts + ' -Ppdf -G0 -u +lilypond.map'
574 ly.warning (_ ('''Trying create PDF, but no PFA fonts found.
575 Using bitmap fonts instead. This will look bad.'''))
577 cmd = 'dvips %s -o%s %s' % (opts, outbase + '.ps', outbase + '.dvi')
581 for score in find_tex_files (files, extra):
582 preview_base = ly.strip_extension (score[0], '.tex')
583 cmd = 'dvips -E -o%s %s' \
584 % (preview_base + '.preview.ps',
585 preview_base + '.preview.dvi')
589 cmd = 'ps2pdf %s.ps %s.pdf' % (outbase , outbase)
592 def generate_dependency_file (depfile, outname):
593 df = open (depfile, 'w')
594 df.write (outname + ':' )
596 for d in dependency_files:
598 s = re.sub ('#[^\n]*\n', '', s)
599 s = re.sub (r'\\\n', ' ', s)
600 m = re.search ('.*:(.*)\n', s)
602 # ugh. Different targets?
604 df.write ( m.group (1) + ' ' )
609 def find_file_in_path (path, name):
610 for d in string.split (path, os.pathsep):
611 if name in os.listdir (d):
612 return os.path.join (d, name)
614 # Added as functionality to ly2dvi, because ly2dvi may well need to do this
617 def find_pfa_fonts (name):
618 s = open (name).read ()
619 if s[:len (PS)] != PS:
621 ly.error (_ ("not a PostScript file: `%s\'" % name))
624 m = re.match ('.*?/(feta[-a-z0-9]+) +findfont', s[here:], re.DOTALL)
628 pfa.append (m.group (1))
629 m = re.match ('.*?/(feta[-a-z0-9]+) +findfont', s[here:], re.DOTALL)
633 def make_html_menu_file (html_file, files_found):
635 'pdf' : "Print (PDF, %s)",
636 'ps.gz' : "Print (gzipped PostScript, %s)",
637 'png' : "View (PNG, %s)",
638 'midi' : "Listen (MIDI, %s)",
639 'ly' : "View source code (%s)",
643 pages = filter (lambda x : re.search ('page[0-9]+.png', x),
645 rest = filter (lambda x : not re.search ('page[0-9]+.png', x),
648 preview = filter (lambda x: re.search ('.png$', x), rest)
650 html_str = '<img src="%s">' % preview[0]
653 page = re.sub ('.*page([0-9])+.*', 'View page \\1 (PNG picture, %s)\n', p)
654 page = page % 'unknown size'
656 html_str += '<li><a href="%s">%s</a>' % (p, page)
659 for e in ['pdf', 'ps.gz', 'midi', 'ly']:
660 fs = filter (lambda x: re.search ('.%s$' % e, x), rest)
662 entry = exts[e] % 'unknown size' # todo
663 html_str += '<li><a href="%s">%s</a>\n\n' % (f, entry)
665 html_str += "\n\n</li>"
666 ly.progress (_("Writing HTML menu `%s'") % html_file)
668 open (html_file, 'w').write (html_str)
670 ################################################################
672 ################################################################
674 (sh, long) = ly.getopt_args (option_definitions)
676 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
677 except getopt.error, s:
678 sys.stderr.write ('\n')
679 ly.error (_ ("getopt says: `%s\'" % s))
680 sys.stderr.write ('\n')
690 elif o == '--help' or o == '-h':
693 elif o == '--find-pfa' or o == '-f':
694 fonts = map (lambda x: x + '.pfa', find_pfa_fonts (a))
695 files = map (lambda x:
696 find_file_in_path (os.environ['GS_FONTPATH'], x),
698 print string.join (files, ' ')
700 elif o == '--include' or o == '-I':
701 include_path.append (a)
702 elif o == '--postscript' or o == '-P':
703 targets.append ('PS')
705 targets.remove ('PS')
706 targets.remove ('PDF')
707 elif o == '--keep' or o == '-k':
712 elif o == '--no-lily':
714 elif o == '--preview':
716 if 'PNG' not in targets:
717 targets.append ('PNG')
718 elif o == '--preview-resolution':
719 preview_resolution = string.atoi (a)
720 elif o == '--no-paper' or o == '-m':
723 elif o == '--output' or o == '-o':
725 elif o == '--set' or o == '-s':
726 ss = string.split (a, '=')
727 set_setting (extra_init, ss[0], ss[1])
728 elif o == '--dependencies' or o == '-d':
729 track_dependencies_p = 1
730 elif o == '--verbose' or o == '-V':
732 elif o == '--version' or o == '-v':
733 ly.identify (sys.stdout)
735 elif o == '--pdftex':
736 latex_cmd = 'pdflatex'
737 targets.remove('DVI')
738 targets.append('PDFTEX')
740 tex_extension = '.pdftex'
741 elif o == '--warranty' or o == '-w':
742 status = os.system ('%s -w' % lilypond_binary)
750 if 'PNG' not in targets:
751 targets.append ('PNG')
753 targets.append ('PS.GZ')
755 unimplemented_option () # signal programming error
757 # Don't convert input files to abspath, rather prepend '.' to include
759 include_path.insert (0, '.')
761 # As a neat trick, add directory part of first input file
762 # to include path. That way you can do without the clumsy -I in:
764 # ly2dvi -I foe/bar/baz foo/bar/baz/baz.ly
765 if files and files[0] != '-' and os.path.dirname (files[0]) != '.':
766 include_path.append (os.path.dirname (files[0]))
768 include_path = map (ly.abspath, include_path)
770 if files and (files[0] == '-' or output_name == '-'):
773 output_name = 'lelie'
775 ly.progress (_ ("pseudo filter") + '\n')
778 ly.error (_ ("pseudo filter only for single input file"))
783 ly.error (_ ("no files specified on command line"))
787 ly.identify (sys.stderr)
788 ly.lilypond_version_check (lilypond_binary, '@TOPLEVEL_VERSION@')
790 original_output = output_name
792 # Ugh, maybe make a setup () function
793 files = map (lambda x: ly.strip_extension (x, '.ly'), files)
795 # hmmm. Wish I'd 've written comments when I wrote this.
796 # now it looks complicated.
798 (outdir, outbase) = ('','')
800 outbase = os.path.basename (files[0])
801 outdir = ly.abspath ('.')
802 elif output_name[-1] == os.sep:
803 outdir = ly.abspath (output_name)
804 outbase = os.path.basename (files[0])
806 (outdir, outbase) = os.path.split (ly.abspath (output_name))
808 for i in ('.dvi', '.latex', '.ly', '.ps', '.tex', '.pdftex'):
809 output_name = ly.strip_extension (output_name, i)
810 outbase = ly.strip_extension (outbase, i)
812 for i in files[:] + [output_name]:
813 b = os.path.basename (i)
815 if string.find (b, ' ') >= 0:
816 ly.error (_ ("filename should not contain spaces: `%s'") %
820 if os.path.dirname (output_name) != '.':
821 dep_prefix = os.path.dirname (output_name)
825 reldir = os.path.dirname (output_name)
826 if outdir != '.' and (track_dependencies_p or targets):
827 ly.mkdir_p (outdir, 0777)
829 tmpdir = ly.setup_temp ()
830 ly.setup_environment ()
832 # to be sure, add tmpdir *in front* of inclusion path.
833 #os.environ['TEXINPUTS'] = tmpdir + ':' + os.environ['TEXINPUTS']
836 # We catch all exceptions, because we need to do stuff at exit:
837 # * copy any successfully generated stuff from tempdir and
838 # notify user of that
842 run_lilypond (files, dep_prefix)
844 ### ARGH. This also catches python programming errors.
845 ### this should only catch lilypond nonzero exit status
849 # TODO: friendly message about LilyPond setup/failing?
853 traceback.print_exc ()
855 ly.warning (_("Running LilyPond failed. Rerun with --verbose for a trace."))
857 # Our LilyPond pseudo filter always outputs to 'lelie'
858 # have subsequent stages and use 'lelie' output.
862 if 'PS.GZ' in targets:
863 targets.append ('PS')
865 if 'PNG' in targets and 'PS' not in targets:
866 targets.append ('PS')
867 if 'PS' in targets and 'DVI' not in targets:
868 targets.append('DVI')
872 run_latex (files, outbase, extra_init)
873 # unless: add --tex, or --latex?
874 targets.remove ('TEX')
875 targets.remove('LATEX')
877 # TODO: friendly message about TeX/LaTeX setup,
878 # trying to run tex/latex by hand
880 targets.remove ('DVI')
882 targets.remove ('PS')
884 traceback.print_exc ()
888 run_dvips (outbase, extra_init)
892 targets.remove ('PS')
894 traceback.print_exc ()
896 ly.warning (_("Failed to make PS file. Rerun with --verbose for a trace."))
899 for score in find_tex_files (files, extra_init):
900 preview_base = ly.strip_extension (score[0], '.tex')
901 ly.make_ps_images (preview_base + '.preview.ps',
902 resolution=preview_resolution
905 if 'PDFTEX' in targets:
907 run_latex (files, outbase, extra_init)
908 # unless: add --tex, or --latex?
909 targets.remove ('TEX')
910 targets.remove ('LATEX')
911 targets.remove ('PDFTEX')
912 if 'PDF' not in targets:
913 targets.append('PDF')
915 # TODO: friendly message about TeX/LaTeX setup,
916 # trying to run tex/latex by hand
917 if 'PDFTEX' in targets:
918 targets.remove ('PDFTEX')
920 targets.remove ('PDF')
922 targets.remove ('PS')
924 traceback.print_exc ()
926 ly.warning (_("Running LaTeX failed. Rerun with --verbose for a trace."))
929 ly.make_ps_images (outbase + '.ps' ,
930 resolution = preview_resolution
933 # add DEP to targets?
934 if track_dependencies_p:
935 depfile = os.path.join (outdir, outbase + '.dep')
936 generate_dependency_file (depfile, depfile)
937 if os.path.isfile (depfile):
938 ly.progress (_ ("dependencies output to `%s'...") %
944 for i in 'PDF', 'PS', 'PNG', 'DVI', 'LATEX':
949 ly.progress (_ ("%s output to <stdout>...") % i)
950 outname = outbase + '.' + string.lower (main_target)
951 if os.path.isfile (outname):
952 sys.stdout.write (open (outname).read ())
954 ly.warning (_ ("can't find file: `%s'") % outname)
958 if 'PS.GZ' in targets:
959 ly.system ("gzip *.ps")
960 targets.remove ('PS')
962 # Hmm, if this were a function, we could call it the except: clauses
965 ext = string.lower (i)
967 pattern = '%s.%s' % (outbase, ext)
970 ls = glob.glob (pattern)
972 ly.cp_to_dir ('.*\.%s$' % ext, outdir)
976 names = string.join (map (lambda x: "`%s'" % x, ls))
977 ly.progress (_ ("%s output to %s...") % (i, names))
980 ly.warning (_ ("can't find file: `%s.%s'") % (outbase, ext))
983 make_html_menu_file (os.path.join (outdir, outbase + ".html"),
986 os.chdir (original_dir)
989 sys.exit (lilypond_error_p)