diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-06-03 16:26:13 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-06-06 10:32:48 +0100 |
commit | d16d19dafb83448fc214fce4fbdc2bcbf4bf9ce3 (patch) | |
tree | 99057f3e6107a815e84f4c02f3e86dd8969891fd /lib/toaster/toastermain | |
parent | c3d520c92ae4ae80d31926a416456df510654b6a (diff) | |
download | bitbake-d16d19dafb83448fc214fce4fbdc2bcbf4bf9ce3.tar.gz |
toaster: read database settings from the environment
We add the capability to read the database settings for
Toaster from the environment. The DATABASE_URL is intepreted
and used to override the default settings.
This capability is essential for easy deployment of Toaster
in a managed hosted environment, and for creating
build environments with custom database settings.
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/toaster/toastermain')
-rw-r--r-- | lib/toaster/toastermain/settings.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/toaster/toastermain/settings.py b/lib/toaster/toastermain/settings.py index 645f32746..adaa56ca1 100644 --- a/lib/toaster/toastermain/settings.py +++ b/lib/toaster/toastermain/settings.py @@ -41,6 +41,39 @@ DATABASES = { } } +# Reinterpret database settings if we have DATABASE_URL environment variable defined +import os, re + +if 'DATABASE_URL' in os.environ: + dburl = os.environ['DATABASE_URL'] + if dburl.startswith('sqlite3://'): + result = re.match('sqlite3://(.*)', dburl) + if result is None: + raise Exception("ERROR: Could not read sqlite database url: %s" % dburl) + DATABASES['default'] = { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': result.group(1), + 'USER': '', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '', + } + elif dburl.startswith('mysql://'): + # URL must be in this form: mysql://user:pass@host:port/name + result = re.match(r"mysql://([^:]*):([^@]*)@([^:]*):(\d+)/([^/]*)", dburl) + if result is None: + raise Exception("ERROR: Could not read mysql database url: %s" % dburl) + DATABASES['default'] = { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': result.group(5), + 'USER': result.group(1), + 'PASSWORD': result.group(2), + 'HOST': result.group(3), + 'PORT': result.group(4), + } + else: + raise Exception("FIXME: Please implement missing database url schema for url: %s" % dburl) + # 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 = [] @@ -51,7 +84,7 @@ ALLOWED_HOSTS = [] # In a Windows environment this must be set to your system time zone. # Always use local computer's time zone, find -import os, hashlib +import hashlib if 'TZ' in os.environ: TIME_ZONE = os.environ['TZ'] else: |