[Swift-commit] r3961 - usertools/persistent-coasters

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Jan 12 11:34:43 CST 2011


Author: wozniak
Date: 2011-01-12 11:34:43 -0600 (Wed, 12 Jan 2011)
New Revision: 3961

Added:
   usertools/persistent-coasters/coasters-setup.sh
   usertools/persistent-coasters/gensites.sh
   usertools/persistent-coasters/gentc.sh
   usertools/persistent-coasters/helpers.zsh
Modified:
   usertools/persistent-coasters/run.zsh
Log:
Additional required scripts from cdm/scripts/tools


Added: usertools/persistent-coasters/coasters-setup.sh
===================================================================
--- usertools/persistent-coasters/coasters-setup.sh	                        (rev 0)
+++ usertools/persistent-coasters/coasters-setup.sh	2011-01-12 17:34:43 UTC (rev 3961)
@@ -0,0 +1,5 @@
+
+# Source this to setup GLOBUS_HOSTNAME
+
+ipaddr=$( ifconfig | grep inet | head -1 | cut -d ':' -f 2 | awk '{print $1}' )
+export GLOBUS_HOSTNAME=$ipaddr

Added: usertools/persistent-coasters/gensites.sh
===================================================================
--- usertools/persistent-coasters/gensites.sh	                        (rev 0)
+++ usertools/persistent-coasters/gensites.sh	2011-01-12 17:34:43 UTC (rev 3961)
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+# Certain sites files may require environment variables,
+#  see below.
+# In particular, URL for the coasters persistent service
+
+# Swift work directory, e.g., ${HOME}/work
+WORK=$1
+# Input sites file, e.g., sites.local.xml
+INPUT=$2
+# Output sites file, e.g., sites.xml
+OUTPUT=$3
+
+crash()
+{
+    MSG=$1
+    echo ${MSG}
+    exit 1
+}
+
+[[ ${WORK}   == "" ]] && crash "Not specified: WORK"
+[[ ${INPUT}  == "" ]] && crash "Not specified: INPUT"
+[[ ${OUTPUT} == "" ]] && crash "Not specified: OUTPUT"
+
+[[ ${GLOBUS_HOSTNAME} == "" ]] && crash "Not specified: GLOBUS_HOSTNAME"
+
+# If the sites file requires a PROJECT, QUEUE, N_GRAN, or N_MAX and
+# it is not set in the environment, crash:
+for TOKEN in PROJECT QUEUE N_GRAN N_MAX SLOTS
+ do
+ if grep _${TOKEN}_ ${INPUT} > /dev/null
+   then
+   if ! declare -p ${TOKEN} > /dev/null
+     then
+     printenv
+     crash "Not specified: ${TOKEN}"
+   fi
+ fi
+done
+
+{
+  echo "s/_NODES_/${NODES}/"
+  echo "s/_HOST_/${GLOBUS_HOSTNAME}/"
+  echo "s at _WORK_@${WORK}@"
+  echo "s/_PROJECT_/${PROJECT}/"
+  echo "s/_QUEUE_/${QUEUE}/"
+  echo "s/_N_GRAN_/${N_GRAN}/"
+  echo "s/_N_MAX_/${N_MAX}/"
+  echo "s/_SLOTS_/${SLOTS}/"
+  echo "s/_MAXTIME_/${MAXTIME}/"
+  echo "s at _SERVICE_COASTERS_@${SERVICE_COASTERS:-NO_URL_GIVEN}@"
+  echo "s at _SERVICE_PORT_@${SERVICE_PORT:-NO_PORT_GIVEN}@"
+} > gensites.sed
+
+sed -f gensites.sed < ${INPUT} > ${OUTPUT}


Property changes on: usertools/persistent-coasters/gensites.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: usertools/persistent-coasters/gentc.sh
===================================================================
--- usertools/persistent-coasters/gentc.sh	                        (rev 0)
+++ usertools/persistent-coasters/gentc.sh	2011-01-12 17:34:43 UTC (rev 3961)
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# Substitutes PWD for _DIR_ in tc files 
+# example usage: gentc.sh tc.something.data tc.data ${PWD}
+
+# Input tc file, e.g., tc.local.data
+INPUT=$1
+# Output tc file, e.g., tc.data
+OUTPUT=$2
+DIR=$3
+
+[[ ${DIR} == "" ]] && echo "No DIR!" && exit 1
+
+crash()
+{
+    MSG=$1
+    echo ${MSG}
+    exit 1
+}
+
+[[ ${INPUT}  == "" ]] && crash "Not specified: INPUT"
+[[ ${OUTPUT} == "" ]] && crash "Not specified: OUTPUT"
+
+{
+    sed "s at _DIR_@${DIR}@" 
+} < ${INPUT} > ${OUTPUT}


