[Greater-commits] r253 - trunk/GREAT-ER-DB/impl/postgresql/test
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jun 23 12:58:52 CEST 2011
Author: aheinecke
Date: 2011-06-23 12:58:52 +0200 (Thu, 23 Jun 2011)
New Revision: 253
Modified:
trunk/GREAT-ER-DB/impl/postgresql/test/postgressupport.py
Log:
Fixes to the postgres test support so it can be used on windows
with python 2.7 and with psycop2
Modified: trunk/GREAT-ER-DB/impl/postgresql/test/postgressupport.py
===================================================================
--- trunk/GREAT-ER-DB/impl/postgresql/test/postgressupport.py 2011-06-22 16:03:34 UTC (rev 252)
+++ trunk/GREAT-ER-DB/impl/postgresql/test/postgressupport.py 2011-06-23 10:58:52 UTC (rev 253)
@@ -15,15 +15,16 @@
import os
import time
from subprocess import Popen, PIPE
+import multiprocessing
import shutil
import traceback
import support
try:
+ import psycopg2 as psycopg
+except ImportError:
import psycopg
-except ImportError:
- psycopg = None
#
# Helper code
@@ -37,6 +38,10 @@
raise RuntimeError('Command %r failed' % cmdline)
return result
+def run_detached(command, outfilename = None):
+ p = multiprocessing.Process(target=run_command, args=(command,outfilename,))
+ p.start()
+
def run_command(command, outfilename = None):
"""Run command as a subprocess and send its stdout and stderr to outfile
@@ -47,10 +52,11 @@
If outfilename is None stdout and stderr are still captured but they
are ignored and not written to any file.
"""
- proc = Popen(command, shell=True,
+ proc = Popen(command, shell=True, env=os.environ,
stdin=PIPE, stdout=PIPE, stderr=PIPE)
- output = proc.stdout.read() + proc.stderr.read()
- status = proc.wait()
+ output = proc.communicate()
+ status = proc.returncode
+ output = "".join(output)
if outfilename is not None:
outfile = open(outfilename, "w")
outfile.write(output)
@@ -146,10 +152,11 @@
run_command(["initdb", "-D", self.dbdir, "-U", self.admin_name],
os.path.join(self.dbdir, "initdb.log"))
- extra_opts = "-p %d -i" % self.port
- if self.socket_dir is not None:
- extra_opts += " -k %s" % self.socket_dir
- run_command(["pg_ctl", "-D", self.dbdir,
+ extra_opts = "-p%d " % self.port
+ # option -i removed
+ # if self.socket_dir is not None:
+ # extra_opts += " -k %s" % self.socket_dir
+ run_detached(["pg_ctl", "-D", self.dbdir,
"-l", os.path.join(self.dbdir, "logfile"),
"-o", extra_opts, "start"],
os.path.join(self.dbdir, "pg_ctl-start.log"))
@@ -205,7 +212,7 @@
def new_postgres_db(self, dbname):
"""Create and return a new PostgresDatabase object using self as server
"""
- db = PostgresDatabase(self, dbname);
+ db = PostgresDatabase(self, dbname);
db.initdb()
self.known_dbs[dbname] = db
return db
@@ -289,7 +296,8 @@
parameter must be the name of a database in the cluster.
"""
conn = psycopg.connect("dbname=%s " % dbname
- + self.connection_string(user))
+ + self.connection_string(user).replace("\\",
+ "\\\\"))
cursor = conn.cursor()
cursor.execute(sql)
conn.commit()
@@ -343,10 +351,15 @@
"-h", self.server.host, "-U", self.server.admin_name,
self.dbname],
os.path.join(self.server.dbdir, "createdb.log"))
- run_command(["createlang", "-p", str(self.server.port),
+ try:
+ run_command(["createlang", "-p", str(self.server.port),
"-h", self.server.host, "-U", self.server.admin_name,
"plpgsql", self.dbname],
os.path.join(self.server.dbdir, "createlang.log"))
+ except RuntimeError:
+ # plgpgsql might be preinstalled in which case a runtime
+ # error is thrown because the return code is != 0
+ pass
def get_connection_target(self):
return self.dbname + "@localhost:" + str(self.server.port)
@@ -442,7 +455,7 @@
_postgres_server = PostgreSQLServer(dbdir, 6544, find_postgis_sql(),
socket_dir = socket_dir)
_postgres_server.createdb()
- db = _postgres_server.new_postgres_db("static_db")
+ db = _postgres_server.new_postgres_db("static_db")
db.execute_sql_file("PostgreSQL/create_db_objects.sql", "create_db_objects.log")
db.execute_sql_file("PostgreSQL/create_system.sql", "create_system.log")
db.execute_sql_file("PostgreSQL/update_objects.sql", "update_objects.log")
More information about the Greater-commits
mailing list