From f9f9ae54fa20bc3a5432326e9563057077d59c8b Mon Sep 17 00:00:00 2001
From: Kenneth Reitz <me@kennethreitz.com>
Date: Wed, 18 Jan 2012 12:24:35 -0500
Subject: [PATCH] move django operations into separate file

---
 bin/compile      | 59 +++++-------------------------------------------
 bin/steps/django | 48 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 53 deletions(-)
 create mode 100755 bin/steps/django

diff --git a/bin/compile b/bin/compile
index 11464bd6..e5ea1065 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 00000000..cb6dbb35
--- /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
-- 
GitLab