Property changes on: usertools/persistent-coasters/gentc.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: usertools/persistent-coasters/helpers.zsh
===================================================================
--- usertools/persistent-coasters/helpers.zsh	                        (rev 0)
+++ usertools/persistent-coasters/helpers.zsh	2011-01-12 17:34:43 UTC (rev 3961)
@@ -0,0 +1,241 @@
+
+KB=1024
+MB=$(( 1024*KB ))
+GB=$(( 1024*MB ))
+
+assert() {
+  ERR=$1
+  shift
+  MSG="${*}"
+  check ${ERR} "${MSG}" || exit ${ERR}
+  return 0
+}
+
+exitcode()
+{
+  ERR=$?
+  MSG="${*}"
+  assert ${ERR} "${MSG}"
+}
+
+# If CODE is non-zero, print MSG and return CODE
+check()
+{
+  CODE=$1
+  shift
+  MSG=${*}
+
+  if [[ ${CODE} != 0 ]]
+    then
+    print ${MSG}
+    return ${CODE}
+  fi
+  return 0
+}
+
+bail()
+{
+  CODE=$1
+  shift
+  MSG="${*}"
+  print "${MSG}"
+  set +x
+}
+
+crash()
+{
+  CODE=$1
+  shift
+  MSG="${*}"
+  bail ${CODE} ${MSG}
+  exit ${CODE}
+}
+
+checkvar()
+{
+  local VAR=$1
+
+  if [[ ${(P)VAR} == "" ]]
+    then
+    crash 1 "Not set: ${VAR}"
+  fi
+  return 0
+}
+
+checkvars()
+{
+  local VARS
+  VARS=( ${*} )
+  for V in ${VARS}
+   do
+   checkvar ${V}
+  done
+  return 0
+}
+
+nanos()
+{
+  date +%s.%N
+}
+
+within()
+{
+  local TIME=$1
+  shift
+  local START STOP DIFF LEFT
+  START=$( nanos )
+  ${*}
+  STOP=$( nanos )
+  DIFF=$(( STOP-START ))
+  if (( DIFF < 0 ))
+    then
+    print "TIME exceeded (${DIFF} > ${TIME})!"
+    return 1
+  fi
+  LEFT=$(( TIME-LEFT ))
+  sleep ${LEFT}
+  return 0
+}
+
+
+scan()
+# Use shoot to output the contents of a scan
+{
+  [[ $1 == "" ]] && return
+  typeset -g -a $1
+  local i=1
+  local T
+  while read T
+  do
+    eval "${1}[${i}]='${T}'"
+    (( i++ ))
+  done
+}
+
+shoot()
+# print out an array loaded by scan()
+{
+  local i
+  local N
+  N=$( eval print '${#'$1'}' )
+    # print N $N
+  for (( i=1 ; i <= N ; i++ ))
+  do
+    eval print -- "$"${1}"["${i}"]"
+  done
+}
+
+scan_kv()
+{
+  [[ $1 == "" ]] && return 1
+  typeset -g -A $1
+  while read T
+  do
+   A=( ${T} )
+   KEY=${A[1]%:} # Strip any tailing :
+   VALUE=${A[2,-1]}
+   eval "${1}[${KEY}]='${VALUE}'"
+  done
+  return 0
+}
+
+shoot_kv()
+{ 
+  local VAR=$1
+  eval print -a -C 2 \"'${(kv)'$VAR'[@]}'\"
+  return 0
+}
+
+tformat()
+# Convert seconds to hh:mm:ss
+{
+  local -Z 2 T=$1
+  local -Z 2 M
+
+  if (( T <= 60 ))
+  then
+    print "${T}"
+  elif (( T <= 3600 ))
+  then
+    M=$(( T/60 ))
+    print "${M}:$( tformat $(( T%60 )) )"
+  else
+    print "$(( T/3600 )):$( tformat $(( T%3600 )) )"
+  fi
+}
+
+bformat()
+# Format byte counts
+{
+  local BYTES=$1
+  local LENGTH=${2:-3}
+  local UNIT
+  local UNITS
+  UNITS=( "B" "KB" "MB" "GB" "TB" )
+
+  local B=${BYTES}
+  for (( UNIT=0 ; UNIT < 4 ; UNIT++ ))
+   do
+   (( B /= 1024 ))
+   (( B == 0 )) && break
+  done
+
+  local RESULT=${UNITS[UNIT+1]}
+  if [[ ${RESULT} == "B" ]] 
+    then
+    print "${BYTES} B"
+  else 
+    local -F BF=${BYTES}
+    local MANTISSA=$(( BF / (1024 ** UNIT ) ))
+    MANTISSA=$( significant ${LENGTH} ${MANTISSA} )
+    print "${MANTISSA} ${RESULT}"
+  fi
+  
+  return 0
+}
+
+significant()
+# Report significant digits from floating point number
+{
+  local DIGITS=$1
+  local NUMBER=$2
+
+  local -F FLOAT=${NUMBER}
+  local RESULT
+  local DOT=0
+  local LZ=1 # Leading zeros
+  local C
+  local i=1
+  while (( 1 )) 
+   do
+    C=${FLOAT[i]}
+    [[ ${C} != "0" ]] && [[ ${C} != "." ]] && break
+    [[ ${C} == "." ]] && DOT=1
+    RESULT+=${C}
+    (( i++ ))
+  done
+  while (( ${DIGITS} > 0 )) 
+  do
+    C=${FLOAT[i]}
+    if [[ ${C} == "" ]] 
+      then 
+      (( ! DOT )) && RESULT+="." && DOT=1
+      C="0"
+    fi
+    RESULT+=${C}
+    [[ ${C} == "." ]] && (( DIGITS++ )) && DOT=1
+    (( i++ ))
+    (( DIGITS-- ))
+  done
+  if (( ! DOT )) # Extra zeros to finish out integer
+    then 
+    local -i J=${NUMBER}
+    # J=${J}
+    while (( ${#RESULT} < ${#J} ))
+     do
+     RESULT+="0"
+    done
+  fi
+  print ${RESULT}
+  return 0
+}

Modified: usertools/persistent-coasters/run.zsh
===================================================================
--- usertools/persistent-coasters/run.zsh	2011-01-12 17:31:25 UTC (rev 3960)
+++ usertools/persistent-coasters/run.zsh	2011-01-12 17:34:43 UTC (rev 3961)
@@ -1,5 +1,8 @@
 #!/bin/zsh
 
+# Process management is incomplete here, check for
+# processes with ps
+
 set -x
 
 APP=$( cd $( dirname $0 ) ; /bin/pwd )




More information about the Swift-commit mailing list