]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond.py
creates LyricText objects
[lilypond.git] / scripts / lilypond.py
index dae512954f337cbf8d442df79e806b672f914d8d..025cd4df79f03e9127f906dda6f72d69cc73b00d 100644 (file)
@@ -87,6 +87,7 @@ program_version = '@TOPLEVEL_VERSION@'
 # input without \book, use classic latex definitions
 classic_p = 0
 verbose_p = 0
+latex_p = 0
 pseudo_filter_p = 0
 original_dir = os.getcwd ()
 temp_dir = os.path.join (original_dir,  '%s.dir' % program_name)
@@ -105,25 +106,25 @@ copyright = ('Han-Wen Nienhuys <hanwen@cs.uu.nl',
             'Jan Nieuwenhuizen <janneke@gnu.org')
 
 option_definitions = [
-       ('', 'd', 'dependencies',
-        _ ("write Makefile dependencies for every input file")),
        ('', 'h', 'help', _ ("print this help")),
+       ('', 'l', 'latex', _('use LaTeX for formatting')), 
        ('', '', 'debug', _ ("print even more output")),
        (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")),
-       ('','', 'html', _("make HTML file with links to all output")),
+
        (_ ("DIR"), 'I', 'include', _ ("add DIR to LilyPond's search path")),
        ('', 'k', 'keep',
         _ ("keep all output, output to directory %s.dir") % program_name),
+
+       #junkme?
        ('', '', 'no-lily', _ ("don't run LilyPond")),
+       #junkme? 
        ('', 'm', 'no-paper', _ ("produce MIDI output only")),
+       
        (_ ("FILE"), 'o', 'output', _ ("write output to FILE")),
        (_ ('RES'), '', 'preview-resolution',
         _ ("set the resolution of the preview to RES")),
-       ('', '', 'no-pdf', _ ("do not generate PDF output")),
-       ('', '', 'no-ps', _ ("do not generate PostScript output")),
        ('', 'p', 'pdf', _ ("generate PDF output")),
        ('', 'P', 'postscript', _ ("generate PostScript output")),
-       ('', '', 'pdftex', _ ("use pdflatex to generate PDF output")),
        ('', '', 'png', _("generate PNG page images")),
        ('', '', 'preview', _ ("make a picture of the first system")),
        ('', '', 'psgz', _ ("generate PS.GZ")),
@@ -138,11 +139,11 @@ option_definitions = [
 safe_mode_p = 0
 preview_p = 0
 page_images_p = 0
+
+# need global variable. sys.exit() raises an exception, which is handled
+# to do cleanups.
 lilypond_error_p = 0
-html_p = 0
 
-# Pdftex support
-pdftex_p = 0
 latex_cmd = 'latex'
 
 
@@ -172,15 +173,12 @@ extra_init = {
 header_fields = extra_init.keys ()
 
 include_path = ['.']
-lily_p = 1
 paper_p = 1
 
 output_name = ''
 
 # Output formats that lilypond should create
-targets = ['DVI', 'LATEX', 'MIDI', 'TEX', 'PDF', 'PS']
-
-track_dependencies_p = 0
+targets = ['MIDI', 'PDF', 'PS']
 dependency_files = []
 
 #what a name.
@@ -223,17 +221,13 @@ def run_lilypond (files, dep_prefix):
                                                header_fields))
        else:
                opts = opts + ' --no-paper'
-       if pdftex_p:
-               opts = opts + ' -f pdftex'              
        if safe_mode_p:
                opts = opts + ' --safe-mode'
-       if track_dependencies_p:
-               opts = opts + " --dependencies"
-               if dep_prefix:
-                       opts = opts + ' --dep-prefix=%s' % dep_prefix
 
        fs = string.join (map (escape_shell, files))
-
+       if not latex_p:
+               opts = opts + " --format=ps"
+               
        global verbose_p
        if verbose_p:
                opts = opts + ' --verbose'
@@ -254,14 +248,15 @@ def run_lilypond (files, dep_prefix):
                ly.exit (status)
                        
        if status:
+               global lilypond_error_p
                sys.stderr.write ('\n')
                if len (files) == 1:
                        ly.error (_ ("LilyPond failed on input file %s (exit status %d)") % (files[0], exit_status))
-                       ly.exit (status)
+                       lilypond_error_p = 1
+                       ly.exit (1)
                else:
                        ly.error (_ ("LilyPond failed on an input file (exit status %d)") % exit_status)
                        ly.error (_ ("Continuing..."))
-                       global lilypond_error_p
                        lilypond_error_p = 1
                
 
@@ -408,7 +403,7 @@ def global_latex_preamble (extra):
 
        # FIXME, must (only) from lilypond-bin
        s += r'''
-\usepackage[latin1]{inputenc}
+\usepackage{inputenc}
 \pagestyle{empty}
 %%PREVIEW%%'''
        
@@ -493,7 +488,10 @@ def run_dvips (outbase, extra):
 leaving a PS file in OUTBASE.ps
 '''
        #FIXME: papersize, orientation must come from lilypond-bin
-       opts = ' -t%s' % extra['papersize'][0]
+       opts = ''
+       if extra['papersize']:
+               opts = ' -t%s' % extra['papersize'][0]
+               
        if extra['orientation'] and extra['orientation'][0] == 'landscape':
                opts = opts + ' -tlandscape'
 
@@ -508,7 +506,8 @@ leaving a PS file in OUTBASE.ps
                                pass
 
                if pfa_file:
-                       opts = opts + ' -Ppdf -G0 -u +lilypond.map'
+                       #opts = opts + ' -Ppdf -G0 -u +lm.map -u +lilypond.map'
+                       opts = opts + ' -Ppdf -G0 -u +ec-mftrace.map -u +lilypond.map'
                else:
                        ly.warning (_ ('''Trying create PDF, but no PFA fonts found.
 Using bitmap fonts instead. This will look bad.'''))
@@ -519,14 +518,10 @@ Using bitmap fonts instead. This will look bad.'''))
        if preview_p:
                for score in find_tex_files (files, extra):
                        preview_base = ly.strip_extension (score[0], '.tex')
