Last active
February 19, 2016 15:31
-
-
Save graphaelli/17bf248422ec17291331 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import fileinput | |
import urllib.parse | |
urllib.parse.uses_netloc.append("postgres") | |
dsn = next(fileinput.input()).strip() | |
url = urllib.parse.urlparse(dsn) | |
pgpass = "{hostname}:{port}:{database}:{username}:{password}".format( | |
database=url.path[1:], | |
username=url.username, | |
password=url.password, | |
hostname=url.hostname, | |
port=url.port | |
) | |
pgpass_dsn = "postgres://{username}@{hostname}:{port}/{database}".format( | |
database=url.path[1:], | |
username=url.username, | |
hostname=url.hostname, | |
port=url.port | |
) | |
print("""cat >> ~/.pgpass << EOF | |
{} | |
EOF""".format(pgpass) | |
) | |
print("%sql {}".format(pgpass_dsn)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment