From 559b7314b5b376935882c43173b5eb9c90ebe8fc Mon Sep 17 00:00:00 2001
From: Fabrice Le Goff <fabrice.le.goff@cern.ch>
Date: Mon, 2 Oct 2023 11:16:14 +0200
Subject: [PATCH] smarter scripts to connect to DB

---
 .../installed/castor.sfotzdb_intr_writer.py   |  6 -----
 .../installed/castor.sfotzdb_intr_writer.sh   | 24 +++++++++++++++++++
 .../installed/castor.sfotzdb_reader.py        |  6 -----
 .../installed/castor.sfotzdb_reader.sh        | 24 +++++++++++++++++++
 .../installed/castor.sfotzdb_writer.py        |  6 -----
 .../installed/castor.sfotzdb_writer.sh        | 24 +++++++++++++++++++
 6 files changed, 72 insertions(+), 18 deletions(-)
 delete mode 100755 ProductionTools/installed/castor.sfotzdb_intr_writer.py
 create mode 100755 ProductionTools/installed/castor.sfotzdb_intr_writer.sh
 delete mode 100755 ProductionTools/installed/castor.sfotzdb_reader.py
 create mode 100755 ProductionTools/installed/castor.sfotzdb_reader.sh
 delete mode 100755 ProductionTools/installed/castor.sfotzdb_writer.py
 create mode 100755 ProductionTools/installed/castor.sfotzdb_writer.sh

diff --git a/ProductionTools/installed/castor.sfotzdb_intr_writer.py b/ProductionTools/installed/castor.sfotzdb_intr_writer.py
deleted file mode 100755
index 857da17..0000000
--- a/ProductionTools/installed/castor.sfotzdb_intr_writer.py
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/sw/atlas/sw/lcg/releases/LCG_101/Python/3.9.6/x86_64-centos7-gcc11-opt/bin/python -i
-import cx_Oracle
-import coral_auth
-user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://int8r/ATLAS_SFO_T0')
-orcl = cx_Oracle.connect(user, pwd, dbn)
-curs = orcl.cursor()
diff --git a/ProductionTools/installed/castor.sfotzdb_intr_writer.sh b/ProductionTools/installed/castor.sfotzdb_intr_writer.sh
new file mode 100755
index 0000000..b974717
--- /dev/null
+++ b/ProductionTools/installed/castor.sfotzdb_intr_writer.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+if [ "x$CMTRELEASE" != x ]; then
+  # TDAQ environment already loaded
+  echo "using $CMTRELEASE"
+elif [ -r /sw/castor/script_setup.sh ]; then
+  #P1
+  source /sw/castor/script_setup.sh
+elif [ -r /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh ]; then
+  #testbed
+  source /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh
+else
+  echo "error: cannot setup environment"
+  exit
+fi
+
+python -i -c "
+import cx_Oracle
+import coral_auth
+user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://int8r/ATLAS_SFO_T0')
+orcl = cx_Oracle.connect(user, pwd, dbn)
+curs = orcl.cursor()
+print('orcl: connection to db object, curs: cursor on the connection')
+"
diff --git a/ProductionTools/installed/castor.sfotzdb_reader.py b/ProductionTools/installed/castor.sfotzdb_reader.py
deleted file mode 100755
index 7eb5ff7..0000000
--- a/ProductionTools/installed/castor.sfotzdb_reader.py
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/sw/atlas/sw/lcg/releases/LCG_101/Python/3.9.6/x86_64-centos7-gcc11-opt/bin/python -i
-import cx_Oracle
-import coral_auth
-user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://atonr_conf/ATLAS_SFO_T0_R')
-orcl = cx_Oracle.connect(user, pwd, dbn)
-curs = orcl.cursor()
diff --git a/ProductionTools/installed/castor.sfotzdb_reader.sh b/ProductionTools/installed/castor.sfotzdb_reader.sh
new file mode 100755
index 0000000..c9ec8a5
--- /dev/null
+++ b/ProductionTools/installed/castor.sfotzdb_reader.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+if [ "x$CMTRELEASE" != x ]; then
+  # TDAQ environment already loaded
+  echo "using $CMTRELEASE"
+elif [ -r /sw/castor/script_setup.sh ]; then
+  #P1
+  source /sw/castor/script_setup.sh
+elif [ -r /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh ]; then
+  #testbed
+  source /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh
+else
+  echo "error: cannot setup environment"
+  exit
+fi
+
+python -i -c "
+import cx_Oracle
+import coral_auth
+user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://atonr_conf/ATLAS_SFO_T0_R')
+orcl = cx_Oracle.connect(user, pwd, dbn)
+curs = orcl.cursor()
+print('orcl: connection to db object, curs: cursor on the connection')
+"
diff --git a/ProductionTools/installed/castor.sfotzdb_writer.py b/ProductionTools/installed/castor.sfotzdb_writer.py
deleted file mode 100755
index d4c4717..0000000
--- a/ProductionTools/installed/castor.sfotzdb_writer.py
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/sw/atlas/sw/lcg/releases/LCG_101/Python/3.9.6/x86_64-centos7-gcc11-opt/bin/python -i
-import cx_Oracle
-import coral_auth
-user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://atonr_conf/ATLAS_SFO_T0')
-orcl = cx_Oracle.connect(user, pwd, dbn)
-curs = orcl.cursor()
diff --git a/ProductionTools/installed/castor.sfotzdb_writer.sh b/ProductionTools/installed/castor.sfotzdb_writer.sh
new file mode 100755
index 0000000..6e2dc76
--- /dev/null
+++ b/ProductionTools/installed/castor.sfotzdb_writer.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+if [ "x$CMTRELEASE" != x ]; then
+  # TDAQ environment already loaded
+  echo "using $CMTRELEASE"
+elif [ -r /sw/castor/script_setup.sh ]; then
+  #P1
+  source /sw/castor/script_setup.sh
+elif [ -r /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh ]; then
+  #testbed
+  source /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh
+else
+  echo "error: cannot setup environment"
+  exit
+fi
+
+python -i -c "
+import cx_Oracle
+import coral_auth
+user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://atonr_conf/ATLAS_SFO_T0')
+orcl = cx_Oracle.connect(user, pwd, dbn)
+curs = orcl.cursor()
+print('orcl: connection to db object, curs: cursor on the connection')
+"
-- 
GitLab