From 60f03686f7242be6a14a901a06afe78bdd18e6b3 Mon Sep 17 00:00:00 2001 From: dbeltran Date: Mon, 10 Jun 2024 14:12:45 +0200 Subject: [PATCH] Fix when file doesn't exist --- autosubmit/autosubmit.py | 9 ++++++++- autosubmit/helpers/utils.py | 25 ++++++++++++++++++++++++- autosubmit/job/job.py | 5 +++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 16c71d182..4e7e8a106 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -86,7 +86,7 @@ from typing import List import autosubmit.history.utils as HUtils import autosubmit.helpers.autosubmit_helper as AutosubmitHelper import autosubmit.statistics.utils as StatisticsUtils -from autosubmit.helpers.utils import proccess_id, terminate_child_process +from autosubmit.helpers.utils import proccess_id, terminate_child_process, check_jobs_file_exists from contextlib import suppress @@ -1485,6 +1485,7 @@ class Autosubmit: signal.signal(signal.SIGINT, signal_handler) as_conf = AutosubmitConfig(expid, BasicConfig, YAMLParserFactory()) as_conf.check_conf_files(True) + project_type = as_conf.get_project_type() safetysleeptime = as_conf.get_safetysleeptime() Log.debug("The Experiment name is: {0}", expid) @@ -2501,6 +2502,12 @@ class Autosubmit: save_2 = False wrapper_errors = {} any_job_submitted = False + # Check section jobs + if not only_wrappers and not inspect : + jobs_section = set([job.section for job in job_list.get_ready()]) + for section in jobs_section: + if check_jobs_file_exists(as_conf, section): + raise AutosubmitCritical(f"Job {self.name} does not have a correct template// template not found", 7014) try: for platform in platforms_to_test: packager = JobPackager(as_conf, platform, job_list, hold=hold) diff --git a/autosubmit/helpers/utils.py b/autosubmit/helpers/utils.py index b712d1f2c..7ccca9cf8 100644 --- a/autosubmit/helpers/utils.py +++ b/autosubmit/helpers/utils.py @@ -1,4 +1,3 @@ -import collections import subprocess import os import pwd @@ -11,6 +10,30 @@ from autosubmit.notifications.notifier import Notifier from autosubmitconfigparser.config.basicconfig import BasicConfig from log.log import AutosubmitCritical, Log + +def check_jobs_file_exists(as_conf, current_section_name=None): + if str(as_conf.experiment_data.get("PROJECT", {}).get("PROJECT_TYPE", "none")).lower() != "none": + templates_dir = f"{as_conf.experiment_data.get('ROOTDIR','')}/proj/{as_conf.experiment_data.get('PROJECT', {}).get('PROJECT_DESTINATION', '')}" + if not os.path.exists(templates_dir): + raise AutosubmitCritical(f"Templates directory {templates_dir} does not exist", 7011) + + # List of files that doesn't exist. + missing_files = "" + # Check if all files in jobs_data exist or only current section + if current_section_name: + jobs_data = [as_conf.jobs_data.get(current_section_name, {})] + else: + jobs_data = as_conf.jobs_data.values() + for data in jobs_data: + if "SCRIPT" not in data: + if "FILE" in data: + if not os.path.exists(f"{templates_dir}/{data['FILE']}"): + missing_files += f"{templates_dir}/{data['FILE']} \n" + else: + Log.result(f"File {templates_dir}/{data['FILE']} exists") + if missing_files: + raise AutosubmitCritical(f"Templates not found:\n{missing_files}", 7011) + def terminate_child_process(expid, platform=None): # get pid of the main process pid = os.getpid() diff --git a/autosubmit/job/job.py b/autosubmit/job/job.py index 9b892d267..bad576df2 100644 --- a/autosubmit/job/job.py +++ b/autosubmit/job/job.py @@ -1995,8 +1995,9 @@ class Job(object): :rtype: str """ self.update_parameters(as_conf, self.parameters) - if self.script and self.file: - Log.warning(f"Custom script for job {self.name} is being used, file contents are ignored.") + if self.script: + if self.file: + Log.warning(f"Custom script for job {self.name} is being used, file contents are ignored.") template = self.script else: try: -- GitLab