"""Wait up to 30 seconds for postgres to be available.

This is useful when running in docker, as the first time we create a
postgres volume it takes a few seconds to become ready.

"""
import time
from os import environ
import psycopg2

if __name__ == '__main__':
    elapsed = 0
    while elapsed < 30:
        try:
            psycopg2.connect(
                host=environ['DB_HOST'],
                user=environ['DB_USER'],
                password=environ['DB_PASS'],
                database=environ['DB_NAME'])
            break
        except (psycopg2.OperationalError):
            if elapsed == 0:
                print "Waiting for postgres to start..."
            time.sleep(1)
            elapsed += 1

@@ -195,30 +195,17 @@
 ime%0A
-from os import environ
+import os
 %0Aimp
@@ -217,16 +217,31 @@
 sycopg2%0A
+import dotenv%0A%0A
 %0Aif __na
@@ -260,16 +260,166 @@
 ain__':%0A
+    env_path = os.path.join(%0A        os.path.dirname(os.path.realpath(__file__)),%0A        '..', 'environment'%0A    )%0A%0A    dotenv.read_dotenv(env_path)%0A
     elap
@@ -514,16 +514,19 @@
    host=
+os.
 environ%5B
@@ -558,16 +558,19 @@
    user=
+os.
 environ%5B
@@ -606,16 +606,19 @@
 assword=
+os.
 environ%5B
@@ -654,16 +654,19 @@
 atabase=
+os.
 environ%5B

Fix bug in script that blocks Travis on postgres ready state