From 5cd15b603dfc7f390cee5856e3bce989c948c7fe Mon Sep 17 00:00:00 2001 From: Qui T Chau Date: Wed, 11 Nov 2020 15:07:21 -0800 Subject: [PATCH] Changes to support issue #246: Add -d parameter to validate-bundle tool. --- src/main/resources/bin/validate-bundle | 51 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/resources/bin/validate-bundle b/src/main/resources/bin/validate-bundle index 96e0d2471..248e7860b 100755 --- a/src/main/resources/bin/validate-bundle +++ b/src/main/resources/bin/validate-bundle @@ -9,7 +9,7 @@ usage() { echo - echo "usage: validate-bundle -t [-n ] [-r ]" + echo "usage: validate-bundle -t [-n ] [-r ] [-d ] [--dry-run]" echo echo " Script to run Validate Tool on a bundle parallelizing across " echo " multiple cores. This script will split up the PDS4 products in " @@ -46,14 +46,29 @@ usage() echo " NOTE: Reports from all parallel executed validation" echo " runs will be output to the parent directory of" echo " this file path." + echo " -d, --dir-path Optional argument to specify the directory to output" + echo " the final summary report." + echo " --dry-run Optional argument to make a dry run to confirm the created output directory" + echo " specified in the --dir-path parameter." echo } ##### Main +dry_run_flag='false' +now_as_text=$(date +%Y%m%d_%H%M%S) PRODUCT_DIR= NUM_GROUPS= -REPORT_FILE=$(pwd)/validate_$(date +%Y%m%d_%H%M%S)/validate_summary.log +REPORT_FILE='' +REPORT_DIR='' + +# Build the unique directory where to write report files to. + +DEFAULT_UNIQUE_REPORT_DIR_STEM=validate_$now_as_text +DEFAULT_UNIQUE_REPORT_DIR_DIR='./$DEFAULT_UNIQUE_REPORT_DIR_STEM' + +# Save where the code is ran from so the default directory can be returned. +my_default_dir=$(pwd) while [ "$1" != "" ]; do case $1 in @@ -66,6 +81,12 @@ while [ "$1" != "" ]; do -r | --report-file ) shift REPORT_FILE=$1 ;; + -d | --report-dir ) shift + REPORT_DIR=$1 + ;; + --dry-run) + dry_run_flag='true' + ;; -h | --help ) usage exit ;; @@ -80,9 +101,18 @@ if [ "$PRODUCT_DIR" == "" ]; then exit 1 fi +# If the user has provided the REPORT_DIR (not a blank space), append the unique directory. +if [ $REPORT_DIR != "" ]; then + REPORT_DIR=$REPORT_DIR/$DEFAULT_UNIQUE_REPORT_DIR_STEM +fi +# If the user has not provided the REPORT_FILE (not a blank space), set to unique file beneath the default dir. +if [ "$REPORT_FILE" = "" ]; then + REPORT_FILE=$REPORT_DIR/validate_summary.log +fi # Setup the directory to run the the parallel processes RUN_DIR=$(dirname $REPORT_FILE) + mkdir -p $RUN_DIR cd $RUN_DIR @@ -118,6 +148,7 @@ else exit 1 fi + NUM_CORES=`getconf _NPROCESSORS_ONLN` HALF_CORES=$((($NUM_CORES/2))) echo " Directory to process is : ${PRODUCT_DIR}" @@ -159,6 +190,17 @@ echo " +--------------------+-----------------" # rm validate_all_files.txt +# If this is a dry run, print the directory create and exit. +if [ "$dry_run_flag" == "true" ]; then + echo "* dry_run_flag is true" + echo "* The following directory has been created: $RUN_DIR" + echo "* Variables inspection:" + echo "* REPORT_FILE = $REPORT_FILE" + echo "* RUN_DIR = $RUN_DIR" + echo "* Program exiting" + exit +fi + echo echo "Running all $NUM_GROUPS groups in parallel now..." echo @@ -205,7 +247,8 @@ echo | tee -a $REPORT_FILE echo "<<<<<<<<<<<<<<<" | tee -a $REPORT_FILE echo | tee -a $REPORT_FILE -cd .. +# Go back to where ran the code from. +cd $my_default_dir echo "Validation complete." echo "* See $RUN_DIR/$REPORT_FILE for a summary of results." @@ -213,4 +256,4 @@ echo "* See $RUN_DIR for individual Validate Tool execution reports." echo echo -exit 0 \ No newline at end of file +exit 0