diff --git a/mslib/msui/constants.py b/mslib/msui/constants.py index c8f443b9a..b6eccdf9d 100644 --- a/mslib/msui/constants.py +++ b/mslib/msui/constants.py @@ -30,6 +30,7 @@ import fs import os import logging +import platformdirs # ToDo refactor to generic functions, keep only constants HOME = os.path.expanduser(f"~{os.path.sep}") @@ -39,6 +40,8 @@ # MSUI does not actually support any PyFilesystem2 fs that is not available as a local path MSUI_CONFIG_SYSPATH = _fs.getsyspath("") +MSUI_CACHE_PATH = platformdirs.user_cache_path("msui", "mss") + GRAVATAR_DIR_PATH = fs.path.join(MSUI_CONFIG_PATH, "gravatars") MSUI_SETTINGS = os.getenv('MSUI_SETTINGS', os.path.join(MSUI_CONFIG_PATH, "msui_settings.json")) diff --git a/mslib/utils/config.py b/mslib/utils/config.py index 525f01ab2..7faf3bd18 100644 --- a/mslib/utils/config.py +++ b/mslib/utils/config.py @@ -32,7 +32,6 @@ import logging import fs import os -import tempfile from mslib.utils import FatalUserError from mslib.msui import constants @@ -149,8 +148,7 @@ class MSUIDefaultConfig: WMS_preload = [] # WMS image cache settings: - # this changes on any start of msui, use ths msui_settings.json when you want a persistent path - wms_cache = os.path.join(tempfile.TemporaryDirectory().name, "msui_wms_cache") + wms_cache = str(constants.MSUI_CACHE_PATH / "wms_cache") # Maximum size of the cache in bytes. wms_cache_max_size_bytes = 20 * 1024 * 1024 diff --git a/tests/constants.py b/tests/constants.py index e9adf835d..cac933a8e 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -27,6 +27,7 @@ import os import fs +import tempfile from fs.tempfs import TempFS try: @@ -60,6 +61,9 @@ os.environ["MSUI_CONFIG_PATH"] = MSUI_CONFIG_PATH SERVER_CONFIG_FILE_PATH = fs.path.join(SERVER_CONFIG_FS.getsyspath(""), SERVER_CONFIG_FILE) +_xdg_cache_home_temporary_directory = tempfile.TemporaryDirectory() +os.environ["XDG_CACHE_HOME"] = _xdg_cache_home_temporary_directory.name + # we keep DATA_DIR until we move netCDF4 files to pyfilesystem2 DATA_DIR = DATA_FS.getsyspath("")