@@ 4,24 4,27 @@ import subprocess
from pathlib import Path
+def pcall(cmd, args, env=None):
+ try:
+ return subprocess.check_call([cmd] + args, env=env)
+ except OSError:
+ raise OSError('command %r failed, it it in your PATH ?' % cmd)
+
+
def setup_local_pg_cluster(request, datadir, pgport):
" create (if missing) a local cluster to use for the tests "
dbpath = Path(datadir, 'pgdb')
if not dbpath.exists():
- subprocess.check_call(['initdb', '-D', dbpath.as_posix(),
- '-E', 'utf-8', '--locale=C'])
+ pcall('initdb', ['-D', dbpath.as_posix(), '-E', 'utf-8', '--locale=C'])
env = os.environ.copy()
sockdir = tempfile.mkdtemp(prefix='pgsocket')
options = '-k %s -p %s' % (sockdir, pgport)
options += ' -c fsync=off -c full_page_writes=off'
options += ' -c synchronous_commit=off'
- subprocess.check_call(['pg_ctl', 'start', '-w', '-D', dbpath.as_posix(),
- '-o', options],
- env=env)
+ pcall('pg_ctl', ['start', '-w', '-D', dbpath.as_posix(), '-o', options], env=env)
def shutdown_postgres():
- subprocess.call(['pg_ctl', 'stop', '-D', dbpath.as_posix(),
- '-m', 'fast'])
+ pcall('pg_ctl', ['stop', '-D', dbpath.as_posix(), '-m', 'fast'])
try:
os.rmdir(sockdir)
except OSError: