From 58b4824084ac3bfcd82a1b472015e589538cee36 Mon Sep 17 00:00:00 2001
From: Karim Ahmed <karim.ahmed@xfel.eu>
Date: Tue, 3 Dec 2019 09:11:48 +0100
Subject: [PATCH] write run name in folder when not prod

---
 xfel_calibrate/calibrate.py | 10 ++++++++++
 xfel_calibrate/settings.py  |  4 +++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/xfel_calibrate/calibrate.py b/xfel_calibrate/calibrate.py
index 0edd6f6ba..6f9f9ebb9 100755
--- a/xfel_calibrate/calibrate.py
+++ b/xfel_calibrate/calibrate.py
@@ -792,6 +792,16 @@ def run():
         if try_report_to_output:
             if "out_folder" in args:
                 out_path = os.path.abspath(args["out_folder"])
+                if "run" in args:
+                    rr = args["run"]
+                    # Only put run, when it is not in the folder path
+                    # (e.g. out-folder from webservice conf)
+                    if "r{:04d}/".format(rr) not in out_path and\
+                            "{}".format(rr) not in out_path:
+                        if isinstance(rr, int):
+                            out_path = "{}/r{:04d}/".format(out_path, rr)
+                        else:
+                            out_path = "{}/{}/".format(out_path, rr)
             else:
                 print("No 'out_folder' defined as argument, outputting to '{}' instead.".format(
                     out_path))
diff --git a/xfel_calibrate/settings.py b/xfel_calibrate/settings.py
index 33924ac12..3b9ee2144 100644
--- a/xfel_calibrate/settings.py
+++ b/xfel_calibrate/settings.py
@@ -33,5 +33,7 @@ launcher_command = "sbatch -t 24:00:00 --requeue --output {temp_path}/slurm-%j.o
 free_nodes_cmd = "sinfo -p exfel -t idle -N --noheader | wc -l"
 preempt_nodes_cmd = "squeue -p all,grid --noheader | grep max-exfl | egrep -v 'max-exfl18[3-8]|max-exfl100|max-exflg' | wc -l"
 max_reserved = 8
-reservation = "xcal"
+# "xcal" reservation value removed as ITDM
+# is giving xcal priority by default.
+reservation = ""
 reservation_char = "darks"
-- 
GitLab