+def command_name (cmd):
+ # Strip all stuf after command,
+ # deal with "((latex ) >& 1 ) .." too
+ cmd = re.match ('([\(\)]*)([^\\\ ]*)', cmd).group (2)
+ return os.path.basename (cmd)
+
+def subprocess_system (cmd,
+ ignore_error=False,
+ progress_p=True,
+ be_verbose=False,
+ redirect_output=False,
+ log_file=None):
+ import subprocess
+
+ show_progress= progress_p
+ name = command_name (cmd)
+ error_log_file = ''
+
+ if redirect_output:
+ progress (_ ("Processing %s.ly") % log_file)
+ else:
+ 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
+
+ if redirect_output:
+ stderr_filename = log_file + '.log'
+ stderr_setting = open(stderr_filename, 'w')
+
+ proc = subprocess.Popen (cmd,
+ shell=True,
+ universal_newlines=True,
+ stdout=stdout_setting,
+ stderr=stderr_setting)
+
+ log = ''
+
+ if redirect_output:
+ while proc.poll()==None:
+ time.sleep(0.01)
+ retval = proc.returncode
+ stderr_setting.close()
+ else:
+ if show_progress:
+ retval = proc.wait()
+ else:
+ log = proc.communicate ()
+ retval = proc.returncode
+
+ if retval:
+ print >>sys.stderr, 'command failed:', cmd
+ if retval < 0:
+ print >>sys.stderr, "Child was terminated by signal", -retval
+ elif retval > 0:
+ print >>sys.stderr, "Child returned", retval
+
+ if ignore_error:
+ print >>sys.stderr, "Error ignored by lilylib"
+ else:
+ if not show_progress:
+ print log[0]
+ print log[1]
+ sys.exit (1)
+
+ return abs (retval)
+
+def ossystem_system (cmd,
+ ignore_error=False,
+ progress_p=True,
+ be_verbose=False,
+ redirect_output=False,
+ log_file=None):
+
+
+ name = command_name (cmd)
+ if be_verbose:
+ show_progress = 1
+ progress (_ ("Invoking `%s\'") % cmd)
+ else:
+ progress ( _("Running %s...") % name)
+
+ retval = os.system (cmd)
+ if retval:
+ print >>sys.stderr, 'command failed:', cmd
+ if retval < 0:
+ print >>sys.stderr, "Child was terminated by signal", -retval
+ elif retval > 0:
+ print >>sys.stderr, "Child returned", retval
+
+ if ignore_error:
+ print >>sys.stderr, "Error ignored"
+ else:
+ sys.exit (1)
+
+ return abs (retval)
+
+
+system = subprocess_system
+if sys.platform == 'mingw32':
+
+ ## subprocess x-compile doesn't work.
+ system = ossystem_system