Now use `subprocess.Popen` instead of the deprecated os.popen3 to issue PostGIS test database creation commands.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9801 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2009-02-01 17:49:33 +00:00
parent c08e0ef649
commit d982edff4b
1 changed files with 12 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import os, re, sys import os, re, sys
from subprocess import Popen, PIPE
from django.conf import settings from django.conf import settings
from django.core.management import call_command from django.core.management import call_command
@ -6,12 +7,17 @@ from django.db import connection
from django.db.backends.creation import TEST_DATABASE_PREFIX from django.db.backends.creation import TEST_DATABASE_PREFIX
def getstatusoutput(cmd): def getstatusoutput(cmd):
"A simpler version of getstatusoutput that works on win32 platforms." """
stdin, stdout, stderr = os.popen3(cmd) Executes a shell command on the platform using subprocess.Popen and
output = stdout.read() return a tuple of the status and stdout output.
if output.endswith('\n'): output = output[:-1] """
status = stdin.close() # Set stdout and stderr to PIPE because we want to capture stdout and
return status, output # 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): def create_lang(db_name, verbosity=1):
"Sets up the pl/pgsql language on the given database." "Sets up the pl/pgsql language on the given database."