diff --git a/beat/web/settings/__init__.py b/beat/web/settings/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8d221af98ef576e61d5a28e214678a3072f3dde0 100644 --- a/beat/web/settings/__init__.py +++ b/beat/web/settings/__init__.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : + +############################################################################### +# # +# Copyright (c) 2020 Idiap Research Institute, http://www.idiap.ch/ # +# Contact: beat.support@idiap.ch # +# # +# This file is part of the beat.web module of the BEAT platform. # +# # +# Commercial License Usage # +# Licensees holding valid commercial BEAT licenses may use this file in # +# accordance with the terms contained in a written agreement between you # +# and Idiap. For further information contact tto@idiap.ch # +# # +# Alternatively, this file may be used under the terms of the GNU Affero # +# Public License version 3 as published by the Free Software and appearing # +# in the file LICENSE.AGPL included in the packaging of this file. # +# The BEAT platform is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # +# or FITNESS FOR A PARTICULAR PURPOSE. # +# # +# You should have received a copy of the GNU Affero Public License along # +# with the BEAT platform. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + +import os +import platform + + +SHM_PATH = "/dev/shm/beatweb" # nosec + + +def get_test_db_path(is_on_ci): + database_name = "test.sqlite3" + database_path = os.path.realpath("./") + + if not is_on_ci: + if platform.system() == "Linux": + database_path = SHM_PATH + if not os.path.exists(database_path): + os.makedirs(database_path) + + return os.path.join(database_path, database_name) + + +def get_test_prefix_path(is_on_ci): + prefix_path = os.path.realpath("./test_prefix") + if not is_on_ci: + if platform.system() == "Linux": + prefix_path = os.path.join(SHM_PATH, "test_prefix") # nosec + + return prefix_path diff --git a/beat/web/settings/ci.py b/beat/web/settings/ci.py index 3ee6eac46cc9db9997716b44d0b5d61d1208d54a..a8db0a93eb347985e766aa0fc103fe53b78bb4e9 100755 --- a/beat/web/settings/ci.py +++ b/beat/web/settings/ci.py @@ -26,8 +26,23 @@ ############################################################################### # Django settings for tests on the CI server +import os from .test import * # noqa +from . import get_test_db_path +from . import get_test_prefix_path RUNNING_ON_CI = True DATABASES["default"]["OPTIONS"]["timeout"] = 60 # noqa +DATABASES["default"]["NAME"] = get_test_db_path(RUNNING_ON_CI) # noqa +DATABASES["default"]["TEST"] = {"NAME": DATABASES["default"]["NAME"]} # noqa + +PREFIX = os.environ.get("BEAT_TEST_PREFIX", get_test_prefix_path(RUNNING_ON_CI)) +ALGORITHMS_ROOT = os.path.join(PREFIX, "algorithms") +PLOTTERS_ROOT = os.path.join(PREFIX, "plotters") +LIBRARIES_ROOT = os.path.join(PREFIX, "libraries") +DATABASES_ROOT = os.path.join(PREFIX, "databases") +DATAFORMATS_ROOT = os.path.join(PREFIX, "dataformats") +TOOLCHAINS_ROOT = os.path.join(PREFIX, "toolchains") +EXPERIMENTS_ROOT = os.path.join(PREFIX, "experiments") +CACHE_ROOT = os.path.join(PREFIX, "cache") diff --git a/beat/web/settings/test.py b/beat/web/settings/test.py index 1abd6fa8af1599f2824731bf8fd3f70b65837faf..eb03c4d943779dfb415a5d46db319b8265e248fd 100755 --- a/beat/web/settings/test.py +++ b/beat/web/settings/test.py @@ -27,9 +27,10 @@ # Django settings for tests import os -import platform from .settings import * # noqa +from . import get_test_db_path +from . import get_test_prefix_path URL_PREFIX = "" @@ -41,17 +42,7 @@ TEMPLATES[0]["OPTIONS"]["debug"] = DEBUG # noqa ALLOWED_HOSTS = ["testserver"] -if platform.system() == "Linux": - shm_path = "/dev/shm/beatweb" # nosec - if not os.path.exists(shm_path): - os.makedirs(shm_path) - - database_name = os.path.join(shm_path, "test.sqlite3") -else: - here = os.path.dirname(os.path.realpath(__file__)) - database_name = os.path.join(here, "test.sqlite3") - -DATABASES["default"]["NAME"] = database_name # noqa +DATABASES["default"]["NAME"] = get_test_db_path(RUNNING_ON_CI) # noqa DATABASES["default"]["TEST"] = {"NAME": DATABASES["default"]["NAME"]} # noqa DATABASES["default"]["OPTIONS"]["timeout"] = 30 # noqa DATABASES["default"]["ATOMIC_REQUESTS"] = True # noqa @@ -67,11 +58,7 @@ LOGGING["loggers"]["beat.web.utils.management.commands"]["handlers"] = [ # noqa ] BASE_DIR = os.path.dirname(os.path.abspath(__name__)) -if platform.system() == "Linux": - default_prefix = os.path.join(shm_path, "test_prefix") # nosec -else: - default_prefix = os.path.realpath("./test_prefix") -PREFIX = os.environ.get("BEAT_TEST_PREFIX", default_prefix) +PREFIX = os.environ.get("BEAT_TEST_PREFIX", get_test_prefix_path(RUNNING_ON_CI)) ALGORITHMS_ROOT = os.path.join(PREFIX, "algorithms") PLOTTERS_ROOT = os.path.join(PREFIX, "plotters") LIBRARIES_ROOT = os.path.join(PREFIX, "libraries")