diff options
author | Michael Wood <michael.g.wood@intel.com> | 2016-05-19 13:59:28 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-20 10:09:02 +0100 |
commit | db843070554fe9bd518103ab922284b510ead7b5 (patch) | |
tree | 66287d8ef8d3f6c39028cd3794ea44b98ed11f68 /bitbake/lib/toaster | |
parent | 8fba59ce45de865354b0b115e1b33f5a59172614 (diff) | |
download | poky-db843070554fe9bd518103ab922284b510ead7b5.tar.gz |
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 <michael.g.wood@intel.com>
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r-- | bitbake/lib/toaster/toastermain/management/commands/get-dburl.py | 9 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastermain/settings.py | 67 |
2 files changed, 10 insertions, 66 deletions
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 @@ | |||
1 | from toastermain.settings import getDATABASE_URL | ||
2 | from django.core.management.base import NoArgsCommand | ||
3 | |||
4 | class 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 | ||
24 | import os, re | 24 | import os |
25 | 25 | ||
26 | DEBUG = True | 26 | DEBUG = True |
27 | TEMPLATE_DEBUG = DEBUG | 27 | TEMPLATE_DEBUG = DEBUG |
@@ -38,14 +38,19 @@ ADMINS = ( | |||
38 | 38 | ||
39 | MANAGERS = ADMINS | 39 | MANAGERS = ADMINS |
40 | 40 | ||
41 | TOASTER_SQLITE_DEFAULT_DIR = os.path.join(os.environ.get('TOASTER_DIR', ''), | ||
42 | 'build') | ||
43 | |||
41 | DATABASES = { | 44 | DATABASES = { |
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 = { | |||
55 | if 'sqlite' in DATABASES['default']['ENGINE']: | 60 | if '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 | |||
60 | if '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 | |||
94 | def 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 |
112 | ALLOWED_HOSTS = [] | 65 | ALLOWED_HOSTS = [] |