Commit 32d11dcb authored by Eric Coissac's avatar Eric Coissac

Change the popvalue function to add an extra parametter allowing to indicate a...

Change the popvalue function to add an extra parametter allowing to indicate a variable name to store the popped value
the clobber packege is now working
parent 59eb2e6a
......@@ -16,81 +16,85 @@
#
# Functions provided:
#
# - setnoclobber
# Sets the noclobber mode on.
# You cannot erase an existing file by a redirection
# - setnoclobber
# Sets the noclobber mode on.
# You cannot erase an existing file by a redirection
#
# - setclobber
# Sets the noclobber mode off.
# You can erase an existing file by a redirection
# - setclobber
# Sets the noclobber mode off.
# You can erase an existing file by a redirection
#
# - getnoclobber
# Returns the noclobber status as a string
# - on: the noclobber mode is on
# - off: the noclobber mode is off
# - getnoclobber
# Returns the noclobber status as a string
# - on: the noclobber mode is on
# - off: the noclobber mode is off
#
# - pushclobber
# Saves the current noclobber mode on a stack and sets it to 'off'
# - pushclobber
# Saves the current noclobber mode on a stack and sets it to 'off'
#
# - pushnoclobber
# Saves the current noclobber mode on a stack and sets it to 'on'
# - pushnoclobber
# Saves the current noclobber mode on a stack and sets it to 'on'
#
# - popclobber
# Restores the last pushed noclobber mode
# - popclobber
# Restores the last pushed noclobber mode
#
# - popnoclobber
# Alias for the popclobber function
# - popnoclobber
# Alias for the popclobber function
#
THIS_DIR="$(dirname ${BASH_SOURCE[0]})"
source "${THIS_DIR}/utils.sh"
include stack
include logging
logdebug "Load clobber package"
include stacks
newstack __LECABASHLIB_CLOBBERSTACK__
function setnoclobber() {
set -o noclobber
set -o noclobber
}
function setclobber() {
set +o noclobber
set +o noclobber
}
function getnoclobber() {
set -o | awk '($1 ~ /noclobber/) {print $2}'
set -o | awk '($1 ~ /noclobber/) {print $2}'
}
function pushclobber() {
pushvalue __LECABASHLIB_CLOBBERSTACK__ $(getnoclobber)
setclobber
pushvalue __LECABASHLIB_CLOBBERSTACK__ $(getnoclobber)
setclobber
}
function pushnoclobber() {
pushvalue __LECABASHLIB_CLOBBERSTACK__ $(getnoclobber)
setnoclobber
pushvalue __LECABASHLIB_CLOBBERSTACK__ $(getnoclobber)
setnoclobber
}
function popclobber() {
local state=$(popvalue __LECABASHLIB_CLOBBERSTACK__)
local state=0
popvalue __LECABASHLIB_CLOBBERSTACK__ state
if [[ "$?" == "0"]]; then
if [[ "${state}" == "on" ]]; then
setnoclobber
else
setclobber
fi
else
return 1
fi
if [[ "$?" == "0" ]]; then
if [[ "${state}" == "on" ]]; then
setnoclobber
else
setclobber
fi
else
return 1
fi
return 0
return 0
}
function popnoclobber() {
popclobber
return $?
popclobber
return $?
}
......@@ -40,6 +40,9 @@
THIS_DIR="$(dirname ${BASH_SOURCE[0]})"
source "${THIS_DIR}/utils.sh"
include logging
logdebug "Load download package"
if onluke; then
module load curl/7.24.0_gcc-4.6.2
module load openssl/1.0.0f_gcc-4.6.2
......
......@@ -17,6 +17,10 @@
THIS_DIR="$(dirname ${BASH_SOURCE[0]})"
source "${THIS_DIR}/utils.sh"
include logging
logdebug "Load lecaluke package"
# Where is located the LECA_ENVIRONEMENT
LECA_ENVIRONEMENT=/nfs_scratch/LECA_ENVIRONEMENT
......
......@@ -62,7 +62,7 @@ exec 3>&2
function logdebug() {
if (( LOG_LEVEL <= LOG_DEBUG_LEVEL )); then
echo `date +'%Y-%m-%d %H:%M:%S'` "[INFO ] $$ -- $*" 1>&3
echo `date +'%Y-%m-%d %H:%M:%S'` "[DEBUG ] $$ -- $*" 1>&3
fi
}
......@@ -100,3 +100,5 @@ function closelogfile() {
LOGFILE=""
fi
}
logdebug "Load logging package"
......@@ -13,12 +13,17 @@
THIS_DIR="$(dirname ${BASH_SOURCE[0]})"
source "${THIS_DIR}/utils.sh"
include logging
logdebug "Load mutex package"
if onluke; then
include lecaluke
else
LOCK_DIR="/tmp"
fi
include clobber
LECA_LOCK_DELAY=2
function lockfile() {
......@@ -31,6 +36,7 @@ function getlock() {
notgetlock=1
while (( notgetlock )); do
pushnoclobber
notgetlock=$?
if (( notgetlock )); then
sleep "${LECA_LOCK_DELAY}"
......
......@@ -13,45 +13,58 @@
#
# Provides function:
#
# - newstack <STACKNAME>
# Creates a new stack named STACKNAME
# - newstack <STACKNAME>
# Creates a new stack named STACKNAME
#
# - stacksize <STACKNAME>
# Returns the count of element stored in the stack
# - stacksize <STACKNAME>
# Returns the count of element stored in the stack
#
# - pushvalue <STACKNAME> <VALUE>
# Adds the value VALUE at the end of the stack STACKNAME
# - pushvalue <STACKNAME> <VALUE>
# Adds the value VALUE at the end of the stack STACKNAME
#
# - popvalue <STACKNAME>
# Pops out the last pushed value of the stack.
# If the stack is already empty the function returns nothing
# and the return status is set to 1 instead of 0 usually
# - popvalue <STACKNAME>
# Pops out the last pushed value of the stack.
# If the stack is already empty the function returns nothing
# and the return status is set to 1 instead of 0 usually
#
THIS_DIR="$(dirname ${BASH_SOURCE[0]})"
source "${THIS_DIR}/utils.sh"
include logging
logdebug "Load stacks package"
function newstack() {
eval declare -a "${1}"
eval declare -a "${1}"
}
function stacksize() {
eval "echo \${#${1}[@]}"
eval "echo \${#${1}[@]}"
}
function pushvalue() {
eval ${1}[$(stacksize ${1})]=${2}
eval ${1}[$(stacksize ${1})]=${2}
}
function popvalue() {
local s=$(stacksize ${1})
local STACK="${1}"
shift
if [[ ! -z "${1}" ]]; then
COMMAND="${1}="
else
COMMAND="echo "
fi
local s=$(stacksize ${STACK})
if (( s==0 )); then
return 1
fi
local valcmd="echo \${${1}[\$(( s - 1 ))]}"
eval $valcmd
local valcmd="unset ${1}[\$(( s - 1 ))]"
eval $valcmd
local valcmd="${COMMAND}\${${STACK}[\$(( s - 1 ))]}"
eval $valcmd
valcmd="unset ${STACK}[\$(( s - 1 ))]"
eval $valcmd
return 0
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment