From db843070554fe9bd518103ab922284b510ead7b5 Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Thu, 19 May 2016 13:59:28 +0100 Subject: bitbake: toaster: Remove DATABASE_URL being passed around as an environment var We don't need to pass the DATABASE_URL around and read it back if we setup the django framework in the correct way. We make the default sqlite database path a full path so that the database isn't being assumed to be in CWD. Also add some more useful comments on the database settings. This is preparation work to migrate the build tests and be able to trigger builds on differently configured databases. (Bitbake rev: 973c740404ca6a09feea250d3433075995067fe0) Signed-off-by: Michael Wood Signed-off-by: Elliot Smith Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastermain/settings.py | 67 +++++------------------------ 1 file changed, 10 insertions(+), 57 deletions(-) (limited to 'bitbake/lib/toaster/toastermain/settings.py') diff --git a/bitbake/lib/toaster/toastermain/settings.py b/bitbake/lib/toaster/toastermain/settings.py index 78702fa59e..c7edff2f61 100644 --- a/bitbake/lib/toaster/toastermain/settings.py +++ b/bitbake/lib/toaster/toastermain/settings.py @@ -21,7 +21,7 @@ # Django settings for Toaster project. -import os, re +import os DEBUG = True TEMPLATE_DEBUG = DEBUG @@ -38,14 +38,19 @@ ADMINS = ( MANAGERS = ADMINS +TOASTER_SQLITE_DEFAULT_DIR = os.path.join(os.environ.get('TOASTER_DIR', ''), + 'build') + DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': 'toaster.sqlite', # Or path to database file if using sqlite3. + # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + 'ENGINE': 'django.db.backends.sqlite3', + # DB name or full path to database file if using sqlite3. + 'NAME': "%s/toaster.sqlite" % TOASTER_SQLITE_DEFAULT_DIR, 'USER': '', 'PASSWORD': '', - 'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '3306', # Set to empty string for default. + #'HOST': '127.0.0.1', # e.g. mysql server + #'PORT': '3306', # e.g. mysql port } } @@ -55,58 +60,6 @@ DATABASES = { if 'sqlite' in DATABASES['default']['ENGINE']: DATABASES['default']['OPTIONS'] = { 'timeout': 20 } -# Reinterpret database settings if we have DATABASE_URL environment variable defined - -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) - - -# 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 = [] -- cgit v1.2.3-54-g00ecf