From fc6ba453ebb14c2dfa61a7b06b621869a14cb188 Mon Sep 17 00:00:00 2001 From: Mohamed Abdel Wedoud Date: Thu, 24 Oct 2024 21:09:15 +0200 Subject: [PATCH] fix(archive-outputs): correct code errors and formatting --- antarest/study/storage/abstract_storage_service.py | 2 +- .../study/storage/rawstudy/model/filesystem/config/files.py | 6 +----- .../study/storage/rawstudy/model/filesystem/config/model.py | 2 +- antarest/study/storage/utils.py | 2 +- tests/core/utils/test_extract_zip.py | 1 + 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/antarest/study/storage/abstract_storage_service.py b/antarest/study/storage/abstract_storage_service.py index 38ca363c74..94773d0011 100644 --- a/antarest/study/storage/abstract_storage_service.py +++ b/antarest/study/storage/abstract_storage_service.py @@ -263,7 +263,7 @@ def import_output( stopwatch.log_elapsed(lambda elapsed_time: logger.info(f"Copied output for {study_id} in {elapsed_time}s")) fix_study_root(path_output) output_full_name = extract_output_name(path_output, output_name) - extension = f"{ArchiveFormat.ZIP}" if is_zipped else "" + extension = f"{ArchiveFormat.SEVEN_ZIP}" if is_archived else "" path_output = path_output.rename(Path(path_output.parent, output_full_name + extension)) data = self.get(metadata, f"output/{output_full_name}", 1, use_cache=False) diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/files.py b/antarest/study/storage/rawstudy/model/filesystem/config/files.py index 656ddaeca7..ba5865fd3a 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/files.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/files.py @@ -25,11 +25,7 @@ from antarest.core.model import JSON from antarest.core.serialization import from_json -from antarest.core.utils.archives import ( - extract_lines_from_archive, - is_archive_format, - read_file_from_archive, -) +from antarest.core.utils.archives import extract_lines_from_archive, is_archive_format, read_file_from_archive from antarest.study.model import STUDY_VERSION_8_1, STUDY_VERSION_8_6 from antarest.study.storage.rawstudy.ini_reader import IniReader from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import ( diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/model.py b/antarest/study/storage/rawstudy/model/filesystem/config/model.py index 73202d8be8..0812aee9ff 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/model.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/model.py @@ -194,7 +194,7 @@ def __init__( def next_file(self, name: str, is_output: bool = False) -> "FileStudyTreeConfig": if is_output and name in self.outputs and self.outputs[name].archived: locations = [self.path / f"{name}.7z", self.path / f"{name}.zip"] - archive_path = next((p for p in locations if p.exists())) + archive_path: t.Optional[Path] = next((p for p in locations if p.exists())) else: archive_path = self.archive_path diff --git a/antarest/study/storage/utils.py b/antarest/study/storage/utils.py index 9da3394920..9d8093b7d5 100644 --- a/antarest/study/storage/utils.py +++ b/antarest/study/storage/utils.py @@ -152,7 +152,7 @@ def extract_output_name(path_output: Path, new_suffix_name: t.Optional[str] = No if new_suffix_name: suffix_name = new_suffix_name general_info["name"] = suffix_name - if not archived: + if not is_output_archived: ini_writer = IniWriter() ini_writer.write(info_antares_output, path_output / info_filename) else: diff --git a/tests/core/utils/test_extract_zip.py b/tests/core/utils/test_extract_zip.py index 9327bfc21e..5d24e6c772 100644 --- a/tests/core/utils/test_extract_zip.py +++ b/tests/core/utils/test_extract_zip.py @@ -20,6 +20,7 @@ from antarest.core.exceptions import BadArchiveContent from antarest.core.utils.archives import extract_archive + class TestExtractArchive: """ Test the `extract_zip` function.