Test File Paths in a Cinelerra XML File
This is a bash script to test all the filenames and paths in a Cinelerra project to make sure they are still valid.
#kk test_xml_paths.sh
#kk
#kk check a cinelerra xml file to make sure the file references are all valid
#kk provide filename to check as parameter
if [ -z "$1" -o "$1" = "-h" ]
then
echo “Usage: test_xml_paths [xml_filename]“
echo “For cinelerra xml files, this script checks that file paths are valid”
exit
fi
SCRIPTDIR=”$HOME/Video/video_new/common/scripts”
TMPDIR=”/tmp”
. $SCRIPTDIR/include.inc
#assign the parameter to a variable
XMLFILE=$1
#check if the xml file exists and exit if it does not
if [ ! -e $XMLFILE ]; then error “XML file does not exist”; fi
#location of the temporary file
FILENAMES=”$TMPDIR/TEST_XML_PATHS”
#set counters to zero
GOODCOUNT=0
BADCOUNT=0
#if the temp file exists, delete it
if [ -e $FILENAMES ]; then
rm $FILENAMES
fi
echo
echo Checking $XMLFILE for valid file paths…
echo
#find all of the filenames in the xml file and strip the extra junk
#send the output to a file
grep -E “SRC=|PATH=” $XMLFILE | sed -e ‘s/^.*SRC=”//g’ -e ‘s/^.*PATH=”//g’ -e ‘s/”>.*$//g’ > $FILENAMES
if [ $? != 0 ] ; then error “grep failed”; fi
# loop through the output and test if the filename is either a link or a file
for f in $( cat $FILENAMES ); do
if [ ! -h $f -a ! -e $f ]; then
BADCOUNT=`expr $BADCOUNT + 1`
echo ERROR: Missing $f
else
GOODCOUNT=`expr $GOODCOUNT + 1`
fi
done
#output the counts
echo
echo $RED$BADCOUNT Total Bad Pathss $NC
echo $GREEN$GOODCOUNT Total Good Paths$NC
echo
This program depends on include.inc which contains the following:
#use colour in the output just for fun
GREEN=$(printf “\033[32m”)
RED=$(printf “\033[31m”)
NC=$(printf “\033[0m”)
error()
{
echo ERROR: $1
exit 1
}
I tried to make these scripts as tidy and portable as possible — you will, however, need to change the path for $SCRIPTDIR to the location you are using (and $TMPDIR if you don’t want to put your temporary files in /tmp).
No comments yet.
Comments are closed.