From 9bbaa319e1a2f5dda58f0c6177fb2343620437c3 Mon Sep 17 00:00:00 2001
From: Nabywaniec <localadmin_mnabywan@Campus.gsi.de>
Date: Tue, 13 Sep 2022 14:52:35 +0200
Subject: [PATCH] Remove migration module from modules to apply if not found

---
 silecs_cli/silecs.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/silecs_cli/silecs.py b/silecs_cli/silecs.py
index 18b4697..49ea008 100644
--- a/silecs_cli/silecs.py
+++ b/silecs_cli/silecs.py
@@ -27,11 +27,11 @@ FESA_XSD=f"{FESA_BASE}/fesa-model-gsi/xml/deployment/deployment-gsi.xsd"
 FESA_GSI_TEMPLATE=f"{FESA_BASE}/fesa-model-gsi/xml/design/templates/GSIClassTemplate.xml"
 
 # silecs specific variables
-SILECS_DIR = "/common/usr/cscofe/silecs"
-
 try:
     SILECS_BASE=(os.environ['SILECS_BASE'])
+    SILECS_DIR=os.path.abspath(os.path.join(SILECS_BASE, os.pardir))
 except KeyError:
+    SILECS_DIR = "/common/usr/cscofe/silecs"
     SILECS_BASE= os.path.join(SILECS_DIR, SILECS_VERSION)
 
 DESIGN_SHEMA_FILE="DesignSchema.xsd"
@@ -565,9 +565,9 @@ def get_migration_modules(matching_versions, old_version):
         prev_version_underscored = get_version_underscored_tiny_as_x(prev_version)
         version_underscored = get_version_underscored_tiny_as_x(version)
 
-        migration_module = f"{prev_version_underscored}to{version_underscored}"
+        module = f"{prev_version_underscored}to{version_underscored}"
         if not prev_version_underscored == version_underscored:
-            migration_modules += [(migration_module, prev_version, version)]
+            migration_modules += [(module, prev_version, version)]
         
         prev_version = version
 
@@ -596,12 +596,14 @@ def silecs_migrate(project_path, new_version):
         else:
             raise Exception(f"Migration {old_version} to {new_version} not possible. The project {project_path} is not a silecs project")
 
-        for module, version_from, version_to in migration_modules:
+        for migration_module in migration_modules:
+            migration_module = module, version_from, version_to
             try:
                 module = __import__(module)
                 module.run_migrate(silecs_filepath, new_xml_schema, version_from, version_to)
             except Exception as e:
                 print(e)
+                migration_modules.remove(migration_module)
 
         if not migration_modules:
             print(f"There is no Migration Script for an update from: {old_version} to {new_version}\n" \
-- 
GitLab