From 0f3fb4e37e257159780cd0b2a7d97c65020cb4a6 Mon Sep 17 00:00:00 2001
From: Michael <m.langguth@fz-juelich.de>
Date: Tue, 9 Feb 2021 14:03:07 +0100
Subject: [PATCH] Integrate method which retireves the values of variables
 declared in a Bash-script.

---
 .../config_runscripts/config_utils.py         | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/video_prediction_tools/config_runscripts/config_utils.py b/video_prediction_tools/config_runscripts/config_utils.py
index 792d0b57..4d967a37 100644
--- a/video_prediction_tools/config_runscripts/config_utils.py
+++ b/video_prediction_tools/config_runscripts/config_utils.py
@@ -168,6 +168,32 @@ class Config_runscript_base:
             stat = True
 
         return stat
+    @staticmethod
+    #
+    # --------------------------------------------------------------------------------------------------------
+    #
+    def get_variable_from_runscript(runscript_file, script_variable):
+        '''
+        Search for the declaration of variable in a Shell script and returns its value.
+        :param runscript_file: path to shell script/runscript
+        :param script_variable: name of variable which is declared in shell script at hand
+        :return: value of script_variable
+        '''
+        script_variable = script_variable + "="
+        found = False
+
+        with open(runscript_file) as runscript:
+            # Skips text before the beginning of the interesting block:
+            for line in runscript:
+                if script_variable in line:
+                    var_value = (line.strip(script_variable)).replace("\n", "")
+                    found = True
+                    break
+
+        if not found:
+            raise Exception("Could not find declaration of '" + script_variable + "' in '" + runscript_file + "'.")
+
+        return var_value
     #
     # -----------------------------------------------------------------------------------
     #
-- 
GitLab