Commit c309a882 authored by Kenneth Reitz's avatar Kenneth Reitz

python cleanups

parent 2a550b1a
...@@ -95,6 +95,7 @@ import sys ...@@ -95,6 +95,7 @@ import sys
import urlparse import urlparse
urlparse.uses_netloc.append('postgres') urlparse.uses_netloc.append('postgres')
urlparse.uses_netloc.append('mysql') urlparse.uses_netloc.append('mysql')
try: try:
# Check to make sure DATABASES is set in settings.py file. # Check to make sure DATABASES is set in settings.py file.
...@@ -103,17 +104,20 @@ try: ...@@ -103,17 +104,20 @@ try:
if 'DATABASES' not in locals(): if 'DATABASES' not in locals():
DATABASES = {} DATABASES = {}
if 'DATABASE_URL' os.environ: if 'DATABASE_URL' in os.environ:
url = urlparse.urlparse(os.environ['DATABASE_URL']) url = urlparse.urlparse(os.environ['DATABASE_URL'])
# Ensure default database exists.
DATABASES['default'] = DATABASES.get('default', {})
# We use update here to preserve other keys we # We use update here to preserve other keys we
# don't care about (like OPTIONS) # don't care about (like OPTIONS)
DATABASES['default'].update({ DATABASES['default'].update({
'NAME': url.path[1:], 'NAME': url.path[1:],
'USER': url.username, 'USER': url.username,
'PASSWORD': url.password, 'PASSWORD': url.password,
'HOST': url.hostname, 'HOST': url.hostname,
'PORT': url.port, 'PORT': url.port,
}) })
if url.scheme == 'postgres': if url.scheme == 'postgres':
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2' DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
...@@ -121,7 +125,7 @@ try: ...@@ -121,7 +125,7 @@ try:
if url.scheme == 'mysql': if url.scheme == 'mysql':
DATABASES['default']['ENGINE'] = 'django.db.backends.mysql' DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
except: except:
print "Unexpected error:", sys.exc_info() print 'Unexpected error:', sys.exc_info()
EOF EOF
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment