]> git.donarmstrong.com Git - lilypond.git/commitdiff
Adds redirect-lilypond-output option to book
authorPhil Holmes <mail@philholmes.net>
Fri, 1 Jul 2011 15:07:04 +0000 (16:07 +0100)
committerGraham Percival <graham@percival-music.ca>
Fri, 15 Jul 2011 18:43:34 +0000 (11:43 -0700)
Adds a new option to lilypond-book that causes the lilypond
output to be directed to logifles.  The option is:
--redirect-lilypond-output

python/lilylib.py
scripts/lilypond-book.py

index dac53c16cf4dd5d83c2111e4ba49e28701f410b0..c3eb98bc6fda38f815b5bc9ebf8d41f91dd46a85 100644 (file)
@@ -23,6 +23,7 @@ import re
 import shutil
 import sys
 import optparse
+import time
 
 ################################################################
 # Users of python modules should include this snippet
@@ -118,6 +119,7 @@ def subprocess_system (cmd,
                        ignore_error=False,
                        progress_p=True,
                        be_verbose=False,
+                       redirect_output=False,
                        log_file=None):
     import subprocess
 
@@ -125,31 +127,46 @@ def subprocess_system (cmd,
     name = command_name (cmd)
     error_log_file = ''
 
-    if be_verbose:
-       show_progress = 1
-       progress (_ ("Invoking `%s\'") % cmd)
+    if redirect_output:
+        progress (_ ("Processing %s.ly") % log_file)
     else:
-       progress ( _("Running %s...") % name)
-
+        if be_verbose:
+            show_progress = 1
+            progress (_ ("Invoking `%s\'") % cmd)
+        else:
+            progress ( _("Running %s...") % name)
 
     stdout_setting = None
+    stderr_setting = None
     if not show_progress:
-       stdout_setting = subprocess.PIPE
+        stdout_setting = subprocess.PIPE
+
+    if redirect_output:
+        stdout_filename = ' '.join([log_file, '.log'])
+        stderr_filename = ' '.join([log_file, '.err.log'])
+        stdout_setting = open(stdout_filename, 'w')
+        stderr_setting = open(stderr_filename, 'w')
 
     proc = subprocess.Popen (cmd,
                              shell=True,
                              universal_newlines=True,
                              stdout=stdout_setting,
-                             stderr=stdout_setting)
+                             stderr=stderr_setting)
 
     log = ''
 
-    if show_progress:
-       retval = proc.wait()
+    if redirect_output:
+        while proc.poll()==None:
+            time.sleep(1)
+        retval = proc.returncode
+        stdout_setting.close()
+        stderr_setting.close()
     else:
-       log = proc.communicate ()
-       retval = proc.returncode
-
+        if show_progress:
+            retval = proc.wait()
+        else:
+            log = proc.communicate ()
+            retval = proc.returncode
 
     if retval:
         print >>sys.stderr, 'command failed:', cmd
index 9617f3666d3a4c878325a089b3d898def9771a8d..cb3ff4de3269861c09f0e5d83bb46a2bbdd39ca4 100644 (file)
@@ -179,6 +179,11 @@ def get_option_parser ():
                   action='store',
                   dest='process_cmd', default='')
 
+    p.add_option ('--redirect-lilypond-output',
+                  help = _ ("Redirect the lilypond output"),
+                  action='store_true',
+                  dest='redirect_output', default=False)
+
     p.add_option ('-s', '--safe', help=_ ("Compile snippets in safe mode"),
                   action="store_true",
                   default=False,
@@ -347,7 +352,7 @@ def find_toplevel_snippets (input_string, formatter):
 
     return snippets
 
-def system_in_directory (cmd, directory):
+def system_in_directory (cmd, directory, logfile):
     """Execute a command in a different directory.
 
     Because of win32 compatibility, we can't simply use subprocess.
@@ -355,7 +360,10 @@ def system_in_directory (cmd, directory):
 
     current = os.getcwd()
     os.chdir (directory)
-    ly.system(cmd, be_verbose=global_options.verbose,
+    ly.system(cmd,
+              be_verbose=global_options.verbose,
+              redirect_output=global_options.redirect_output,
+              log_file=logfile,
               progress_p=1)
     os.chdir (current)
 
@@ -374,11 +382,12 @@ def process_snippets (cmd, snippets,
                           + list (set ([snip.basename() + '.ly' for snip in snippets])))
     name = os.path.join (lily_output_dir,
                          'snippet-names-%d.ly' % checksum)
+    logfile = name.replace('.ly', '')
     file (name, 'wb').write (contents)
 
     system_in_directory (' '.join ([cmd, ly.mkarg (name)]),
-                         lily_output_dir)
-
+                         lily_output_dir,
+                         logfile)
 
 def snippet_list_checksum (snippets):
     return hash (' '.join([l.basename() for l in snippets]))