[Checkins] SVN: zc.buildout/trunk/ Switched from using os.popen* to subprocess.Popen

Tres Seaver tseaver at palladion.com
Wed Mar 4 23:39:07 EST 2009


Log message for revision 97510:
  Switched from using os.popen* to subprocess.Popen
  
  o Avoids deprecation warnings in Python 2.6.  See:
  
    http://docs.python.org/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3
  

Changed:
  U   zc.buildout/trunk/CHANGES.txt
  U   zc.buildout/trunk/src/zc/buildout/easy_install.py
  U   zc.buildout/trunk/src/zc/buildout/testing.py

-=-
Modified: zc.buildout/trunk/CHANGES.txt
===================================================================
--- zc.buildout/trunk/CHANGES.txt	2009-03-05 03:26:48 UTC (rev 97509)
+++ zc.buildout/trunk/CHANGES.txt	2009-03-05 04:39:06 UTC (rev 97510)
@@ -7,6 +7,11 @@
 1.1.2 (Unreleased)
 ==================
 
+- Switched from using os.popen* to subprocess.Popen, to avoid a deprecation
+  warning in Python 2.6.  See:
+
+  http://docs.python.org/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3
+
 - Made sure the 'redo_pyc' function and the doctest checkers work with Python
   executable paths containing spaces.
 

Modified: zc.buildout/trunk/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.py	2009-03-05 03:26:48 UTC (rev 97509)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.py	2009-03-05 04:39:06 UTC (rev 97510)
@@ -31,6 +31,7 @@
 import setuptools.command.setopt
 import setuptools.package_index
 import shutil
+import subprocess
 import sys
 import tempfile
 import urlparse
@@ -78,7 +79,14 @@
     try:
         return _versions[executable]
     except KeyError:
-        i, o = os.popen4(_safe_arg(executable) + ' -V')
+        cmd = _safe_arg(executable) + ' -V'
+        p = subprocess.Popen(cmd,
+                             shell=True,
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.STDOUT,
+                             close_fds=True)
+        i, o = (p.stdin, p.stdout)
         i.close()
         version = o.read().strip()
         o.close()

Modified: zc.buildout/trunk/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/testing.py	2009-03-05 03:26:48 UTC (rev 97509)
+++ zc.buildout/trunk/src/zc/buildout/testing.py	2009-03-05 04:39:06 UTC (rev 97510)
@@ -16,15 +16,25 @@
 $Id$
 """
 
-import BaseHTTPServer, os, random, re, shutil, socket, sys
-import tempfile, threading, time, urllib2, errno
+import BaseHTTPServer
+import errno
+import os
 import pkg_resources
+import random
+import re
+import shutil
+import socket
+import subprocess
+import sys
+import tempfile
+import threading
+import time
+import urllib2
 
 import zc.buildout.buildout
 import zc.buildout.easy_install
+from zc.buildout.rmtree import rmtree
 
-from rmtree import rmtree
-
 fsync = getattr(os, 'fsync', lambda fileno: None)
 
 setuptools_location = pkg_resources.working_set.find(
@@ -76,11 +86,17 @@
 
 
 def system(command, input=''):
-    i, o, e = os.popen3(command)
+    p = subprocess.Popen(command,
+                         shell=True,
+                         stdin=subprocess.PIPE,
+                         stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE,
+                         close_fds=True)
+    i, o, e = (p.stdin, p.stdout, p.stderr)
     if input:
         i.write(input)
     i.close()
-    result = o.read()+e.read()
+    result = o.read() + e.read()
     o.close()
     e.close()
     return result
@@ -122,21 +138,39 @@
         if os.path.exists(e):
             return e
     else:
-        i, o = os.popen4('python%s -c "import sys; print sys.executable"'
-                         % version)
+        cmd = 'python%s -c "import sys; print sys.executable"' % version
+        p = subprocess.Popen(cmd,
+                             shell=True,
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.STDOUT,
+                             close_fds=True)
+        i, o = (p.stdin, p.stdout)
         i.close()
         e = o.read().strip()
         o.close()
         if os.path.exists(e):
             return e
-        i, o = os.popen4(
-            'python -c "import sys; print \'%s.%s\' % sys.version_info[:2]"'
-            )
+        cmd = 'python -c "import sys; print \'%s.%s\' % sys.version_info[:2]"'
+        p = subprocess.Popen(cmd,
+                             shell=True,
+                             stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.STDOUT,
+                             close_fds=True)
+        i, o = (p.stdin, p.stdout)
         i.close()
         e = o.read().strip()
         o.close()
         if e == version:
-            i, o = os.popen4('python -c "import sys; print sys.executable"')
+            cmd = 'python -c "import sys; print sys.executable"'
+            p = subprocess.Popen(cmd,
+                                shell=True,
+                                stdin=subprocess.PIPE,
+                                stdout=subprocess.PIPE,
+                                stderr=subprocess.STDOUT,
+                                close_fds=True)
+            i, o = (p.stdin, p.stdout)
             i.close()
             e = o.read().strip()
             o.close()



More information about the Checkins mailing list