-                       cmd = 'dvips -E -Ppdf -u+lilypond.map -o%s %s' \
+                       cmd = 'dvips -E -Ppdf -u+ec-mftrace.map -u+lilypond.map -o%s %s' \
                              % (preview_base + '.preview.ps',
                                 preview_base + '.preview.dvi')
                        ly.system (cmd)
-
-       if 'PDF' in targets:
-               cmd = 'ps2pdf %s.ps %s.pdf' % (outbase , outbase)
-               ly.system (cmd)
                
 def generate_dependency_file (depfile, outname):
        df = open (depfile, 'w')
@@ -568,44 +563,6 @@ def find_pfa_fonts (name):
                m = re.match ('.*?/([-a-zA-Z]*(feta|parmesan)[-a-z0-9]+) +findfont', s[here:], re.DOTALL)
        return pfa
 
-
-def make_html_menu_file (html_file, files_found):
-       exts = {
-               'pdf' : "Print (PDF, %s)",
-               'ps.gz' : "Print (gzipped PostScript, %s)",
-               'png' : "View (PNG, %s)",
-               'midi' : "Listen (MIDI, %s)",
-               'ly' : "View source code (%s)", 
-               }
-       html_str = ''
-
-       pages = filter (lambda x : re.search ('page[0-9]+.png',  x),
-                       files_found)
-       rest =  filter (lambda x : not re.search ('page[0-9]+.png',  x),
-                       files_found)
-
-       preview = filter (lambda x: re.search ('.png$', x), rest)
-       if preview:
-               html_str = '<img src="%s">' % preview[0]
-
-       for p in pages:
-               page = re.sub ('.*page([0-9])+.*', 'View page \\1 (PNG picture, %s)\n', p)
-               page = page % 'unknown size'
-               
-               html_str += '<li><a href="%s">%s</a>' % (p, page)
-               
-               
-       for e in ['pdf', 'ps.gz', 'midi', 'ly']:
-               fs = filter (lambda x: re.search ('.%s$' % e, x), rest)
-               for f in fs:
-                       entry = exts[e] % 'unknown size' # todo
-                       html_str += '<li><a href="%s">%s</a>\n\n' % (f, entry)
-
-       html_str += "\n\n</li>"
-       ly.progress (_("Writing HTML menu `%s'") % html_file)
-       ly.progress ('\n')
-       open (html_file, 'w').write (html_str)
-       
 ################################################################
 ## MAIN
 ################################################################
@@ -638,6 +595,9 @@ for opt in options:
                sys.exit (0)
        elif o == '--include' or o == '-I':
                include_path.append (a)
+       elif o == '--latex' or o == '-l':
+               latex_p = 1
+               targets += ['DVI', 'LATEX', 'TEX']
        elif o == '--postscript' or o == '-P':
                if 'PDF' in targets:
                        targets.remove ('PDF')
@@ -646,21 +606,11 @@ for opt in options:
        elif o == '--pdf' or o == '-p':
                if 'PDF' not in targets:
                        targets.append ('PDF')
-       elif o == '--no-pdf':
-               if 'PDF' in targets:
-                       targets.remove ('PDF')
-       elif o == '--no-ps':
-               if 'PS' in targets:
-                       targets.remove ('PS')
-               if 'PDF' in targets:
-                       targets.remove ('PDF')
        elif o == '--keep' or o == '-k':
                keep_temp_dir_p = 1
        elif o == '--debug':
                verbose_p = 1
                debug_p = 1 
-       elif o == '--no-lily':
-               lily_p = 0
        elif o == '--preview':
                preview_p = 1
                if 'PNG' not in targets:
@@ -677,26 +627,16 @@ for opt in options:
        elif o == '--set' or o == '-S':
                ss = string.split (a, '=')
                set_setting (extra_init, ss[0], ss[1])
-       elif o == '--dependencies' or o == '-d':
-               track_dependencies_p = 1
        elif o == '--verbose' or o == '-V':
                verbose_p = 1
        elif o == '--version' or o == '-v':
                ly.identify (sys.stdout)
                sys.exit (0)
-       elif o == '--pdftex':
-               latex_cmd = 'pdflatex'
-               targets.remove ('DVI')
-               targets.append ('PDFTEX')
-               pdftex_p = 1
-               tex_extension = '.pdftex'
        elif o == '--warranty' or o == '-w':
                status = os.system ('%s -w' % lilypond_binary)
                if status:
                        ly.warranty ()
                sys.exit (0)
-       elif o == '--html':
-               html_p = 1
        elif o == '--png':
                page_images_p = 1
                if 'PNG' not in targets:
@@ -755,7 +695,7 @@ if 1:
        else:
                (outdir, outbase) = os.path.split (ly.abspath (output_name))
 
-       for i in ('.dvi', '.latex', '.ly', '.ps', '.tex', '.pdftex'):
+       for i in ('.dvi', '.latex', '.ly', '.ps', '.tex'):
                output_name = ly.strip_extension (output_name, i)
                outbase = ly.strip_extension (outbase, i)
 
@@ -771,7 +711,7 @@ if 1:
                dep_prefix = 0
 
        reldir = os.path.dirname (output_name)
-       if outdir != '.' and (track_dependencies_p or targets):
+       if outdir != '.' and targets:
                ly.mkdir_p (outdir, 0777)
 
        tmpdir = ly.setup_temp ()
@@ -787,23 +727,21 @@ if 1:
        #   * copy any successfully generated stuff from tempdir and
        #     notify user of that
        #   * cleanout tempdir
