diff options
Diffstat (limited to 'bitbake/lib')
| -rw-r--r-- | bitbake/lib/bb/ui/buildinfohelper.py | 20 | ||||
| -rw-r--r-- | bitbake/lib/toaster/toastermain/management/commands/get-dburl.py | 9 | ||||
| -rw-r--r-- | bitbake/lib/toaster/toastermain/settings.py | 67 |
3 files changed, 20 insertions, 76 deletions
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 | |||
| 21 | import re | 21 | import re |
| 22 | import os | 22 | import os |
| 23 | 23 | ||
| 24 | os.environ["DJANGO_SETTINGS_MODULE"] = "toaster.toastermain.settings" | ||
| 25 | |||
| 26 | |||
| 27 | import django | 24 | import django |
| 28 | from django.utils import timezone | 25 | from django.utils import timezone |
| 29 | 26 | ||
| 27 | import toaster | ||
| 28 | # Add toaster module to the search path to help django.setup() find the right | ||
| 29 | # modules | ||
| 30 | sys.path.insert(0, os.path.dirname(toaster.__file__)) | ||
| 30 | 31 | ||
| 31 | def _configure_toaster(): | 32 | #Set the DJANGO_SETTINGS_MODULE if it's not already set |
| 32 | """ Add toaster to sys path for importing modules | 33 | os.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 | |||
| 37 | django.setup() | 37 | django.setup() |
| 38 | 38 | ||
| 39 | from orm.models import Build, Task, Recipe, Layer_Version, Layer, Target, LogMessage, HelpText | 39 | from orm.models import Build, Task, Recipe, Layer_Version, Layer, Target, LogMessage, HelpText |
| @@ -54,11 +54,11 @@ from datetime import datetime, timedelta | |||
| 54 | 54 | ||
| 55 | from django.db import transaction, connection | 55 | from 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 |
| 59 | logger = logging.getLogger("ToasterLogger") | 60 | logger = logging.getLogger("ToasterLogger") |
| 60 | 61 | ||
| 61 | |||
| 62 | class NotExisting(Exception): | 62 | class 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 @@ | |||
| 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 = [] |
