Author: jbronn
Date: 2009-02-01 11:52:25 -0600 (Sun, 01 Feb 2009)
New Revision: 9802

Modified:
   
django/branches/releases/1.0.X/django/contrib/gis/db/backend/postgis/creation.py
Log:
[1.0.X] Now use `subprocess.Popen` instead of the deprecated os.popen3 to issue 
PostGIS test database creation commands.

Backport of r9801 from trunk.


Modified: 
django/branches/releases/1.0.X/django/contrib/gis/db/backend/postgis/creation.py
===================================================================
--- 
django/branches/releases/1.0.X/django/contrib/gis/db/backend/postgis/creation.py
    2009-02-01 17:49:33 UTC (rev 9801)
+++ 
django/branches/releases/1.0.X/django/contrib/gis/db/backend/postgis/creation.py
    2009-02-01 17:52:25 UTC (rev 9802)
@@ -1,4 +1,5 @@
 import os, re, sys
+from subprocess import Popen, PIPE
 
 from django.conf import settings
 from django.core.management import call_command
@@ -6,12 +7,17 @@
 from django.db.backends.creation import TEST_DATABASE_PREFIX
 
 def getstatusoutput(cmd):
-    "A simpler version of getstatusoutput that works on win32 platforms."
-    stdin, stdout, stderr = os.popen3(cmd)
-    output = stdout.read()
-    if output.endswith('\n'): output = output[:-1]
-    status = stdin.close()
-    return status, output
+    """
+    Executes a shell command on the platform using subprocess.Popen and
+    return a tuple of the status and stdout output.
+    """
+    # Set stdout and stderr to PIPE because we want to capture stdout and
+    # prevent stderr from displaying.
+    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
+    # We use p.communicate() instead of p.wait() to avoid deadlocks if the
+    # output buffers exceed POSIX buffer size.
+    stdout, stderr = p.communicate()
+    return p.returncode, stdout.strip()
 
 def create_lang(db_name, verbosity=1):
     "Sets up the pl/pgsql language on the given database."


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to