]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/lilylib.py
Merge with master
[lilypond.git] / python / lilylib.py
index 10bddbb6f71167253fbcd6d43d25d0800ac28086..686993e5d87165b69c131aa33e7b1ca141eb22b8 100644 (file)
@@ -3,7 +3,7 @@
 # 
 # source file of the GNU LilyPond music typesetter
 #
-# (c) 1998--2006 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+# (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 #                 Jan Nieuwenhuizen <janneke@gnu.org>
 
 import __main__
@@ -14,14 +14,6 @@ import shutil
 import string
 import sys
 import optparse
-import subprocess
-
-## windows mingw cross compile doesn't have selectmodule.so
-have_fcntl = True
-try:
-    import fcntl
-except ImportError:
-    have_fcntl = False
 
 ################################################################
 # Users of python modules should include this snippet
@@ -60,6 +52,16 @@ except:
 underscore = _
 progress = sys.stderr.write 
 
+# Modified version of the commands.mkarg(x), which always uses 
+# double quotes (since Windows can't handle the single quotes:
+def mkarg(x):
+    s = ' "'
+    for c in x:
+        if c in '\\$"`':
+            s = s + '\\'
+        s = s + c
+    s = s + '"'
+    return s
 
 def command_name (cmd):
     # Strip all stuf after command,
@@ -67,11 +69,12 @@ def command_name (cmd):
     cmd = re.match ('([\(\)]*)([^\\\ ]*)', cmd).group (2)
     return os.path.basename (cmd)
 
-def system (cmd,
-             ignore_error=False,
-             progress_p=True,
-             be_verbose=False,
-             log_file=None):
+def subprocess_system (cmd,
+                       ignore_error=False,
+                       progress_p=True,
+                       be_verbose=False,
+                       log_file=None):
+    import subprocess
 
     show_progress= progress_p 
     name = command_name (cmd)
@@ -120,6 +123,42 @@ def system (cmd,
 
     return abs (retval)
 
+def ossystem_system (cmd,
+                     ignore_error=False,
+                     progress_p=True,
+                     be_verbose=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
+
 def strip_extension (f, ext):
     (p, e) = os.path.splitext (f)
     if e == ext:
@@ -141,7 +180,6 @@ def print_environment ():
     for (k,v) in os.environ.items ():
        sys.stderr.write ("%s=\"%s\"\n" % (k, v)) 
 
-
 class NonDentedHeadingFormatter (optparse.IndentedHelpFormatter):
     def format_heading(self, heading):
        if heading:
@@ -162,7 +200,7 @@ class NonDentedHeadingFormatter (optparse.IndentedHelpFormatter):
                               metavar)
 
     def format_usage(self, usage):
-        return _("Usage: %s\n") % usage
+        return _("Usage: %s") % usage + '\n'
 
     def format_description(self, description):
        return description