From 8903fb12e9c361db8e00db8ae8c0233150ed6fed Mon Sep 17 00:00:00 2001
From: Adrian Schmitz <adrian.schmitz@rwth-aachen.de>
Date: Tue, 10 Jan 2023 15:58:38 +0100
Subject: [PATCH] Resolve "Move SLURM parameters to call"

---
 core/modes/__init__.py  | 15 ++++++++++++++-
 core/utility/defines.py |  2 +-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/core/modes/__init__.py b/core/modes/__init__.py
index 76ed01a..062d7c0 100644
--- a/core/modes/__init__.py
+++ b/core/modes/__init__.py
@@ -249,6 +249,17 @@ class Sbatch(Slurm):
         self.slurm_output_dir = f'{self.job.clone_path}/slurm_output'
         self.slurm_output_file = f'{self.slurm_output_dir}/so_{self.job.jobid}.txt'
 
+    def get_batch_properties(self, batch_script):
+        # cmd_out = ""
+        if self.job.down_scoping:
+            stdout = self.job.execute(f"{srun_path} /usr/bin/cat {batch_script}", '',
+                                      f"{self.job.driver_path}/core/scripts/runHelper.sh", stdout=subprocess.PIPE,
+                                      text=True).stdout
+            cmd_out = ' '.join([l.split()[1] for l in stdout.split("\n") if l.startswith('#SBATCH')])
+        else:
+            with open(batch_script, 'r') as f:
+                cmd_out = ' '.join([l.split()[1] for l in f.readlines() if l.startswith('#SBATCH')])
+        return cmd_out
 
     def get_combiner_script(self):
         self._combiner_script = f"{self.job.driver_path}/core/scripts/pipeHelper.sh"
@@ -256,7 +267,9 @@ class Sbatch(Slurm):
 
 
     def get_run_properties(self):
-        self._run_properties = f'{sbatch_path} --wait --output={self.slurm_output_file} {self.job.get_parameters()}'
+        batch_script = f'{self.job.clone_path}/{get_cenv("BATCH_SCRIPT")}'
+        self._run_properties = f'{sbatch_path} --wait {self.get_batch_properties(batch_script)} ' \
+                               f'{self.job.get_parameters()} --output={self.slurm_output_file}'
         return self._run_properties
 
     def custom_run_setup(self, **kwargs):
diff --git a/core/utility/defines.py b/core/utility/defines.py
index 76ca915..b2a5a66 100644
--- a/core/utility/defines.py
+++ b/core/utility/defines.py
@@ -1,6 +1,6 @@
 import logging
 name = 'Aixcellenz CI Driver'
-version = '0.3.0'
+version = '0.3.1'
 
 debug = False
 stdout_logging = True
-- 
GitLab