95 lines
2.7 KiB
Bash
95 lines
2.7 KiB
Bash
#!/bin/sh
|
|
#
|
|
# Run frpost on a hierarchy
|
|
#
|
|
# Usage: post-all.sh [--verbose] TGZDIR TEMPLATEDIR INPUTDIR
|
|
#
|
|
# Options (used by web side, ours slightly different!):
|
|
# --use-control-file,
|
|
# --separator=|,
|
|
# --emit-meta-fields,
|
|
# --emit-markers,
|
|
# --column-headers,
|
|
# --target-column-report,
|
|
# --default-value=,
|
|
# --output-file=/media/YellowSnow/CoreLogicIngest/data/APPRAISALS_TEST_SET2/Combined/output/FRPost/FRPostOutput.out,
|
|
# --verbose,
|
|
# --mapping-file=*,
|
|
# --input-directory=/media/YellowSnow/CoreLogicIngest/staging/APPRAISALS_TEST_SET2/Combined/output/FRCapture,
|
|
# --template-directory=/media/YellowSnow/CoreLogicIngest/templates
|
|
#
|
|
|
|
VERBOSE=""
|
|
if [ "$1" = "--verbose" ]; then
|
|
VERBOSE=$1
|
|
shift;
|
|
fi
|
|
|
|
# e.g. /Users/tim/Dropbox/FR (1)/CLresults
|
|
TGZDIR="$1"
|
|
shift
|
|
|
|
# e.g. /home/tim/dev/frpost/templates
|
|
TEMPLATEDIR="$1"
|
|
shift
|
|
|
|
# e.g. /media/YellowSnow/CoreLogicIngest/staging/APPRAISALS
|
|
SRCDIR="$1"
|
|
shift
|
|
|
|
if [ "${SRCDIR}" = "" -o ! -d "$SRCDIR" ]; then
|
|
echo "Usage: post-all.sh TGZDIR TEMPLATEDIR INPUTDIR"
|
|
exit 1
|
|
fi
|
|
|
|
DSTDIR=`echo $SRCDIR | sed 's#staging#data#'`
|
|
|
|
echo "Finding directories to process..."
|
|
find "$SRCDIR" -mindepth 0 -maxdepth 1 -type d | while read dir; do
|
|
SUBDIR="${dir}/output/FRCapture"
|
|
if [ ! -d "${SUBDIR}" ]; then
|
|
echo "Not an output directory: ${SUBDIR}; skipping"
|
|
continue;
|
|
fi
|
|
# template
|
|
#TMPLDIR=`echo ${SRCDIR} | sed "s#CoreLogicIngest.*#CoreLogicIngest/templates#"`
|
|
|
|
# dest
|
|
dst=${DSTDIR}`echo $dir | sed "s#$SRCDIR##"`
|
|
OUTDIR="${dst}/output/FRPost"
|
|
mkdir -p "${OUTDIR}"
|
|
OUTFILE="${OUTDIR}/FRPostOutput-tabs.csv"
|
|
|
|
# clean out any cruft
|
|
echo "*** Move previous .csv to PREVIOUS"
|
|
mkdir "${SUBDIR}"/PREVIOUS
|
|
mv -v "${SUBDIR}"/*.csv "${SUBDIR}"/*.typ "${SUBDIR}"/PREVIOUS
|
|
|
|
# .tgz extract
|
|
base=`basename "${dir}"`
|
|
echo "*** Process: $SUBDIR to\n*** \t$OUTDIR ***"
|
|
echo " Looking for tgz .csv files in: ${TGZDIR}/${base}.csv.tgz ..."
|
|
if [ -f "${TGZDIR}/${base}.csv.tgz" ]; then
|
|
echo "Found ${TGZDIR}/${base}.csv.tgz"
|
|
tar -C "${SUBDIR}" -xvf "${TGZDIR}/${base}.csv.tgz"
|
|
else
|
|
echo "Did not find ${TGZDIR}/${base}.csv.tgz"
|
|
fi
|
|
|
|
# template extract
|
|
echo " Copying template .typ files ..."
|
|
cp -v "${TEMPLATEDIR}"/*.typ "${SUBDIR}"
|
|
|
|
#rm "${OUTDIR}"/../_frpost_.log
|
|
(
|
|
echo "*** Processing directory: $SUBDIR to\n\t$OUTDIR ***"
|
|
args="--mapping-file=x --separator=tab --column-headers --emit-meta-fields --emit-markers ${VERBOSE}"
|
|
args="$args --input-directory=${SUBDIR} --output-file=$OUTFILE --template-directory=${TEMPLATEDIR}"
|
|
echo "*** frpost.sh ${args}"
|
|
frpost.sh ${args}
|
|
) > "${OUTDIR}"/../_frpost_.log
|
|
#gnutar -czvf "${OUTDIR}"/../_frpost_.log.tar.gz "${OUTDIR}"/../_frpost_.log --remove_files
|
|
done
|
|
|
|
exit 0
|