summaryrefslogtreecommitdiffstats
path: root/lib/toaster/toastermain/settings.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/toaster/toastermain/settings.py')
-rw-r--r--lib/toaster/toastermain/settings.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/toaster/toastermain/settings.py b/lib/toaster/toastermain/settings.py
index 2c52b6888..2ce10c474 100644
--- a/lib/toaster/toastermain/settings.py
+++ b/lib/toaster/toastermain/settings.py
@@ -74,6 +74,25 @@ if 'DATABASE_URL' in os.environ:
else:
raise Exception("FIXME: Please implement missing database url schema for url: %s" % dburl)
+
+# Allows current database settings to be exported as a DATABASE_URL environment variable value
+
+def getDATABASE_URL():
+ d = DATABASES['default']
+ if d['ENGINE'] == 'django.db.backends.sqlite3':
+ if d['NAME'] == ':memory:':
+ return 'sqlite3://:memory:'
+ elif d['NAME'].startswith("/"):
+ return 'sqlite3://' + d['NAME']
+ return "sqlite3://" + os.path.join(os.getcwd(), d['NAME'])
+
+ elif d['ENGINE'] == 'django.db.backends.mysql':
+ return "mysql://" + d['USER'] + ":" + d['PASSWORD'] + "@" + d['HOST'] + ":" + d['PORT'] + "/" + d['NAME']
+
+ raise Exception("FIXME: Please implement missing database url schema for engine: %s" % d['ENGINE'])
+
+
+
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []