db.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:abe-bootstrap 作者: TryCoin-Team 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号