inject_dbs script cleanup

This commit is contained in:
Noah Zoschke
2011-05-18 07:28:47 -07:00
parent 716aa8b4a1
commit 2a7a686e9f
3 changed files with 7 additions and 152 deletions
+31
View File
@@ -0,0 +1,31 @@
##########
# BEGIN HEROKU PYTHON/DJANGO LANGUAGE PACK
# Dynamically set DATABASES from ENV vars
import os, urlparse
urlparse.uses_netloc.append("postgres")
key_re = re.compile(r"^(?P<name>[A-Z_]+)_URL$")
for k,v in os.environ.items():
url = urlparse.urlparse(v)
matches = key_re.match(k)
if not matches or url.scheme != "postgres":
continue
DATABASES[matches.group("name")] = {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": url.path[1:],
"USER": url.username,
"PASSWORD": url.password,
"HOST": url.hostname,
"PORT": url.port,
}
# alias "default" to DATABASE_URL
if DATABASES["DATABASE"]:
DATABASES["default"] = DATABASES["DATABASE"]
#
# END HEROKU PYTHON/DJANGO LANGUAGE PACK
##########