]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
Changed scripts/* to use sys.argv[0]
[lilypond.git] / scripts / lilypond-book.py
index d634ab693c36fff9a6679c9ebb238983dde9495e..44ba8e60ff15636d74f967c1c2b3a70483f303fc 100644 (file)
@@ -32,8 +32,6 @@ import string
 #
 # TODO:
 #
-#  * should have a sane default --process setting 
-#
 #  * use --png --ps --pdf for making images? 
 #
 
@@ -69,7 +67,7 @@ global re;re = ly.re
 
 # lilylib globals
 program_version = '@TOPLEVEL_VERSION@'
-program_name = 'lilypond-book'
+program_name = sys.argv[0]
 verbose_p = 0
 pseudo_filter_p = 0
 original_dir = os.getcwd ()
@@ -112,7 +110,7 @@ format = 0
 output_name = 0
 latex_filter_cmd = 'latex "\\nonstopmode \input /dev/stdin"'
 filter_cmd = 0
-process_cmd = lilypond_binary
+process_cmd = ''
 default_ly_options = {}
 
 #
@@ -321,7 +319,7 @@ PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
 #(set! toplevel-score-handler ly:parser-print-score)
 #(set! toplevel-music-handler (lambda (p m)
                               (ly:parser-print-score
-                               p (ly:music-scorify m))
+                               p (ly:music-scorify m p))
                            ))
 %(preamble_string)s
 \bookpaper {%(bookpaper_string)s
@@ -505,7 +503,10 @@ class Chunk:
                return self.replacement_text ()
 
 
-       def is_outdated (self):
+       def ly_is_outdated (self):
+               return 0
+
+       def png_is_outdated (self):
                return 0
 
 class Substring (Chunk):
@@ -579,7 +580,7 @@ class Lilypond_snippet (Snippet):
                open (self.basename() + '.txt', 'w').write("image of music")
                
 
-       def is_outdated (self):
+       def ly_is_outdated (self):
                base = self.basename ()
 
                tex_file = '%s.tex' % base
@@ -588,10 +589,6 @@ class Lilypond_snippet (Snippet):
                     and os.stat (tex_file)[stat.ST_SIZE] \
                     and open (tex_file).readlines ()[-1][1:-1] \
                     == 'lilypondend'
-
-               if format == HTML or format == TEXINFO:
-                       ok = ok and (os.path.exists (base + '.png')
-                                    or glob.glob (base + '-page*.png'))
                        
                if ok and (use_hash_p or self.ly () == open (ly_file).read ()):
                        # TODO: something smart with target formats
@@ -599,6 +596,14 @@ class Lilypond_snippet (Snippet):
                        return None
                return self
        
+       def png_is_outdated (self):
+               base = self.basename ()
+               ok = self.ly_is_outdated ()
+               if format == HTML or format == TEXINFO:
+                       ok = ok and (os.path.exists (base + '.png')
+                                    or glob.glob (base + '-page*.png'))
+               return not ok
+       
        def filter_text (self):
                code  = self.substring ('code')
                s = run_filter (code)
@@ -712,7 +717,7 @@ class Lilypond_snippet (Snippet):
 class Lilypond_file_snippet (Lilypond_snippet):
        def ly (self):
                name = self.substring ('filename')
-               return open (find_file (name)).read ()
+               return '\\renameinput \"%s\"\n%s' % (name, open (find_file (name)).read ())
                        
 snippet_type_to_class = {
        'lilypond_file' : Lilypond_file_snippet,
@@ -827,13 +832,15 @@ def is_derived_class (cl,  baseclass):
        return 0
 
 
-def process_snippets (cmd, snippets):
-       names = filter (lambda x: x, map (Lilypond_snippet.basename, snippets))
-       if names:
-               ly.system (string.join ([cmd] + names))
+def process_snippets (cmd, ly_snippets, png_snippets):
+       ly_names = filter (lambda x: x, map (Lilypond_snippet.basename, ly_snippets))
+       png_names = filter (lambda x: x, map (Lilypond_snippet.basename, png_snippets))
+       
+       if ly_names:
+               ly.system (string.join ([cmd] + ly_names), progress_p = 1)
 
        if format == HTML or format == TEXINFO:
-               for i in names:
+               for i in png_names:
                        if not os.path.exists (i + '.eps') and os.path.exists (i + '.tex'):
                                to_eps (i)
                                ly.make_ps_images (i + '.eps', resolution=110)
@@ -991,15 +998,18 @@ def do_file (input_filename):
                
                
        elif process_cmd:
-               outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
-                                  and x.is_outdated (), chunks)
+               ly_outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
+                                  and x.ly_is_outdated (), chunks)
+               png_outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
+                                  and x.png_is_outdated (), chunks)
+               
                ly.progress (_ ("Writing snippets..."))
-               map (Lilypond_snippet.write_ly, outdated)
+               map (Lilypond_snippet.write_ly, ly_outdated)
                ly.progress ('\n')
 
-               if outdated:
+               if ly_outdated:
                        ly.progress (_ ("Processing..."))
-                       process_snippets (process_cmd, outdated)
+                       process_snippets (process_cmd, ly_outdated, png_outdated)
                else:
                        ly.progress (_ ("All snippets are up to date..."))
                ly.progress ('\n')
@@ -1073,6 +1083,9 @@ def do_options ():
 def main ():
        files = do_options ()
        global process_cmd
+       if process_cmd == '':
+               process_cmd = lilypond_binary + " -f tex "
+       
        if process_cmd:
                process_cmd += string.join ([(' -I %s' % p)
                                             for p in include_path])