-       if lily_p:
-               try:
-                       run_lilypond (files, dep_prefix)
-               except:
-                       ### ARGH. This also catches python programming errors.
-                       ### this should only catch lilypond nonzero exit  status
-                       ### --hwn
+       try:
+               run_lilypond (files, dep_prefix)
+       except:
+               ### ARGH. This also catches python programming errors.
+               ### this should only catch lilypond nonzero exit  status
+               ### --hwn
+
+               # TODO: friendly message about LilyPond setup/failing?
+               #
+               targets = []
+               if verbose_p:
+                       traceback.print_exc ()
+               else:
+                       ly.warning (_("Running LilyPond failed. Rerun with --verbose for a trace."))
 
-                       
-                       # TODO: friendly message about LilyPond setup/failing?
-                       #
-                       targets = []
-                       if verbose_p:
-                               traceback.print_exc ()
-                       else:
-                               ly.warning (_("Running LilyPond failed. Rerun with --verbose for a trace."))
-                               
        # Our LilyPond pseudo filter always outputs to 'lelie'
        # have subsequent stages and use 'lelie' output.
        if pseudo_filter_p:
@@ -814,9 +752,10 @@ if 1:
                
        if 'PNG' in targets and 'PS' not in targets:
                targets.append ('PS')
-       if 'PS' in targets and 'DVI' not in targets:
+       if latex_p and 'PS' in targets and 'DVI' not in targets:
                targets.append('DVI')
 
+       
        if 'DVI' in targets:
                try:
                        run_latex (files, outbase, extra_init)
@@ -833,7 +772,7 @@ if 1:
                        if verbose_p:
                                traceback.print_exc ()
 
-       if 'PS' in targets:
+       if 'PS' in targets and "DVI" in targets:
                try:
                        run_dvips (outbase, extra_init)
                        
@@ -845,6 +784,13 @@ if 1:
                        else:
                                ly.warning (_("Failed to make PS file. Rerun with --verbose for a trace."))
 
+       
+       if 'PDF' in targets:
+               papersize = 'a4' # fixme.
+               cmd = 'ps2pdf -sPAPERSIZE=%s %s.ps %s.pdf' % (papersize, outbase , outbase)
+               ly.system (cmd)
+
+
        if preview_p:
                for score in find_tex_files (files, extra_init):
                        preview_base = ly.strip_extension (score[0], '.tex')
@@ -852,43 +798,12 @@ if 1:
                                           resolution=preview_resolution
                                           )
 
-       if 'PDFTEX' in targets:
-               try:
-                       run_latex (files, outbase, extra_init)
-                       # unless: add --tex, or --latex?
-                       targets.remove ('TEX')
-                       targets.remove ('LATEX')
-                       targets.remove ('PDFTEX')
-                       if 'PDF' not in targets:
-                               targets.append('PDF')
-               except:
-                       # TODO: friendly message about TeX/LaTeX setup,
-                       # trying to run tex/latex by hand
-                       if 'PDFTEX' in targets:
-                               targets.remove ('PDFTEX')
-                       if 'PDF' in targets:
-                               targets.remove ('PDF')
-                       if 'PS' in targets:
-                               targets.remove ('PS')
-                       if verbose_p:
-                               traceback.print_exc ()
-                       else:
-                               ly.warning (_("Running LaTeX failed. Rerun with --verbose for a trace."))
-                               
+                       
        if page_images_p:
                ly.make_ps_images (outbase + '.ps' ,
                                   resolution = preview_resolution
                                   )
 
-       # add DEP to targets?
-       if track_dependencies_p:
-               depfile = os.path.join (outdir, outbase + '.dep')
-               generate_dependency_file (depfile, depfile)
-               if os.path.isfile (depfile):
-                       ly.progress (_ ("dependencies output to `%s'...") %
-                                    depfile)
-                       ly.progress ('\n')
-
        if pseudo_filter_p:
                main_target = 0
                for i in 'PDF', 'PS', 'PNG', 'DVI', 'LATEX':
@@ -929,9 +844,6 @@ if 1:
                elif verbose_p:
                        ly.warning (_ ("can't find file: `%s.%s'") % (outbase, ext))
 
-       if html_p:
-               make_html_menu_file (os.path.join (outdir, outbase + ".html"),
-                                    files_found)
 
        os.chdir (original_dir)
        ly.cleanup_temp ()