Skip to content
Snippets Groups Projects
Commit f9f9ae54 authored by Kenneth Reitz's avatar Kenneth Reitz
Browse files

move django operations into separate file

parent a00b4900
No related branches found
No related tags found
No related merge requests found
......@@ -81,59 +81,6 @@ then
fi
# if Django, append settings
if [ "$NAME" = "Python/Django" ]; then
echo "-----> Django settings injection"
SETTINGS_FILE=$(ls **/settings.py | head -1)
PROJECT=$(dirname $SETTINGS_FILE)
echo "Injecting code into $SETTINGS_FILE to read from DATABASE_URL" | indent
cat >>$SETTINGS_FILE <<EOF
import os
import sys
import urlparse
# Register database schemes in URLs.
urlparse.uses_netloc.append('postgres')
urlparse.uses_netloc.append('mysql')
try:
# Check to make sure DATABASES is set in settings.py file.
# If not default to {}
if 'DATABASES' not in locals():
DATABASES = {}
if 'DATABASE_URL' in os.environ:
url = urlparse.urlparse(os.environ['DATABASE_URL'])
# Ensure default database exists.
DATABASES['default'] = DATABASES.get('default', {})
# Update with environment configuration.
DATABASES['default'].update({
'NAME': url.path[1:],
'USER': url.username,
'PASSWORD': url.password,
'HOST': url.hostname,
'PORT': url.port,
})
if url.scheme == 'postgres':
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
if url.scheme == 'mysql':
DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
except Exception:
print 'Unexpected error:', sys.exc_info()
EOF
fi
echo "-----> Activating virtualenv"
source bin/activate
......@@ -148,6 +95,12 @@ echo "-----> Installing dependencies using pip version $(bin/pip --version | awk
pip install --use-mirrors -r requirements.txt | indent
# if Django, append settings
if [ "$NAME" = "Python/Django" ]; then
source $BIN_DIR/steps/django
fi
# Make virtualenv relocatable.
set +e
OUT=$(virtualenv --relocatable .)
......
#!/usr/bin/env bash
echo "-----> Django settings injection"
SETTINGS_FILE=$(ls **/settings.py | head -1)
PROJECT=$(dirname $SETTINGS_FILE)
echo "Injecting code into $SETTINGS_FILE to read from DATABASE_URL" | indent
cat >>$SETTINGS_FILE <<EOF
import os
import sys
import urlparse
# Register database schemes in URLs.
urlparse.uses_netloc.append('postgres')
urlparse.uses_netloc.append('mysql')
try:
# Check to make sure DATABASES is set in settings.py file.
# If not default to {}
if 'DATABASES' not in locals():
DATABASES = {}
if 'DATABASE_URL' in os.environ:
url = urlparse.urlparse(os.environ['DATABASE_URL'])
# Ensure default database exists.
DATABASES['default'] = DATABASES.get('default', {})
# Update with environment configuration.
DATABASES['default'].update({
'NAME': url.path[1:],
'USER': url.username,
'PASSWORD': url.password,
'HOST': url.hostname,
'PORT': url.port,
})
if url.scheme == 'postgres':
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
if url.scheme == 'mysql':
DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
except Exception:
print 'Unexpected error:', sys.exc_info()
EOF
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment