Rudimentary Python 2.6 portability in the test infrastructure, fixing
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 7 Oct 2008 00:39:54 +0000 (00:39 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 7 Oct 2008 00:39:54 +0000 (00:39 +0000)
"import popen2" warnings that interfere with some of the tests executing
cleanly.  This converts to using subprocess by default, falling back
to popen2 if it's not available.

git-svn-id: http://scons.tigris.org/svn/scons/trunk@3570 fdb21ef1-2011-0410-befe-b5e4ea1792b1

QMTest/TestSCons.py
runtest.py

index c5180d89688a806691a6fce6bc3ba2c455266702..a35bf8de19c662b420d969d38db12a2d309ed160 100644 (file)
@@ -100,12 +100,19 @@ def gccFortranLibs():
     a more reliable way, but using popen3 is relatively efficient."""
 
     libs = ['g2c']
+    cmd = 'gcc -v'
 
     try:
-        import popen2
-        stderr = popen2.popen3('gcc -v')[2]
-    except OSError:
-        return libs
+        import subprocess
+    except ImportError:
+        try:
+            import popen2
+            stderr = popen2.popen3(cmd)[2]
+        except OSError:
+            return libs
+    else:
+        p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
+        stderr = p.stderr
 
     for l in stderr.readlines():
         list = string.split(l)
index 3ff68f6dcd662951a4b1b445c10d18531a6ee602..96e6dc3b233139fa1bb8c82e81eec5d52bc200de 100644 (file)
@@ -89,7 +89,6 @@ import getopt
 import glob
 import os
 import os.path
-import popen2
 import re
 import stat
 import string
@@ -345,25 +344,37 @@ class SystemExecutor(Base):
             sys.stdout.write("Unexpected exit status %d\n" % s)
 
 try:
-    popen2.Popen3
-except AttributeError:
-    class PopenExecutor(Base):
-        def execute(self):
-            (tochild, fromchild, childerr) = os.popen3(self.command_str)
-            tochild.close()
-            self.stderr = childerr.read()
-            self.stdout = fromchild.read()
-            fromchild.close()
-            self.status = childerr.close()
-            if not self.status:
-                self.status = 0
+    import subprocess
+except ImportError:
+    import popen2
+    try:
+        popen2.Popen3
+    except AttributeError:
+        class PopenExecutor(Base):
+            def execute(self):
+                (tochild, fromchild, childerr) = os.popen3(self.command_str)
+                tochild.close()
+                self.stderr = childerr.read()
+                self.stdout = fromchild.read()
+                fromchild.close()
+                self.status = childerr.close()
+                if not self.status:
+                    self.status = 0
+    else:
+        class PopenExecutor(Base):
+            def execute(self):
+                p = popen2.Popen3(self.command_str, 1)
+                p.tochild.close()
+                self.stdout = p.fromchild.read()
+                self.stderr = p.childerr.read()
+                self.status = p.wait()
 else:
     class PopenExecutor(Base):
         def execute(self):
-            p = popen2.Popen3(self.command_str, 1)
-            p.tochild.close()
-            self.stdout = p.fromchild.read()
-            self.stderr = p.childerr.read()
+            p = subprocess.Popen(self.command_str, shell=True)
+            p.stdin.close()
+            self.stdout = p.stdout.read()
+            self.stdout = p.stderr.read()
             self.status = p.wait()
 
 class Aegis(SystemExecutor):