From 5b0304f0b5309ba74bdf4c1bba38c64cc25ce2e9 Mon Sep 17 00:00:00 2001
From: Thomas Kluyver <thomas@kluyver.me.uk>
Date: Thu, 10 Sep 2020 10:46:49 +0100
Subject: [PATCH] Finalize script in Python

---
 bin/slurm_calibrate.sh      |  2 +-
 xfel_calibrate/calibrate.py | 16 +++++++---------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/bin/slurm_calibrate.sh b/bin/slurm_calibrate.sh
index 12f574071..80d84603d 100755
--- a/bin/slurm_calibrate.sh
+++ b/bin/slurm_calibrate.sh
@@ -59,6 +59,6 @@ fi
 
 if [ "${final}" == "FINAL" ]
 then
-   XFEL_CALIBRATE_PYTHON="${python_path}" ${finalize} $SLURM_JOB_ID
+   ${python_path} ${finalize} $SLURM_JOB_ID
 fi
 killall -9 cal_influx_feeder.sh || true
diff --git a/xfel_calibrate/calibrate.py b/xfel_calibrate/calibrate.py
index ad56618c7..a3395d75c 100755
--- a/xfel_calibrate/calibrate.py
+++ b/xfel_calibrate/calibrate.py
@@ -500,17 +500,15 @@ def create_finalize_script(fmt_args, temp_path, job_list):
     """
     Create a finalize script to produce output report
     :param fmt_args: Dictionary of fmt arguments
-    :param temp_path: Path to temopary folder to run slurm job
+    :param temp_path: Path to temporary folder to run slurm job
     :param job_list: List of slurm jobs
     """
     tmpl = Template('''
-                    #!/bin/tcsh
-                    source /etc/profile.d/modules.sh
-                    module load texlive/2019
-                    echo 'Running finalize script'
-                    "${XFEL_CALIBRATE_PYTHON}" -c "from xfel_calibrate.finalize import finalize;
+                    import sys
+                    from xfel_calibrate.finalize import finalize
+
                     finalize(joblist={{joblist}}, 
-                             finaljob=$1,
+                             finaljob=sys.argv[1],
                              run_path='{{run_path}}',
                              out_path='{{out_path}}',
                              project='{{project}}', 
@@ -525,7 +523,7 @@ def create_finalize_script(fmt_args, temp_path, job_list):
                     ''')
 
     fmt_args['joblist'] = job_list
-    f_name = os.path.join(temp_path, "finalize.sh")
+    f_name = os.path.join(temp_path, "finalize.py")
     with open(f_name, "w") as finfile:
         finfile.write(textwrap.dedent(tmpl.render(**fmt_args)))
 
@@ -658,7 +656,7 @@ def concurrent_run(temp_path, nb, nbname, args, cparm=None, cval=None,
                   '"{}"'.format(args["detector"].upper()),
                   '"{}"'.format(args["type"].upper()),
                   "FINAL" if final_job else "NONFINAL",
-                  ". {}/finalize.sh".format(os.path.abspath(temp_path)),
+                  "{}/finalize.py".format(os.path.abspath(temp_path)),
                   str(cluster_cores)]
 
     output = check_output(srun_base).decode('utf8')
-- 
GitLab