From 9b105ac3b44a46048925c329789340b09b8e1bea Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Mon, 15 Apr 2024 19:11:47 +0200 Subject: [PATCH] feat(export): use "7zip" format to export a study --- .../storage/rawstudy/raw_study_service.py | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/antarest/study/storage/rawstudy/raw_study_service.py b/antarest/study/storage/rawstudy/raw_study_service.py index 4990d70bf6..659fb1b1c1 100644 --- a/antarest/study/storage/rawstudy/raw_study_service.py +++ b/antarest/study/storage/rawstudy/raw_study_service.py @@ -128,21 +128,19 @@ def update_name_and_version_from_raw_meta(self, metadata: RawStudy) -> bool: def exists(self, study: RawStudy) -> bool: """ - Check study exist. + Check if the study exists in the filesystem. + Args: - study: study + study: The study to check. Returns: true if study presents in disk, false else. - """ - path = self.get_study_path(study) - if study.archived: - path = self.get_archive_path(study) - zf = ZipFile(path, "r") - return str("study.antares") in zf.namelist() + archive_path = self.get_archive_path(study) + return archive_path.is_file() - return (path / "study.antares").is_file() + path = self.get_study_path(study) + return path.joinpath("study.antares").is_file() def get_raw( self, @@ -392,7 +390,21 @@ def unarchive(self, study: RawStudy) -> None: self.import_study(study, fh) def get_archive_path(self, study: RawStudy) -> Path: - return Path(self.config.storage.archive_dir / f"{study.id}.zip") + """ + Get archive path of a study. + + Args: + study: The study to get the archive path for. + + Returns: + The full path of the archive file (zip or 7z). + """ + archive_dir: Path = self.config.storage.archive_dir + for suffix in [".zip", ".7z"]: + path = archive_dir.joinpath(f"{study.id}{suffix}") + if path.is_file(): + return path + return archive_dir.joinpath(f"{study.id}.7z") def get_study_path(self, metadata: Study) -> Path: """