Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id BE18BE00DE3; Thu, 5 May 2016 06:13:26 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [74.125.82.54 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id AF656E00D88 for ; Thu, 5 May 2016 06:13:22 -0700 (PDT) Received: by mail-wm0-f54.google.com with SMTP id n129so20096578wmn.1 for ; Thu, 05 May 2016 06:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ato8bIeBskArhttYEGpL1/7Ce6qWzaW7vnIR5tlSWtM=; b=a3Y9NQDF1z2bwDl1di2VgmGrm3zTDaolTF0PnQcUavWoXhUlHecZ0wLXDtjEy4dvcX QJa4DIm7xP+YlHyBq02fITnEy+InfvO2eq/Fx6/IdEc1CqSUkztUt9nVnHsw1xoViDr4 qGYOKUHab6j3aEEGGfqYjP7qWBe8HKpZ7hh5AWpyeWroAbB1/EF/zlxo38FSpN0K3vJ9 flEZgYYNxLbty1WzBfubBmjPiFLuSJqrISVqb3A7mvjRSOHtFXUemg9T6oA+7b0vkuPe zDkEBebxJXyMXPzyGY3emeu4LyaO5HhM2vkEGGyGnDqhjZijqIlcfb3i8CuV2hmzSNMc Dmog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ato8bIeBskArhttYEGpL1/7Ce6qWzaW7vnIR5tlSWtM=; b=MDxFiC4Bxp53uIVfrYljQnD+a1jjPpTooB+W0ipeY3zXOYABIjMDM7GPiTc0PcBMva 4wtTQaKVQN1gvGvo+tYjFEWXsy4JWyfMevdV79Yc7zdxVwF4424d5SYnWJyWw0+BHFau ZF7p7+iAdewmt20n+HAd2QuYORysdxABEBQiVHwj7yDyEkJmPthEbdpAIJdDvd9k/eOO Ns5xdfb/lq3ZfJOYvuPM+GgLAsfnn4wJIqzC6f6UrhsjvqkJL/+tqUZClS7fjhndjL8e iUH8QQ/WtAZ9hBFM8j4CGtD6nkU03D9QBqcYh6QWUKXpV1FXAJRqUjg1ddK31V9v+pkZ eObg== X-Gm-Message-State: AOPr4FUhuehN7ePPGWPhryChHpiyBBi7O9mCaAlwzus0HgT5V1WGzAcZuMfCUdxsEqCTf46G X-Received: by 10.194.165.226 with SMTP id zb2mr15136567wjb.172.1462454001202; Thu, 05 May 2016 06:13:21 -0700 (PDT) Received: from dorado.ger.corp.intel.com (genld-218-172.t-mobile.co.uk. [149.254.218.172]) by smtp.gmail.com with ESMTPSA id ug8sm9719755wjc.42.2016.05.05.06.13.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 May 2016 06:13:20 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Thu, 5 May 2016 14:12:27 +0100 Message-Id: <1462453952-8837-1-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1461607497-17591-5-git-send-email-michael.g.wood@intel.com> References: <1461607497-17591-5-git-send-email-michael.g.wood@intel.com> Subject: [PATCH v2 1/6] toaster: Remove DATABASE_URL being passed around as an environment var X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2016 13:13:26 -0000 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. Signed-off-by: Michael Wood --- bitbake/bin/toaster | 2 - bitbake/lib/bb/ui/buildinfohelper.py | 20 +++---- .../toastermain/management/commands/get-dburl.py | 9 --- bitbake/lib/toaster/toastermain/settings.py | 69 ++++------------------ 4 files changed, 22 insertions(+), 78 deletions(-) delete mode 100644 bitbake/lib/toaster/toastermain/management/commands/get-dburl.py diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster index 987d53c1..91716e6 100755 --- a/bitbake/bin/toaster +++ b/bitbake/bin/toaster @@ -100,7 +100,6 @@ stop_system() fi webserverKillAll # unset exported variables - unset DATABASE_URL unset TOASTER_CONF unset TOASTER_DIR unset BITBAKE_UI @@ -278,7 +277,6 @@ case $CMD in return 4 fi export BITBAKE_UI='toasterui' - export DATABASE_URL=`$MANAGE get-dburl` $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid # set fail safe stop system on terminal exit trap stop_system SIGHUP diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py index 9397905..b07dc81 100644 --- a/bitbake/lib/bb/ui/buildinfohelper.py +++ b/bitbake/lib/bb/ui/buildinfohelper.py @@ -21,19 +21,19 @@ import bb import re import os -os.environ["DJANGO_SETTINGS_MODULE"] = "toaster.toastermain.settings" - - import django from django.utils import timezone +import toaster +# Add toaster module to the search path to help django.setup() find the right +# modules +sys.path.insert(0, os.path.dirname(toaster.__file__)) -def _configure_toaster(): - """ Add toaster to sys path for importing modules - """ - sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'toaster')) -_configure_toaster() - +#Set the DJANGO_SETTINGS_MODULE if it's not already set +os.environ["DJANGO_SETTINGS_MODULE"] =\ + os.environ.get("DJANGO_SETTINGS_MODULE", + "toaster.toastermain.settings") +# Setup django framework (needs to be done before importing modules) django.setup() from orm.models import Build, Task, Recipe, Layer_Version, Layer, Target, LogMessage, HelpText @@ -54,11 +54,11 @@ from datetime import datetime, timedelta from django.db import transaction, connection + # pylint: disable=invalid-name # the logger name is standard throughout BitBake logger = logging.getLogger("ToasterLogger") - class NotExisting(Exception): pass 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 22b3eb7..0000000 --- a/bitbake/lib/toaster/toastermain/management/commands/get-dburl.py +++ /dev/null @@ -1,9 +0,0 @@ -from toastermain.settings import getDATABASE_URL -from django.core.management.base import NoArgsCommand - -class Command(NoArgsCommand): - args = "" - help = "get database url" - - def handle_noargs(self,**options): - print getDATABASE_URL() diff --git a/bitbake/lib/toaster/toastermain/settings.py b/bitbake/lib/toaster/toastermain/settings.py index 74ab604..cab7c2e 100644 --- a/bitbake/lib/toaster/toastermain/settings.py +++ b/bitbake/lib/toaster/toastermain/settings.py @@ -21,7 +21,7 @@ # Django settings for Toaster project. -import os, re +import os DEBUG = True TEMPLATE_DEBUG = DEBUG @@ -38,14 +38,21 @@ ADMINS = ( MANAGERS = ADMINS +TOASTER_SQLITE_DEFAULT_DIR = os.path.join(os.environ.get('TOASTER_DIR', ''), + 'build') + +print "default path %s" % TOASTER_SQLITE_DEFAULT_DIR + DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': 'toaster.sqlite', # Or path to database file if using sqlite3. + # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + 'ENGINE': 'django.db.backends.sqlite3', + # DB name or full path to database file if using sqlite3. + 'NAME': "%s/toaster1.sqlite" % TOASTER_SQLITE_DEFAULT_DIR, 'USER': '', 'PASSWORD': '', - 'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '3306', # Set to empty string for default. + #'HOST': '127.0.0.1', # e.g. mysql server + #'PORT': '3306', # e.g. mysql port } } @@ -55,58 +62,6 @@ DATABASES = { if 'sqlite' in DATABASES['default']['ENGINE']: DATABASES['default']['OPTIONS'] = { 'timeout': 20 } -# Reinterpret database settings if we have DATABASE_URL environment variable defined - -if 'DATABASE_URL' in os.environ: - dburl = os.environ['DATABASE_URL'] - - if dburl.startswith('sqlite3://'): - result = re.match('sqlite3://(.*)', dburl) - if result is None: - raise Exception("ERROR: Could not read sqlite database url: %s" % dburl) - DATABASES['default'] = { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': result.group(1), - 'USER': '', - 'PASSWORD': '', - 'HOST': '', - 'PORT': '', - } - elif dburl.startswith('mysql://'): - # URL must be in this form: mysql://user:pass@host:port/name - result = re.match(r"mysql://([^:]*):([^@]*)@([^:]*):(\d*)/([^/]*)", dburl) - if result is None: - raise Exception("ERROR: Could not read mysql database url: %s" % dburl) - DATABASES['default'] = { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': result.group(5), - 'USER': result.group(1), - 'PASSWORD': result.group(2), - 'HOST': result.group(3), - 'PORT': result.group(4), - } - 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 = [] -- 2.7.4