diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 736be3a0694bee4e5c0032ba889c4d0d14255040..8f22a65c486b5c213e87a989120ce20ed54f4f43 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -18,6 +18,7 @@ # along with Autosubmit. If not, see . from __future__ import print_function import threading +import traceback from job.job_packager import JobPackager from job.job_exceptions import WrongTemplateException @@ -3131,7 +3132,7 @@ class Autosubmit: @staticmethod def create(expid, noplot, hide, output='pdf', group_by=None, expand=list(), expand_status=list(), notransitive=False, check_wrappers=False, detail=False): """ - Creates job list for given experiment. Configuration files must be valid before realizing this process. + Creates job list for given experiment. Configuration files must be valid before executing this process. :param expid: experiment identifier :type expid: str @@ -3163,12 +3164,14 @@ class Autosubmit: as_conf = AutosubmitConfig( expid, BasicConfig, ConfigParserFactory()) as_conf.check_conf_files(False) + project_type = as_conf.get_project_type() # Getting output type provided by the user in config, 'pdf' as default output_type = as_conf.get_output_type() if not Autosubmit._copy_code(as_conf, expid, project_type, False): return False + update_job = not os.path.exists(os.path.join(BasicConfig.LOCAL_ROOT_DIR, expid, "pkl", "job_list_" + expid + ".pkl")) Autosubmit._create_project_associated_conf( @@ -3299,6 +3302,7 @@ class Autosubmit: message = "We have detected that there is another Autosubmit instance using the experiment\n. Stop other Autosubmit instances that are using the experiment or delete autosubmit.lock file located on tmp folder" raise AutosubmitCritical(message, 7000) except AutosubmitCritical as e: + Log.debug(traceback.format_exc()) raise AutosubmitCritical(e.message, e.code) @staticmethod @@ -3317,6 +3321,9 @@ class Autosubmit: :rtype: bool """ project_destination = as_conf.get_project_destination() + # if project_destination is None: + # raise AutosubmitCritical( + # "Autosubmit couldn't identify the project destination.", 7014) if project_type == "git": submitter = Autosubmit._get_submitter(as_conf) submitter.load_platforms(as_conf) @@ -3324,6 +3331,7 @@ class Autosubmit: hpcarch = submitter.platforms[as_conf.get_platform()] except: raise AutosubmitCritical("Can't set main platform", 7014) + return AutosubmitGit.clone_repository(as_conf, force, hpcarch) elif project_type == "svn": svn_project_url = as_conf.get_svn_project_url() diff --git a/autosubmit/config/config_common.py b/autosubmit/config/config_common.py index c5203ce703d6cf0d44b947a9c3485a237a33e00a..d3bd390909a3b208b906263b8d66e46fb6c5ff18 100644 --- a/autosubmit/config/config_common.py +++ b/autosubmit/config/config_common.py @@ -25,6 +25,7 @@ except ImportError: import os import re import subprocess +import traceback from pyparsing import nestedExpr @@ -908,16 +909,21 @@ class AutosubmitConfig(object): :return: git commit :rtype: str """ - value = self._exp_parser.get('project', 'PROJECT_DESTINATION') - if not value: - if self.get_project_type().lower() == "local": - value = os.path.split(self.get_local_project_path())[1] - elif self.get_project_type().lower() == "svn": - value = self.get_svn_project_url().split('/')[-1] - elif self.get_project_type().lower() == "git": - value = self.get_git_project_origin().split( - '/')[-1].split('.')[-2] - return value + try: + value = self._exp_parser.get('project', 'PROJECT_DESTINATION') + if not value: + if self.get_project_type().lower() == "local": + value = os.path.split(self.get_local_project_path())[1] + elif self.get_project_type().lower() == "svn": + value = self.get_svn_project_url().split('/')[-1] + elif self.get_project_type().lower() == "git": + value = self.get_git_project_origin().split( + '/')[-1].split('.')[-2] + return value + except Exception as exp: + Log.debug(str(exp)) + Log.debug(traceback.format_exc()) + return '' def set_git_project_commit(self, as_conf): """ diff --git a/autosubmit/database/db_jobdata.py b/autosubmit/database/db_jobdata.py index b25fc8dfd5f19adffca6a02a35b14149fa9e5be2..63f9cc0696bcc67c76c262f8d971413f7f501e88 100644 --- a/autosubmit/database/db_jobdata.py +++ b/autosubmit/database/db_jobdata.py @@ -707,7 +707,9 @@ class JobDataStructure(MainDataBase): failed INTEGER NOT NULL, queuing INTEGER NOT NULL, running INTEGER NOT NULL, - submitted INTEGER NOT NULL + submitted INTEGER NOT NULL, + suspended INTEGER NOT NULL DEFAULT 0, + metadata TEXT ); ''') diff --git a/autosubmit/git/autosubmit_git.py b/autosubmit/git/autosubmit_git.py index e6110b635587540bc506803ade2972129396de5f..577ff571aef217cd236c3c01e9ce20ff37be5467 100644 --- a/autosubmit/git/autosubmit_git.py +++ b/autosubmit/git/autosubmit_git.py @@ -22,9 +22,11 @@ import os from shutil import rmtree import subprocess import shutil +import zipfile #from autosubmit import Autosubmit from autosubmit.config.basicConfig import BasicConfig -from log.log import Log,AutosubmitCritical,AutosubmitError +from time import time +from log.log import Log, AutosubmitCritical, AutosubmitError Log.get_logger("Autosubmit") @@ -47,7 +49,8 @@ class AutosubmitGit: :param as_conf: experiment configuration :type as_conf: autosubmit.config.AutosubmitConfig """ - proj_dir = os.path.join(BasicConfig.LOCAL_ROOT_DIR, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) + proj_dir = os.path.join( + BasicConfig.LOCAL_ROOT_DIR, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) dirname_path = as_conf.get_project_dir() Log.debug("Checking git directory status...") if path.isdir(dirname_path): @@ -56,16 +59,18 @@ class AutosubmitGit: output = subprocess.check_output("cd {0}; git diff-index HEAD --".format(dirname_path), shell=True) except subprocess.CalledProcessError as e: - raise AutosubmitCritical("Failed to retrieve git info ...",7064,e.message) + raise AutosubmitCritical( + "Failed to retrieve git info ...", 7064, e.message) if output: Log.info("Changes not committed detected... SKIPPING!") - raise AutosubmitCritical("Commit needed!",7013) + raise AutosubmitCritical("Commit needed!", 7013) else: output = subprocess.check_output("cd {0}; git log --branches --not --remotes".format(dirname_path), shell=True) if output: Log.info("Changes not pushed detected... SKIPPING!") - raise AutosubmitCritical("Synchronization needed!", 7064) + raise AutosubmitCritical( + "Synchronization needed!", 7064) else: if not as_conf.set_git_project_commit(as_conf): return False @@ -76,6 +81,7 @@ class AutosubmitGit: else: Log.debug("Not a directory... SKIPPING!") return True + @staticmethod def check_commit(as_conf): """ @@ -84,7 +90,8 @@ class AutosubmitGit: :param as_conf: experiment configuration :type as_conf: autosubmit.config.AutosubmitConfig """ - proj_dir = os.path.join(BasicConfig.LOCAL_ROOT_DIR, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) + proj_dir = os.path.join( + BasicConfig.LOCAL_ROOT_DIR, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) dirname_path = as_conf.get_project_dir() if path.isdir(dirname_path): Log.debug("Checking git directory status...") @@ -97,19 +104,22 @@ class AutosubmitGit: return True if output: - Log.printlog("There are local changes not commited to git",3000) + Log.printlog( + "There are local changes not commited to git", 3000) return True else: output = subprocess.check_output("cd {0}; git log --branches --not --remotes".format(dirname_path), shell=True) if output: - Log.printlog("There are local changes not pushed to git", 3000) + Log.printlog( + "There are local changes not pushed to git", 3000) return True else: Log.info("Model Git repository is updated") Log.result("Model Git repository is updated") return True + @staticmethod def clone_repository(as_conf, force, hpcarch): """ @@ -126,7 +136,8 @@ class AutosubmitGit: submodule_failure = False if not as_conf.is_valid_git_repository(): - raise AutosubmitCritical("Incorrect git Configuration, check origin,commit and branch settings of expdef file", 7064) + raise AutosubmitCritical( + "Incorrect git Configuration, check origin,commit and branch settings of expdef file", 7064) git_project_origin = as_conf.get_git_project_origin() git_project_branch = as_conf.get_git_project_branch() git_remote_project_path = as_conf.get_git_remote_project_root() @@ -140,11 +151,23 @@ class AutosubmitGit: else: git_single_branch = True project_destination = as_conf.get_project_destination() - project_path = os.path.join(BasicConfig.LOCAL_ROOT_DIR, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) + project_path = os.path.join( + BasicConfig.LOCAL_ROOT_DIR, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) + project_backup_path = os.path.join( + BasicConfig.LOCAL_ROOT_DIR, as_conf.expid, 'proj_{0}'.format(int(time()))) git_path = as_conf.get_project_dir() + # Making proj backup + if force: + Log.info("Making a backup of your current proj folder at {0}".format( + project_backup_path)) + shutil.move(project_path, project_backup_path) + #shutil.make_archive(project_backup_path, 'zip', project_path) + #project_backup_path = project_backup_path + ".zip" + if os.path.exists(project_path): Log.info("Using project folder: {0}", project_path) + # print("Force {0}".format(force)) if not force: Log.debug("The project folder exists. SKIPPING...") return True @@ -155,46 +178,57 @@ class AutosubmitGit: if git_remote_project_path != '': if git_remote_project_path[-1] == '/': - git_remote_path=os.path.join(git_remote_project_path[:-1], as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) + git_remote_path = os.path.join( + git_remote_project_path[:-1], as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) else: - git_remote_path=os.path.join(git_remote_project_path, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) - project_path=git_remote_path + git_remote_path = os.path.join( + git_remote_project_path, as_conf.expid, BasicConfig.LOCAL_PROJ_DIR) + project_path = git_remote_path if git_project_commit: - Log.info("Fetching {0} into {1}", git_project_commit + " " + git_project_origin, project_path) + Log.info("Fetching {0} into {1}", git_project_commit + + " " + git_project_origin, project_path) try: if git_single_branch: command = "cd {0}; git clone {1} {4}; cd {2}; git checkout {3};".format(project_path, - git_project_origin, git_path, - git_project_commit, - project_destination) + git_project_origin, git_path, + git_project_commit, + project_destination) else: command = "cd {0}; git clone {1} {4}; cd {2}; git checkout {3};".format(project_path, - git_project_origin, git_path, - git_project_commit, - project_destination) + git_project_origin, git_path, + git_project_commit, + project_destination) if git_project_submodules.__len__() <= 0: command += " git submodule update --init --recursive" else: - command += " cd {0}; git submodule init;".format(project_destination) + command += " cd {0}; git submodule init;".format( + project_destination) for submodule in git_project_submodules: try: - command += " git submodule update {0};".format(submodule) + command += " git submodule update {0};".format( + submodule) except BaseException as e: - submodule_failure=True + submodule_failure = True Log.printlog("Trace: {0}".format(e.message), 6014) - Log.printlog("Submodule {0} has a wrong configuration".format(submodule), 6014) + Log.printlog( + "Submodule {0} has a wrong configuration".format(submodule), 6014) if git_remote_project_path == '': output = subprocess.check_output(command, shell=True) else: - command="cd {0} && {1}".format(git_remote_path,command) + command = "cd {0} && {1}".format(git_remote_path, command) hpcarch.send_command(command) except subprocess.CalledProcessError as e: shutil.rmtree(project_path) - raise AutosubmitCritical("Can not checkout commit {0}: {1}".format(git_project_commit, output)) + if os.path.exists(project_backup_path): + Log.info("Restoring proj folder...") + shutil.move(project_backup_path, project_path) + raise AutosubmitCritical( + "Can not checkout commit {0}: {1}".format(git_project_commit, output)) else: - Log.info("Cloning {0} into {1}", git_project_branch + " " + git_project_origin, project_path) + Log.info("Cloning {0} into {1}", git_project_branch + + " " + git_project_origin, project_path) try: command = "cd {0}; ".format(project_path) @@ -204,34 +238,46 @@ class AutosubmitGit: project_destination) else: command += " git clone --single-branch --recursive -b {0} {1} {2}".format(git_project_branch, git_project_origin, - project_destination) + project_destination) else: if not git_single_branch: command += " git clone -b {0} {1} {2};".format(git_project_branch, git_project_origin, - project_destination) + project_destination) else: command += " git clone --single-branch -b {0} {1} {2};".format(git_project_branch, git_project_origin, project_destination) - command += " cd {0}; git submodule init;".format(project_destination) + command += " cd {0}; git submodule init;".format( + project_destination) for submodule in git_project_submodules: try: - command += " git submodule update {0};".format(submodule) + command += " git submodule update {0};".format( + submodule) except BaseException as e: - submodule_failure=True + submodule_failure = True Log.printlog("Trace: {0}".format(e.message), 6014) - Log.printlog("Submodule {0} has a wrong configuration".format(submodule), 6014) + Log.printlog( + "Submodule {0} has a wrong configuration".format(submodule), 6014) Log.debug('{0}', command) if git_remote_project_path == '': output = subprocess.check_output(command, shell=True) else: hpcarch.send_command(command) - except subprocess.CalledProcessError as e: shutil.rmtree(project_path) - raise AutosubmitCritical("Can not clone {0} into {1}".format(git_project_branch + " " + git_project_origin, project_path), 7065,e.message) + if os.path.exists(project_backup_path): + Log.info("Restoring proj folder...") + shutil.move(project_backup_path, project_path) + raise AutosubmitCritical("Can not clone {0} into {1}".format( + git_project_branch + " " + git_project_origin, project_path), 7065, e.message) + if submodule_failure: - return False + Log.info( + "Some Submodule failures have been detected. Backup {0} will not be removed.".format(project_backup_path)) + return False + if os.path.exists(project_backup_path): + Log.info("Removing backup...") + shutil.rmtree(project_backup_path) return True