From a49f3cf2d23fcfb6400bc70651882fd37fca8a09 Mon Sep 17 00:00:00 2001 From: Wilmer Uruchi Ticona Date: Wed, 18 Sep 2019 16:13:42 +0200 Subject: [PATCH] Fixed #152. Added conditionals in expid, both for create and copy, that verify if the parameter [conf] custom_platforms has been set in autosubmitrc. Also added a couple of fixes for the error handling of these procedures. Updated documentation accordingly. --- autosubmit/autosubmit.py | 16 ++++++++++++---- autosubmit/config/basicConfig.py | 3 +++ docs/source/usage/create_exp.rst | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 24439f359..dc4c9fd3a 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -619,13 +619,17 @@ class Autosubmit: else: content = resource_string('autosubmit.config', 'files/' + filename) + # If autosubmitrc [conf] custom_platforms has been set and file exists, replace content + if filename.startswith("platforms") and os.path.isfile(BasicConfig.CUSTOM_PLATFORMS_PATH): + content = open(BasicConfig.CUSTOM_PLATFORMS_PATH, 'r').read() + conf_new_filename = os.path.join(BasicConfig.LOCAL_ROOT_DIR, exp_id, "conf", new_filename) Log.debug(conf_new_filename) open(conf_new_filename, 'w').write(content) Autosubmit._prepare_conf_files(exp_id, hpc, Autosubmit.autosubmit_version, dummy) except (OSError, IOError) as e: - Log.error("Can not create experiment: {0}\nCleaning...".format(e)) - Autosubmit._delete_expid(exp_id) + Log.error("Can not create experiment: {0}\nCleaning...".format(e)) + Autosubmit._delete_expid(exp_id, True) return '' else: try: @@ -640,9 +644,13 @@ class Autosubmit: conf_copy_id = os.path.join(BasicConfig.LOCAL_ROOT_DIR, copy_id, "conf") files = os.listdir(conf_copy_id) for filename in files: - if os.path.isfile(os.path.join(conf_copy_id, filename)): + if os.path.isfile(os.path.join(conf_copy_id, filename)): new_filename = filename.replace(copy_id, exp_id) content = open(os.path.join(conf_copy_id, filename), 'r').read() + # If autosubmitrc [conf] custom_platforms has been set and file exists, replace content + if filename.startswith("platforms") and os.path.isfile(BasicConfig.CUSTOM_PLATFORMS_PATH): + content = open(BasicConfig.CUSTOM_PLATFORMS_PATH, 'r').read() + open(os.path.join(dir_exp_id, "conf", new_filename), 'w').write(content) Autosubmit._prepare_conf_files(exp_id, hpc, Autosubmit.autosubmit_version, dummy) ##### @@ -661,7 +669,7 @@ class Autosubmit: return '' except (OSError, IOError) as e: Log.error("Can not create experiment: {0}\nCleaning...".format(e)) - Autosubmit._delete_expid(exp_id) + Autosubmit._delete_expid(exp_id, True) return '' Log.debug("Creating temporal directory...") diff --git a/autosubmit/config/basicConfig.py b/autosubmit/config/basicConfig.py index 528b66276..c9bec16cc 100755 --- a/autosubmit/config/basicConfig.py +++ b/autosubmit/config/basicConfig.py @@ -43,6 +43,7 @@ class BasicConfig: LOCAL_ASLOG_DIR = 'ASLOGS' LOCAL_PROJ_DIR = 'proj' DEFAULT_PLATFORMS_CONF = '' + CUSTOM_PLATFORMS_PATH = '' DEFAULT_JOBS_CONF = '' SMTP_SERVER = '' MAIL_FROM = '' @@ -80,6 +81,8 @@ class BasicConfig: BasicConfig.LOCAL_ROOT_DIR = parser.get('local', 'path') if parser.has_option('conf', 'platforms'): BasicConfig.DEFAULT_PLATFORMS_CONF = parser.get('conf', 'platforms') + if parser.has_option('conf', 'custom_platforms'): + BasicConfig.CUSTOM_PLATFORMS_PATH = parser.get('conf', 'custom_platforms') if parser.has_option('conf', 'jobs'): BasicConfig.DEFAULT_JOBS_CONF = parser.get('conf', 'jobs') if parser.has_option('mail', 'smtp_server'): diff --git a/docs/source/usage/create_exp.rst b/docs/source/usage/create_exp.rst index d0f097ceb..e7bba1859 100644 --- a/docs/source/usage/create_exp.rst +++ b/docs/source/usage/create_exp.rst @@ -25,6 +25,18 @@ Example: autosubmit expid --HPC ithaca --description "experiment is about..." +If there is an autosubmitrc or .autosubmitrc file in your home directory (cd ~), you can setup a default file from where the contents of platforms_expid.conf should be copied. + +In this autosubmitrc or .autosubmitrc file, include the configuration setting custom_platforms: + +Example: +:: + [conf] + custom_platforms=/home/Earth/user/custom.conf + +Where the specified path should be complete, as something you would get when executing pwd, and also include the filename of your custom platforms content. + + How to create a copy of an experiment ===================================== This option makes a copy of an existing experiment. @@ -42,8 +54,20 @@ Example: autosubmit expid -y cxxx -H ithaca -d "experiment is about..." +If there is an autosubmitrc or .autosubmitrc file in your home directory (cd ~), you can setup a default file from where the contents of platforms_expid.conf should be copied. + +In this autosubmitrc or .autosubmitrc file, include the configuration setting custom_platforms: + +Example: +:: + [conf] + custom_platforms=/home/Earth/user/custom.conf + +Where the specified path should be complete, as something you would get when executing pwd, and also include the filename of your custom platforms content. + .. warning:: You can only copy experiments created with Autosubmit 3.0 or above. + How to create a dummy experiment ================================ This command creates a new experiment with default values, useful for testing: -- GitLab