diff --git a/bin/compile b/bin/compile index 11464bd67dce0cf2157da6a4def4a0c7f2b798ea..e5ea10652f2435604a62e7e2f6a0db942ab17876 100755 --- a/bin/compile +++ b/bin/compile @@ -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 .) diff --git a/bin/steps/django b/bin/steps/django new file mode 100755 index 0000000000000000000000000000000000000000..cb6dbb350ba2f2ae6e50e32d95bf4a441c546512 --- /dev/null +++ b/bin/steps/django @@ -0,0 +1,48 @@ +#!/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