def install_server(db):
db.bindir = subprocess.Popen(['pg_config', '--bindir'], stdout=subprocess.PIPE).communicate()[0].rstrip()
subprocess.check_call([
os.path.join(db.bindir, 'initdb'),
'-D', str(db.installation_dir),
'-U', 'postgres'])
server = subprocess.Popen([
os.path.join(db.bindir, 'postgres'),
'-D', str(db.installation_dir),
'-c', 'listen_addresses=',
'-c', 'unix_socket_directory=.'])
import time, psycopg2
tries = 30
for t in range(tries):
try:
with db.root() as cur:
cur.execute("COMMIT") # XXX
cur.execute("CREATE USER abe UNENCRYPTED PASSWORD 'Bitcoin'")
cur.execute("COMMIT")
return server
except psycopg2.OperationalError as e:
if t+1 == tries:
raise e
time.sleep(1)
评论列表
文章目录