bitbake: toaster: add function to get the database url
authorAlexandru DAMIAN <alexandru.damian@intel.com>
Wed, 11 Jun 2014 08:34:55 +0000 (09:34 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 13 Jun 2014 10:55:33 +0000 (11:55 +0100)
We add a function that returns the DATABASE_URL
for the current 'default' database settings. This
is useful to be able to start other toaster instances
with the same database settigns as the currently running
instance.

(Bitbake rev: 272a4bba0804bb6b5e0d498d3453321b5ed1dc76)

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/lib/toaster/toastermain/settings.py

index 2c52b68..2ce10c4 100644 (file)
@@ -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 = []