From 9fda7e0a76e31163b7b662857c435b305e447aeb Mon Sep 17 00:00:00 2001 From: dbeltran Date: Mon, 29 Apr 2019 11:44:24 +0200 Subject: [PATCH] migrate --- autosubmit/autosubmit.py | 4 +-- autosubmit/config/config_common.py | 50 +++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 4f21278c7..d1c6b3fd6 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -1578,12 +1578,12 @@ class Autosubmit: error = True break - as_conf.set_new_user(platform[3], as_conf.get_migrate_user_to(platform)) + as_conf.set_new_user(platform, as_conf.get_migrate_user_to(platform)) if as_conf.get_migrate_project_to(platform): Log.info("Project in platform configuration file successfully updated to {0}", as_conf.get_migrate_user_to(platform)) backup_conf.append([platform, as_conf.get_current_user(platform), as_conf.get_current_project(platform)]) - as_conf.set_new_project(platform[3], as_conf.get_migrate_project_to(platform)) + as_conf.set_new_project(platform, as_conf.get_migrate_project_to(platform)) else: Log.warning("optional PROJECT_TO directive not found. The directive PROJECT will remain unchanged") diff --git a/autosubmit/config/config_common.py b/autosubmit/config/config_common.py index 232dc4892..0248dce41 100644 --- a/autosubmit/config/config_common.py +++ b/autosubmit/config/config_common.py @@ -244,13 +244,25 @@ class AutosubmitConfig(object): :param section: platform name :type: str """ - content = open(self._platforms_parser_file).read() - - if re.search(section, content): - old_user = self.get_current_user(self.get_platform()) - content = content.replace(re.search(r'[^#]\bUSER\b =.*', content).group(0)[1:], "USER = " + new_user) - content = content.replace(re.search(r'[^#]\bUSER_TO\b =.*', content).group(0)[1:], "USER_TO = " + old_user) + with open(self._platforms_parser_file) as p_file: + contentLine = p_file.readline() + contentToMod="" + content="" + mod=False + while contentLine: + if re.search(section, contentLine): + mod=True + if mod: + contentToMod += contentLine + else: + content += contentLine + contentLine = p_file.readline() + if mod: + old_user = self.get_current_user(section) + contentToMod = contentToMod.replace(re.search(r'[^#]\bUSER\b =.*', contentToMod).group(0)[1:], "USER = " + new_user) + contentToMod = contentToMod.replace(re.search(r'[^#]\bUSER_TO\b =.*', contentToMod).group(0)[1:], "USER_TO = " + old_user) open(self._platforms_parser_file, 'w').write(content) + open(self._platforms_parser_file, 'a').write(contentToMod) def get_migrate_project_to(self, section): """ @@ -259,7 +271,7 @@ class AutosubmitConfig(object): :return: migrate project to :rtype: str """ - return self._platforms_parser.get_option(section, 'PROJECT_TO', '').lower() #TODO DOC + return self._platforms_parser.get_option(section, 'PROJECT_TO', '').lower() def set_new_project(self, section, new_project): """ @@ -268,12 +280,26 @@ class AutosubmitConfig(object): :param section: platform name :type: str """ - content = open(self._platforms_parser_file).read() - if re.search(section, content): - old_project = self.get_current_project(self.get_platform()) - content = content.replace(re.search(r"[^#]\bPROJECT\b =.*", content).group(0)[1:], "PROJECT = " + new_project) - content = content.replace(re.search(r"[^#]\bPROJECT_TO\b =.*", content).group(0)[1:], "PROJECT_TO = " + old_project) + with open(self._platforms_parser_file) as p_file: + contentLine = p_file.readline() + contentToMod="" + content="" + mod=False + while contentLine: + if re.search(section, contentLine): + mod=True + if mod: + contentToMod += contentLine + else: + content += contentLine + contentLine = p_file.readline() + if mod: + old_project = self.get_current_project(section) + contentToMod = contentToMod.replace(re.search(r"[^#]\bPROJECT\b =.*", contentToMod).group(0)[1:], "PROJECT = " + new_project) + contentToMod = contentToMod.replace(re.search(r"[^#]\bPROJECT_TO\b =.*", contentToMod).group(0)[1:], "PROJECT_TO = " + old_project) open(self._platforms_parser_file, 'w').write(content) + open(self._platforms_parser_file, 'a').write(contentToMod) + def get_custom_directives(self, section): """ -- GitLab