From 4ee1ef00fdc1eb4754bdf53dc285c8ab1580aefe Mon Sep 17 00:00:00 2001
From: karnem <mikhail.karnevskiy@desy.de>
Date: Mon, 6 Jan 2020 15:03:01 +0100
Subject: [PATCH] refactor activate script

---
 activate => bin/activate.sh |  3 ++-
 bin/slurm_calibrate.sh      | 14 +++-----------
 xfel_calibrate/calibrate.py |  4 ++--
 xfel_calibrate/settings.py  |  4 ++--
 4 files changed, 9 insertions(+), 16 deletions(-)
 rename activate => bin/activate.sh (51%)

diff --git a/activate b/bin/activate.sh
similarity index 51%
rename from activate
rename to bin/activate.sh
index f10650047..359a3df5c 100644
--- a/activate
+++ b/bin/activate.sh
@@ -1,4 +1,5 @@
 source /etc/profile.d/modules.sh
 module load anaconda/3
 module load texlive
-export PATH=/home/${USER}/.local/bin:$PATH
+# export path to python environment
+export PATH=$HOME/.local/bin:$PATH
diff --git a/bin/slurm_calibrate.sh b/bin/slurm_calibrate.sh
index 5b7105a5b..44be0e93e 100755
--- a/bin/slurm_calibrate.sh
+++ b/bin/slurm_calibrate.sh
@@ -6,7 +6,7 @@ python_path=$2
 ipython_path=$3
 jupyter_path=$4
 ipcluster_path="${5}"
-krb_activate_path=$6
+activate_path=$6
 uuid=$7
 notebook=$8
 detector=$9
@@ -21,7 +21,7 @@ echo "Python path: $python_path"
 echo "IPython path: $ipython_path"
 echo "Jupyter path: $jupyter_path"
 echo "IP-Cluster path: $ipcluster_path"
-echo "Karabo activate: $krb_activate_path"
+echo "Environment activate: $activate_path"
 echo "IP-Cluster profile: $uuid"
 echo "notebook: $notebook"
 echo "detector: $detector"
@@ -34,15 +34,7 @@ echo "job ID: $SLURM_JOB_ID"
 export CAL_NOTEBOOK_NAME=$notebook
 
 # set-up enviroment
-if [ "${krb_activate_path}" != "NO_KRB_ACTIVATE" ]
-then
-    source ${krb_activate_path}
-else
-    source /etc/profile.d/modules.sh
-    module load anaconda/3
-    module load texlive
-    export PATH=/home/${USER}/.local/bin:$PATH
-fi
+source ${activate_path}
 
 echo "Starting influx feeder"
 ./cal_influx_feeder.sh $notebook $detector $caltype > /dev/null 2>&1  &
diff --git a/xfel_calibrate/calibrate.py b/xfel_calibrate/calibrate.py
index d32a857ec..cdfc87f34 100755
--- a/xfel_calibrate/calibrate.py
+++ b/xfel_calibrate/calibrate.py
@@ -641,8 +641,8 @@ def concurrent_run(temp_path, nb, nbname, args, cparm=None, cval=None,
                   ipython_path,  # path to ipython
                   jupyter_path,  # path to jupyter
                   ipcluster_path,  # path to ipcluster
-                  # karabo activate path
-                  karabo_activate_path if karabo_activate_path else "NO_KRB_ACTIVATE",
+                  # python activate path
+                  activate_path if activate_path!="" else "{}/bin/activate.sh".format(os.path.dirname(__file__)),
                   args.get("cluster_profile", "NO_CLUSTER"),
                   '"{}"'.format(base_name.upper()),
                   '"{}"'.format(args["detector"].upper()),
diff --git a/xfel_calibrate/settings.py b/xfel_calibrate/settings.py
index 33924ac12..b132b895d 100644
--- a/xfel_calibrate/settings.py
+++ b/xfel_calibrate/settings.py
@@ -12,8 +12,8 @@ ipython_path = "ipython"
 # Path to use for calling Jupyter. If the environment is correctly set, simply the command
 jupyter_path = "jupyter"
 
-# Path to find the Karabo activate script at, set to an empty string if not running in a Karabo environemnt
-karabo_activate_path = ""
+# Path to find activate script
+activate_path = ""
 
 # Path to use for calling ipcluster. If the environment is correctly set, simply the command
 ipcluster_path = "ipcluster"
-- 
GitLab