Adds a new option to lilypond-book that causes the lilypond
output to be directed to logifles. The option is:
--redirect-lilypond-output
import shutil
import sys
import optparse
import shutil
import sys
import optparse
################################################################
# Users of python modules should include this snippet
################################################################
# Users of python modules should include this snippet
ignore_error=False,
progress_p=True,
be_verbose=False,
ignore_error=False,
progress_p=True,
be_verbose=False,
log_file=None):
import subprocess
log_file=None):
import subprocess
name = command_name (cmd)
error_log_file = ''
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)
- progress ( _("Running %s...") % name)
-
+ if be_verbose:
+ show_progress = 1
+ progress (_ ("Invoking `%s\'") % cmd)
+ else:
+ progress ( _("Running %s...") % name)
- 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,
proc = subprocess.Popen (cmd,
shell=True,
universal_newlines=True,
stdout=stdout_setting,
- 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()
- 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
if retval:
print >>sys.stderr, 'command failed:', cmd
action='store',
dest='process_cmd', default='')
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,
p.add_option ('-s', '--safe', help=_ ("Compile snippets in safe mode"),
action="store_true",
default=False,
-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.
"""Execute a command in a different directory.
Because of win32 compatibility, we can't simply use subprocess.
current = os.getcwd()
os.chdir (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)
progress_p=1)
os.chdir (current)
+ list (set ([snip.basename() + '.ly' for snip in snippets])))
name = os.path.join (lily_output_dir,
'snippet-names-%d.ly' % checksum)
+ 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)]),
file (name, 'wb').write (contents)
system_in_directory (' '.join ([cmd, ly.mkarg (name)]),
+ lily_output_dir,
+ logfile)
def snippet_list_checksum (snippets):
return hash (' '.join([l.basename() for l in snippets]))
def snippet_list_checksum (snippets):
return hash (' '.join([l.basename() for l in snippets]))