From 8d966b9da58776d1633e406b4a75a54b55d3d3a4 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Tue, 19 Dec 2023 21:51:03 +0100 Subject: [PATCH] refactor(service): simplify implementation of `retrieve_output_path` function --- antarest/launcher/service.py | 4 ++-- antarest/study/storage/utils.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/antarest/launcher/service.py b/antarest/launcher/service.py index f0c1941227..b661fa3a78 100644 --- a/antarest/launcher/service.py +++ b/antarest/launcher/service.py @@ -498,9 +498,9 @@ def _import_output( study_id = job_result.study_id job_launch_params = LauncherParametersDTO.parse_raw(job_result.launcher_params or "{}") - # this now can be a zip file instead of a directory ! + # this now can be a zip file instead of a directory! output_true_path = retrieve_output_path(output_path) - output_is_zipped = is_zip(output_true_path) + output_is_zipped = output_true_path.suffix.lower() == ".zip" output_suffix = cast( Optional[str], getattr( diff --git a/antarest/study/storage/utils.py b/antarest/study/storage/utils.py index b6617de2ed..d27d341ff1 100644 --- a/antarest/study/storage/utils.py +++ b/antarest/study/storage/utils.py @@ -115,14 +115,17 @@ def fix_study_root(study_path: Path) -> None: def retrieve_output_path(job_path: Path) -> Path: - inside_study_output_path = job_path / "output" output_already_zipped_path = job_path.with_suffix(".zip") if output_already_zipped_path.exists(): return output_already_zipped_path - elif inside_study_output_path.exists() and len(os.listdir(inside_study_output_path)) == 1: - return inside_study_output_path / os.listdir(str(inside_study_output_path))[0] - else: - return Path() + + output_inside_study = job_path / "output" + if output_inside_study.is_dir(): + output_folders = os.listdir(output_inside_study) + if len(output_folders) == 1: + return output_inside_study / output_folders[0] + + return Path() def extract_output_name(path_output: Path, new_suffix_name: t.Optional[str] = None) -> str: