diff --git a/antarest/launcher/service.py b/antarest/launcher/service.py index a3dde31182..f0c1941227 100644 --- a/antarest/launcher/service.py +++ b/antarest/launcher/service.py @@ -3,6 +3,7 @@ import logging import os import shutil +import zipfile from datetime import datetime, timedelta from http import HTTPStatus from pathlib import Path @@ -522,6 +523,12 @@ def _import_output( log_paths, output_true_path / log_name, ) + if additional_logs and output_is_zipped: + with zipfile.ZipFile(output_true_path, "a") as zf: + for log_paths in additional_logs.values(): + for path in log_paths: + dest_name = path.name[: path.name.rfind("-")] + ".log" + zf.write(filename=path, arcname=dest_name) if study_id: zip_path: Optional[Path] = None @@ -535,18 +542,6 @@ def _import_output( final_output_path = zip_path or output_true_path with db(): try: - if additional_logs and output_is_zipped: - for log_name, log_paths in additional_logs.items(): - log_type = LogType.from_filename(log_name) - log_suffix = log_name - if log_type: - log_suffix = log_type.to_suffix() - self.study_service.save_logs( - study_id, - job_id, - log_suffix, - concat_files_to_str(log_paths), - ) return self.study_service.import_output( study_id, final_output_path, diff --git a/antarest/study/storage/utils.py b/antarest/study/storage/utils.py index 438f685097..b6617de2ed 100644 --- a/antarest/study/storage/utils.py +++ b/antarest/study/storage/utils.py @@ -116,8 +116,9 @@ def fix_study_root(study_path: Path) -> None: def retrieve_output_path(job_path: Path) -> Path: inside_study_output_path = job_path / "output" - if job_path.exists() and len([file for file in os.listdir(str(job_path)) if ".zip" in file]) == 1: - return job_path / [file for file in os.listdir(str(job_path)) if ".zip" in file][0] + 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: diff --git a/tests/launcher/test_service.py b/tests/launcher/test_service.py index 01611ade1d..ba726b478d 100644 --- a/tests/launcher/test_service.py +++ b/tests/launcher/test_service.py @@ -721,17 +721,15 @@ def test_manage_output(self, tmp_path: Path) -> None: ) output_path = tmp_path / "output" - zipped_output_path = tmp_path / "zipped_output" os.mkdir(output_path) - os.mkdir(zipped_output_path) new_output_path = output_path / "new_output" os.mkdir(new_output_path) (new_output_path / "log").touch() (new_output_path / "data").touch() additional_log = tmp_path / "output.log" additional_log.write_text("some log") - new_output_zipped_path = zipped_output_path / "test.zip" - with ZipFile(new_output_zipped_path, "w", ZIP_DEFLATED) as output_data: + zipped_path = tmp_path / "test.zip" + with ZipFile(zipped_path, "w", ZIP_DEFLATED) as output_data: output_data.writestr("some output", "0\n1") job_id = "job_id" zipped_job_id = "zipped_job_id" @@ -768,7 +766,7 @@ def test_manage_output(self, tmp_path: Path) -> None: launcher_service._import_output( zipped_job_id, - zipped_output_path, + zipped_path, { "out.log": [additional_log], "antares-out": [additional_log], diff --git a/tests/launcher/test_slurm_launcher.py b/tests/launcher/test_slurm_launcher.py index 7d82122b62..e5da17a8d9 100644 --- a/tests/launcher/test_slurm_launcher.py +++ b/tests/launcher/test_slurm_launcher.py @@ -413,7 +413,9 @@ def test_import_study_output(launcher_config, tmp_path) -> None: xpansion_zip_dir = launcher_config.launcher.slurm.local_workspace / "OUTPUT" / "2" xpansion_zip_dir.mkdir(parents=True) (xpansion_zip_dir / "input" / "links").mkdir(parents=True) - xpansion_output_file = xpansion_zip_dir / "xpansion.zip" + xpansion_out_put_dir = xpansion_zip_dir / "output" + xpansion_out_put_dir.mkdir(parents=True) + xpansion_output_file = xpansion_out_put_dir / "xpansion.zip" with zipfile.ZipFile(xpansion_output_file, "w") as zipf: zipf.write(xpansion_dir / "something_else", "some_file.txt") slurm_launcher._import_study_output("2", "cpp")