allow to have AUTOYEAR instead of e.g. 2011
authormkrzewic <mikolaj.krzewicki@cern.ch>
Thu, 11 Dec 2014 11:28:07 +0000 (12:28 +0100)
committermkrzewic <mikolaj.krzewicki@cern.ch>
Thu, 18 Dec 2014 15:58:49 +0000 (16:58 +0100)
for clear documentation now AUTOYEAR can be set in
$ocdbStorage, e.g.

ocdbStorage=local:///cvmfs/alice.gsi.de/alice/data/AUTOYEAR/OCDB/

no change in fuctionality, just a better hint at the automatic
funtionality

PWGPP/scripts/utilities.sh

index e7f6bee..0308abd 100755 (executable)
@@ -171,13 +171,16 @@ guessPeriod()
 
 setYear()
 {
-  #set the year
+  #set the year in the string
+  #usualy used to modify the year in $ocdbStorage
   #  ${1} - year to be set
   #  ${2} - where to set the year
-  local year1=$(guessYearFast ${1})
-  local year2=$(guessYearFast ${2})
+  #if AUTOYEAR is present in target - it will be replaced by the year
+  local yearSource=$(guessYearFast ${1})
+  local yearTarget=$(guessYearFast ${2})
   local path=${2}
-  [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
+  [[ ${yearSource} -ne ${yearTarget} && -n ${yearTarget} && -n ${yearSource} ]] \
+    && path=${2/\/"${yearTarget}"\//\/"${yearSource}"\/}
   echo ${path}
   return 0
 }
@@ -185,13 +188,17 @@ setYear()
 guessYearFast()
 {
   #guess the year from the path, pick the rightmost one
+  #is string AUTOYEAR present, will be returned
   local IFS="/"
   declare -a pathArray=( ${1} )
-  local field
-  local year
+  local field=""
+  local year=""
+  local autoYear=""
   for field in ${pathArray[@]}; do
-    [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
+    [[ ${field} =~ ^20[0-9][0-9]$ ]] && year="${field}"
+    [[ ${field} == AUTOYEAR ]] && autoYear="${field}"
   done
+  [[ -n ${autoYear} ]] && year="${autoYear}"
   echo ${year}
   return 0
 }