Skip to content
Snippets Groups Projects
Commit e11e05ce authored by Arno Schoenmakers's avatar Arno Schoenmakers
Browse files

Bug 1642: Renamed load_components to loadComponents

parent fcbc93b2
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
#
# load_components : loads all components in an OTDB database
#
# Copyright (C) 2006-2011
# ASTRON (Netherlands Foundation for Research in Astronomy)
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Syntax: load_components databasename
#
# $Id$
#
VERSION="v2.0" # Implemented complete new algorithm that works top down iso bottom up.
# SyntaxError msg
#
SyntaxError()
{
Msg=$1
[ -z "${Msg}" ] || echo "ERROR: ${Msg}"
echo ""
echo "Syntax: $(basename $0) [-D databasename] [-v versionnr] [-q qualifier]"
echo " [-H hostname] [-d directory]"
echo " - databasename for loading components into []"
echo " - versionnumber is svn revision number (max 6 digits) [Current]"
echo " - qualifier can be development|test|operational|example []"
echo " - hostname is the hostname of the database server [sas001]"
echo " - directory is the path to the executable load_OTDB_comps [/opt/lofar/bin]"
echo ""
}
#
# Recursive solve the childs of the current node and construct a order-file
# during the descent into the tree.
#
solveNode()
{
echo -n "."
nodeFile=`grep "^$1 " ${NODELISTFILE} | cut -d' ' -f2`
# update file admin
grep -v ^${nodeFile} ${UNUSEDFILES} >${WORKFILE}
mv ${WORKFILE} ${UNUSEDFILES}
grep "^uses" $nodeFile | sed "s/\\t/ /g" | sed "s/ / /g" | sed "s/ / /g" | cut -d' ' -f2 | while read nodeName
do
nodeFile=`grep "^$nodeName " ${NODELISTFILE} | cut -d' ' -f2`
grep "^$nodeFile" ${REVERSORDERFILE} >> /dev/null
if [ $? == 1 ]; then
# echo $nodeName
echo $nodeFile >>${REVERSORDERFILE}
solveNode $nodeName
# else
# echo "Endnode: $nodeName , file=$nodeFile"
fi
done
}
#
# MAIN
#
# check invocation syntax
DATABASE=
VERSION=`svn info | grep Revision | awk '{print $2}'`
QUAL=
HOST=`hostname -s'
DIR="/opt/lofar/bin"
while getopts "hD:v:q:H:d:" OPTION
do
case $OPTION in
h)
SyntaxError
exit 1
;;
D)
DATABASE=$OPTARG
;;
v)
VERSION=$OPTARG
;;
q)
QUAL=$OPTARG
;;
H)
HOST=$OPTARG
;;
d)
DIR=$OPTARG
;;
?)
SyntaxError
exit 1
;;
esac
done
if [[ -z $DATABASE ]]; then
echo "Please provide a database name!"
SyntaxError
exit
fi
if [ -e $DIR/load_OTDB_comps ]; then
# We use a lot of tmpfile to make life easier.
NODELISTFILE=/tmp/nodeList
REVERSORDERFILE=/tmp/reverseOrder
RESULTFILE=/tmp/fileOrder
UNUSEDFILES=/tmp/unusedFiles
WORKFILE=/tmp/tmpFile4load_components
# First construct gcompfile using .base-files.
./create_OTDB_comps
# construct a file with 'node file' relations
grep "^node" *comp | sed "s/:/ /" | sed "s/\\t/ /g" | sed "s/ / /g" | sed "s/ / /g" | cut -d' ' -f1,3 | awk '{ print $2" "$1 }' >${NODELISTFILE}
# construct a file with all componentfiles
ls -1 *comp >${UNUSEDFILES}
# strip off layer for layer
echo -n "Analysing load order: "
echo LOFAR.comp >${REVERSORDERFILE}
solveNode LOFAR
echo "."
# we now have a file with components (in reverse) order, swap the order
tac ${REVERSORDERFILE} >${RESULTFILE}
rm -f ${NODELISTFILE} ${REVERSORDERFILE}
# Construct commandline for load_OTDB_comps
arguments=$DATABASE
arguments=$arguments" "${RESULTFILE}
arguments=$arguments" -v "$VERSION
arguments=$arguments" -h "$HOST
if [ "$QUAL" != "" ]; then
arguments=$arguments" -q "$QUAL
fi
echo "Executing: $DIR/load_OTDB_comps $arguments 2>&1 | tee load_components.log"
$DIR/load_OTDB_comps $arguments 2>&1 | tee load_components.log
# when there are files we didn't use report that to the user
if [ -s ${UNUSEDFILES} ]; then
echo
echo " The following files are NOT LOADED into the database because they are NOT part of the current defined LOFAR tree:"
cat ${UNUSEDFILES}
fi
# Cleanup
rm -f ${UNUSEDFILES} ${RESULTFILE}
else
echo "Cannot execute $DIR/load_OTDB_comps (not there, or not executable)"
fi
exit
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment