]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-book: avoid subprocess for mingw
authorGraham Percival <graham@percival-music.ca>
Thu, 12 Jan 2012 05:57:59 +0000 (05:57 +0000)
committerGraham Percival <graham@percival-music.ca>
Sun, 15 Jan 2012 16:32:04 +0000 (16:32 +0000)
python/book_latex.py
python/book_texinfo.py

index fcd539aeaa8219eeeb5e8d07e4860e632ae31bb9..398d88c42c229b728edf9e81866934bf075758c4 100644 (file)
@@ -3,6 +3,7 @@
 import re
 import tempfile
 import os
+import sys
 import subprocess
 import book_base as BookBase
 from book_snippets import *
@@ -186,13 +187,38 @@ def get_latex_textwidth (source, global_options):
     progress (_ ("Running `%s' on file `%s' to detect default page settings.\n")
               % (global_options.latex_program, tmpfile));
     cmd = '%s %s' % (global_options.latex_program, tmpfile);
-    proc = subprocess.Popen (cmd,
-        universal_newlines=True, shell=True,
-        stdout=subprocess.PIPE, stderr=subprocess.PIPE);
-    (parameter_string, error_string) = proc.communicate ()
-    if proc.returncode != 0:
-        warning (_ ("Unable to auto-detect default page settings:\n%s")
-                 % error_string);
+    ly.debug_output ("Executing: %s\n" % cmd);
+    run_env = os.environ.copy()
+    run_env['LC_ALL:'] = 'C'
+
+    ### unknown why this is necessary
+    universal_newlines = True
+    if sys.platform == 'mingw32':
+        universal_newlines = False
+        ### use os.system to avoid weird sleep() problems on
+        ### GUB's python 2.4.2 on mingw
+        # make file to write to
+        output_dir = tempfile.mkdtemp()
+        output_filename = os.path.join(output_dir, 'output.txt')
+        # call command
+        cmd += " > %s" % output_filename
+        returncode = os.system(cmd)
+        parameter_string = open(output_filename).read()
+        if returncode != 0:
+            warning (_ ("Unable to auto-detect default settings:\n"))
+        # clean up
+        os.remove(output_filename)
+        os.rmdir(output_dir)
+    else:
+        proc = subprocess.Popen (cmd,
+            env=run_env,
+            universal_newlines=universal_newlines,
+            shell=True,
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        (parameter_string, error_string) = proc.communicate ()
+        if proc.returncode != 0:
+            warning (_ ("Unable to auto-detect default settings:\n%s")
+                    % error_string)
     os.unlink (tmpfile)
     if os.path.exists (auxfile):
         os.unlink (auxfile)
index 59a1d54e3cfbef0b03f1b8bbe011315907ebd950..6137f282731cd9d6b23b62ea4cc456983aacda56 100644 (file)
@@ -3,6 +3,7 @@
 import re
 import tempfile
 import subprocess
+import sys
 import book_base as BookBase
 from book_snippets import *
 import lilylib as ly
@@ -205,16 +206,39 @@ def get_texinfo_width_indent (source, global_options):
     progress (_ ("Running texi2pdf on file %s to detect default page settings.\n") % tmpfile);
 
     # execute the command and pipe stdout to the parameter_string:
-    cmd = 'LC_ALL=C %s -c -o %s %s' % (global_options.texinfo_program, outfile, tmpfile);
+    cmd = '%s -c -o %s %s' % (global_options.texinfo_program, outfile, tmpfile);
     ly.debug_output ("Executing: %s\n" % cmd);
-
-    proc = subprocess.Popen (cmd,
-        universal_newlines=True, shell=True,
-        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    (parameter_string, error_string) = proc.communicate ()
-    if proc.returncode != 0:
-        warning (_ ("Unable to auto-detect default settings:\n%s")
-                 % error_string)
+    run_env = os.environ.copy()
+    run_env['LC_ALL:'] = 'C'
+
+    ### unknown why this is necessary
+    universal_newlines = True
+    if sys.platform == 'mingw32':
+        universal_newlines = False
+        ### use os.system to avoid weird sleep() problems on
+        ### GUB's python 2.4.2 on mingw
+        # make file to write to
+        output_dir = tempfile.mkdtemp()
+        output_filename = os.path.join(output_dir, 'output.txt')
+        # call command
+        cmd += " > %s" % output_filename
+        returncode = os.system(cmd)
+        parameter_string = open(output_filename).read()
+        if returncode != 0:
+            warning (_ ("Unable to auto-detect default settings:\n"))
+        # clean up
+        os.remove(output_filename)
+        os.rmdir(output_dir)
+    else:
+        proc = subprocess.Popen (cmd,
+            env=run_env,
+            universal_newlines=universal_newlines,
+            shell=True,
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        (parameter_string, error_string) = proc.communicate ()
+        if proc.returncode != 0:
+            warning (_ ("Unable to auto-detect default settings:\n%s")
+                    % error_string)
     os.unlink (tmpfile)
     if os.path.exists(outfile):
         os.unlink (outfile)