diff options
Diffstat (limited to 'bitbake/lib/toaster/toastermain/settings.py')
| -rw-r--r-- | bitbake/lib/toaster/toastermain/settings.py | 67 |
1 files changed, 10 insertions, 57 deletions
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 = [] |
