#!/bin/bash

PATH_ZOOMIFY="/root/tools/ZoomifyImage"
PATH_LOG=`pwd`
LOG=$PATH_LOG/zoomify.log

if test $# -ne 1
   then
      echo "nombre de parametre incorrect"
      exit 1
fi

DIRNAME=$1

if [ ! -d $DIRNAME ]
 then
   echo "      -> ERROR : $DIRNAME n'existe pas"
   exit 1
fi

cd $DIRNAME
CDRET=$?
if test $CDRET -ne 0
 then
	echo "      -> ERROR : impossible d'aller dans le repertoire $DIRNAME"
	exit $CDRET 
fi

for CURRENTDIR in $DIRNAME/*
do
  if [ -d $CURRENTDIR ]
	then
	 for IMAGE in $CURRENTDIR/*
	 do
		if [ -f $IMAGE ]
		  then
			FULLFILENAME=$(basename $IMAGE)
			FILENAME=${FULLFILENAME%.*}
			if [ ! -d $CURRENTDIR/zoomify/$FILENAME ]
				then
					python ${PATH_ZOOMIFY}/ZoomifyFileProcessor.py zoomify $IMAGE
					CDRET=$?
					if test $CDRET -ne 0
					then
						echo "Erreur traitement zoomify sur $IMAGE" >> $LOG
						exit $CDRET
					fi
			fi
		fi
	 done
	fi
done
