From 0f898ff6f5e2e2265b9f2970f36a4559e046d0c8 Mon Sep 17 00:00:00 2001 From: Marco Dalla Tiezza Date: Thu, 13 Jun 2024 16:16:36 +0200 Subject: [PATCH] Introduced temporary folder --- artemis/utils/path_utils.py | 10 ++++++++++ artemis/utils/update_utils.py | 14 +++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/artemis/utils/path_utils.py b/artemis/utils/path_utils.py index aa7ffd9..8c800d1 100644 --- a/artemis/utils/path_utils.py +++ b/artemis/utils/path_utils.py @@ -36,6 +36,15 @@ def _data_dir(): return data_dir_path +def _tmp_dir(): + if is_windows(): + tmp_dir_path = Path.home() / 'AppData' / 'Local' / 'Temp' + else: + tmp_dir_path = Path('/tmp') + + return tmp_dir_path + + def _preference_dir(): preference_dir_path = APP_DIR / 'config' if not preference_dir_path.exists(): @@ -46,4 +55,5 @@ def _preference_dir(): BASE_DIR = Path(os.path.dirname(__file__)) / '../..' APP_DIR = _app_dir() DATA_DIR = _data_dir() +TMP_DIR = _tmp_dir() PREFERENCES_DIR = _preference_dir() diff --git a/artemis/utils/update_utils.py b/artemis/utils/update_utils.py index 643dca4..b68d397 100644 --- a/artemis/utils/update_utils.py +++ b/artemis/utils/update_utils.py @@ -6,7 +6,7 @@ from packaging.version import Version from artemis.utils.constants import Constants, Messages from artemis.utils.sql_utils import ArtemisDatabase from artemis.utils.sys_utils import is_windows, is_linux, is_macos, delete_file, delete_dir, match_hash, unpack_tar, open_file -from artemis.utils.path_utils import DATA_DIR, APP_DIR +from artemis.utils.path_utils import DATA_DIR, TMP_DIR class UpdateManager: @@ -116,13 +116,13 @@ class UpdateManager: def download_db(self): """ Open the downloader and download the sigID database in the - DATA_DIR folder. After a succesfull download the callback function + TMP_DIR folder. After a succesfull download the callback function from the downloader is post_download_db """ self._parent.downloader.finished.connect(self.post_download_db) self._parent.downloader.on_start( self.remote_db_url, - DATA_DIR + TMP_DIR ) @@ -131,7 +131,7 @@ class UpdateManager: for possible corrupted data, delete old sigID DB and extract the new one """ - latest_db_tar_path = DATA_DIR / self.remote_db_file_name + latest_db_tar_path = TMP_DIR / self.remote_db_file_name if match_hash(latest_db_tar_path, self.remote_db_hash): delete_dir(DATA_DIR / 'SigID') unpack_tar(latest_db_tar_path, DATA_DIR / 'SigID') @@ -144,13 +144,13 @@ class UpdateManager: def download_artemis(self): """ Open the downloader and download Artemis in the - APP_DIR folder. After a succesfull download the callback function + TMP_DIR folder. After a succesfull download the callback function from the downloader is post_download_artemis """ self._parent.downloader.finished.connect(self.post_download_artemis) self._parent.downloader.on_start( self.remote_artemis_url, - APP_DIR + TMP_DIR ) @@ -159,7 +159,7 @@ class UpdateManager: and close the application """ if is_windows(): - open_file(APP_DIR / self.remote_artemis_file_name) + open_file(TMP_DIR / self.remote_artemis_file_name) self._parent.close_ui.emit()