summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbitbake/bin/toaster2
-rw-r--r--bitbake/lib/bb/ui/buildinfohelper.py20
-rw-r--r--bitbake/lib/toaster/toastermain/management/commands/get-dburl.py9
-rw-r--r--bitbake/lib/toaster/toastermain/settings.py67
4 files changed, 20 insertions, 78 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index 921164c47e..05b7935ddb 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -100,7 +100,6 @@ stop_system()
100 fi 100 fi
101 webserverKillAll 101 webserverKillAll
102 # unset exported variables 102 # unset exported variables
103 unset DATABASE_URL
104 unset TOASTER_CONF 103 unset TOASTER_CONF
105 unset TOASTER_DIR 104 unset TOASTER_DIR
106 unset BITBAKE_UI 105 unset BITBAKE_UI
@@ -278,7 +277,6 @@ case $CMD in
278 return 4 277 return 4
279 fi 278 fi
280 export BITBAKE_UI='toasterui' 279 export BITBAKE_UI='toasterui'
281 export DATABASE_URL=`$MANAGE get-dburl`
282 $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid 280 $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid
283 # set fail safe stop system on terminal exit 281 # set fail safe stop system on terminal exit
284 trap stop_system SIGHUP 282 trap stop_system SIGHUP
diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
index c5368f63be..cea53e053a 100644
--- a/bitbake/lib/bb/ui/buildinfohelper.py
+++ b/bitbake/lib/bb/ui/buildinfohelper.py
@@ -21,19 +21,19 @@ import bb
21import re 21import re
22import os 22import os
23 23
24os.environ["DJANGO_SETTINGS_MODULE"] = "toaster.toastermain.settings"
25
26
27import django 24import django
28from django.utils import timezone 25from django.utils import timezone
29 26
27import toaster
28# Add toaster module to the search path to help django.setup() find the right
29# modules
30sys.path.insert(0, os.path.dirname(toaster.__file__))
30 31
31def _configure_toaster(): 32#Set the DJANGO_SETTINGS_MODULE if it's not already set
32 """ Add toaster to sys path for importing modules 33os.environ["DJANGO_SETTINGS_MODULE"] =\
33 """ 34 os.environ.get("DJANGO_SETTINGS_MODULE",
34 sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'toaster')) 35 "toaster.toastermain.settings")
35_configure_toaster() 36# Setup django framework (needs to be done before importing modules)
36
37django.setup() 37django.setup()
38 38
39from orm.models import Build, Task, Recipe, Layer_Version, Layer, Target, LogMessage, HelpText 39from orm.models import Build, Task, Recipe, Layer_Version, Layer, Target, LogMessage, HelpText
@@ -54,11 +54,11 @@ from datetime import datetime, timedelta
54 54
55from django.db import transaction, connection 55from django.db import transaction, connection
56 56
57
57# pylint: disable=invalid-name 58# pylint: disable=invalid-name
58# the logger name is standard throughout BitBake 59# the logger name is standard throughout BitBake
59logger = logging.getLogger("ToasterLogger") 60logger = logging.getLogger("ToasterLogger")
60 61
61
62class NotExisting(Exception): 62class NotExisting(Exception):
63 pass 63 pass
64 64
diff --git a/bitbake/lib/toaster/toastermain/management/commands/get-dburl.py b/bitbake/lib/toaster/toastermain/management/commands/get-dburl.py
deleted file mode 100644
index 911296f714..0000000000
--- a/bitbake/lib/toaster/toastermain/management/commands/get-dburl.py
+++ /dev/null
@@ -1,9 +0,0 @@
1from toastermain.settings import getDATABASE_URL
2from django.core.management.base import NoArgsCommand
3
4class Command(NoArgsCommand):
5 args = ""
6 help = "get database url"
7
8 def handle_noargs(self,**options):
9 print(getDATABASE_URL())
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 @@
21 21
22# Django settings for Toaster project. 22# Django settings for Toaster project.
23 23
24import os, re 24import os
25 25
26DEBUG = True 26DEBUG = True
27TEMPLATE_DEBUG = DEBUG 27TEMPLATE_DEBUG = DEBUG
@@ -38,14 +38,19 @@ ADMINS = (
38 38
39MANAGERS = ADMINS 39MANAGERS = ADMINS
40 40
41TOASTER_SQLITE_DEFAULT_DIR = os.path.join(os.environ.get('TOASTER_DIR', ''),
42 'build')
43
41DATABASES = { 44DATABASES = {
42 'default': { 45 'default': {
43 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 46 # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
44 'NAME': 'toaster.sqlite', # Or path to database file if using sqlite3. 47 'ENGINE': 'django.db.backends.sqlite3',
48 # DB name or full path to database file if using sqlite3.
49 'NAME': "%s/toaster.sqlite" % TOASTER_SQLITE_DEFAULT_DIR,
45 'USER': '', 50 'USER': '',
46 'PASSWORD': '', 51 'PASSWORD': '',
47 'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 52 #'HOST': '127.0.0.1', # e.g. mysql server
48 'PORT': '3306', # Set to empty string for default. 53 #'PORT': '3306', # e.g. mysql port
49 } 54 }
50} 55}
51 56
@@ -55,58 +60,6 @@ DATABASES = {
55if 'sqlite' in DATABASES['default']['ENGINE']: 60if 'sqlite' in DATABASES['default']['ENGINE']:
56 DATABASES['default']['OPTIONS'] = { 'timeout': 20 } 61 DATABASES['default']['OPTIONS'] = { 'timeout': 20 }
57 62
58# Reinterpret database settings if we have DATABASE_URL environment variable defined
59
60if 'DATABASE_URL' in os.environ:
61 dburl = os.environ['DATABASE_URL']
62
63 if dburl.startswith('sqlite3://'):
64 result = re.match('sqlite3://(.*)', dburl)
65 if result is None:
66 raise Exception("ERROR: Could not read sqlite database url: %s" % dburl)
67 DATABASES['default'] = {
68 'ENGINE': 'django.db.backends.sqlite3',
69 'NAME': result.group(1),
70 'USER': '',
71 'PASSWORD': '',
72 'HOST': '',
73 'PORT': '',
74 }
75 elif dburl.startswith('mysql://'):
76 # URL must be in this form: mysql://user:pass@host:port/name
77 result = re.match(r"mysql://([^:]*):([^@]*)@([^:]*):(\d*)/([^/]*)", dburl)
78 if result is None:
79 raise Exception("ERROR: Could not read mysql database url: %s" % dburl)
80 DATABASES['default'] = {
81 'ENGINE': 'django.db.backends.mysql',
82 'NAME': result.group(5),
83 'USER': result.group(1),
84 'PASSWORD': result.group(2),
85 'HOST': result.group(3),
86 'PORT': result.group(4),
87 }
88 else:
89 raise Exception("FIXME: Please implement missing database url schema for url: %s" % dburl)
90
91
92# Allows current database settings to be exported as a DATABASE_URL environment variable value
93
94def getDATABASE_URL():
95 d = DATABASES['default']
96 if d['ENGINE'] == 'django.db.backends.sqlite3':
97 if d['NAME'] == ':memory:':
98 return 'sqlite3://:memory:'
99 elif d['NAME'].startswith("/"):
100 return 'sqlite3://' + d['NAME']
101 return "sqlite3://" + os.path.join(os.getcwd(), d['NAME'])
102
103 elif d['ENGINE'] == 'django.db.backends.mysql':
104 return "mysql://" + d['USER'] + ":" + d['PASSWORD'] + "@" + d['HOST'] + ":" + d['PORT'] + "/" + d['NAME']
105
106 raise Exception("FIXME: Please implement missing database url schema for engine: %s" % d['ENGINE'])
107
108
109
110# Hosts/domain names that are valid for this site; required if DEBUG is False 63# Hosts/domain names that are valid for this site; required if DEBUG is False
111# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts 64# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
112ALLOWED_HOSTS = [] 65ALLOWED_HOSTS = []