Skip to content

Commit

Permalink
refactor: update input and dataset handling for all other scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Oct 5, 2023
1 parent 32ce6d0 commit 12f6e06
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 83 deletions.
67 changes: 34 additions & 33 deletions bin/deploy-timelines.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
#!/bin/bash
# copy timelines to a target webserver directory

set -e
set -u
source $(dirname $0)/environ.sh

# timeline webserver directory
TIMELINEDIR=/u/group/clas/www/clas12mon/html/hipo

# input finding command
inputCmd="$TIMELINESRC/bin/set-input-dir.sh -s timeline_web"
inputCmdOpts=""

usage() {
echo """
USAGE: $0 [OPTIONS]... -d [DATASET] -t [TARGET_DIRECTORY]
=================================================================
CAUTION: READ ALL OF THIS BEFORE RUNNING !
If you really don't want to read, do a dry run using -D:
$0 -D [ARGS]...
WARNING: be careful not to overwrite anything you shouldn't
=================================================================
USAGE: $0 [OPTIONS]...
========================================================================
| CAUTION: READ ALL OF THIS GUIDE BEFORE RUNNING!
|
| If you want a quick start, try the most typical command:
| $0 -d [DATASET] -t [TARGET_DIRECTORY] -D
| This will only print what will be done; remove -D to actually run
|
| WARNING: be careful not to overwrite anything you shouldn't
========================================================================
REQUIRED OPTIONS: copy timelines for dataset [DATASET] to [TARGET_DIRECTORY]
-----------------
* Specify one or both of the following:
-d [DATASET_NAME] unique dataset name, defined by the user
default = based on [INPUT_DIR]
-i [INPUT_DIR] directory containing run subdirectories of timeline histograms
default = ./outfiles/[DATASET_NAME]/timeline_web
* Also, specify the target:
*** Specify at least one of the following:""" >&2
$inputCmd -h
echo """
*** Also, specify the target:
-t [TARGET_DIRECTORY] the top-level destination where the directory of
final timelines will be copied to
Expand All @@ -40,7 +41,6 @@ usage() {
TIMELINEDIR = $TIMELINEDIR
- use the -c option for a [TARGET_DIRECTORY] not relative to \$TIMELINEDIR
- you must have write permission to the destination directory
- when in doubt, explore \$TIMELINEDIR
- recommendations for [TARGET_DIRECTORY]:
\$LOGNAME your personal directory for testing
Expand Down Expand Up @@ -71,24 +71,25 @@ dryRun=false
customTarget=false
subDir=""
inputDir=""
while getopts "d:t:Dcs:i:" opt; do
while getopts "d:i:Ut:Dcs:" opt; do
case $opt in
d) dataset=$OPTARG ;;
d) inputCmdOpts+=" -d $OPTARG" ;;
i) inputCmdOpts+=" -i $OPTARG" ;;
U) inputCmdOpts+=" -U" ;;
t) targetDirArg=$OPTARG ;;
D) dryRun=true ;;
c) customTarget=true ;;
s) subDir=$OPTARG ;;
i) inputDir=$OPTARG ;;
*) exit 100 ;;
D) dryRun=true ;;
c) customTarget=true ;;
s) subDir=$OPTARG ;;
*) exit 100 ;;
esac
done

# check required options
[ -z "$dataset" -o -z "$targetDirArg" ] && printError "missing required options -d and -t" && usage && exit 100
# set input/output directories and dataset name
dataset=$($inputCmd $inputCmdOpts -D)
inputDir=$($inputCmd $inputCmdOpts -I)

# specify input directory
[ -z "$inputDir" ] && inputDir=$TIMELINESRC/outfiles/$dataset/timeline_web
[ ! -d $inputDir ] && printError "input timelines directory $inputDir does not exist" && exit 100
# check required options
[ -z "$dataset" -o -z "$inputDir" -o -z "$targetDirArg" ] && printError "missing one or more required options" && usage && exit 100

# specify target directory
[ -z "$subDir" ] && subDir=$dataset
Expand Down
2 changes: 1 addition & 1 deletion bin/run-detectors-timelines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if ${modes['list']}; then
exit $?
fi

# set directories and dataset name
# set input/output directories and dataset name
dataset=$($inputCmd $inputCmdOpts -D)
inputDir=$($inputCmd $inputCmdOpts -I)
[ -z "$outputDir" ] && outputDir=$(pwd -P)/outfiles/$dataset
Expand Down
56 changes: 15 additions & 41 deletions bin/run-physics-timelines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputDir=""
dataset=""
outputDir=""

# input finding command
inputCmd="$TIMELINESRC/bin/set-input-dir.sh -s timeline_physics"
inputCmdOpts=""

# usage
sep="================================================================"
if [ $# -eq 0 ]; then
Expand All @@ -18,14 +22,9 @@ if [ $# -eq 0 ]; then
$sep
Creates web-ready physics timelines locally
REQUIRED OPTIONS: specify one or both of the following:
-d [DATASET_NAME] unique dataset name, defined by the user
default = based on [INPUT_DIR]
-i [INPUT_DIR] directory containing run subdirectories of timeline histograms
default = ./outfiles/[DATASET_NAME]/timeline_physics
REQUIRED OPTIONS: specify at least one of the following:""" >&2
$inputCmd -h
echo """
OPTIONAL OPTIONS:
-o [OUTPUT_DIR] output directory
Expand All @@ -36,49 +35,24 @@ if [ $# -eq 0 ]; then
fi

# parse options
while getopts "i:d:o:" opt; do
while getopts "d:i:Uo:" opt; do
case $opt in
i)
if [ -d $OPTARG ]; then
inputDir=$(realpath $OPTARG)
else
printError "input directory $OPTARG does not exist"
exit 100
fi
;;
d)
echo $OPTARG | grep -q "/" && printError "dataset name must not contain '/' " && exit 100
[ -z "$OPTARG" ] && printError "dataset name may not be empty" && exit 100
dataset=$OPTARG
;;
o)
outputDir=$OPTARG
;;
d) inputCmdOpts+=" -d $OPTARG" ;;
i) inputCmdOpts+=" -i $OPTARG" ;;
U) inputCmdOpts+=" -U" ;;
o) outputDir=$OPTARG ;;
esac
done

# set directories and dataset name
# FIXME: copied implementation from `run-detector-timelines.sh`
if [ -z "$inputDir" -a -n "$dataset" ]; then
inputDir=$(pwd -P)/outfiles/$dataset/timeline_physics # default input directory is in ./outfiles/
elif [ -n "$inputDir" -a -z "$dataset" ]; then
dataset=$(ruby -e "puts '$inputDir'.split('/')[-4..].join('_')") # set dataset using last few subdirectories in inputDir dirname
elif [ -z "$inputDir" -a -z "$dataset" ]; then
printError "required options, either [INPUT_DIR] or [DATASET_NAME], have not been set"
exit 100
fi
# set input/output directories and dataset name
dataset=$($inputCmd $inputCmdOpts -D)
inputDir=$($inputCmd $inputCmdOpts -I)
[ -z "$outputDir" ] && outputDir=$(pwd -P)/outfiles/$dataset

# set subdirectories
finalDir=$outputDir/timeline_web
logDir=$outputDir/log

# check input directory
if [ ! -d $inputDir ]; then
printError "input directory $inputDir does not exist"
exit 100
fi

# print settings
echo """
Settings:
Expand Down
15 changes: 7 additions & 8 deletions bin/set-input-dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ set -u
source $(dirname $0)/environ.sh

# defaults
inputDir=""
subDir=""
dataset=""
datasetDefault="test_v0"
subDirDefault=""
useDefaults=false
printDatasetOnly=false
printInputDirOnly=false

# usage guide
usage() {
Expand All @@ -17,7 +22,7 @@ usage() {
default = $datasetDefault
-i [INPUT_DIR] directory containing run subdirectories of timeline histograms
default = ./outfiles/[DATASET_NAME]/$subDirDefault
default = ./outfiles/[DATASET_NAME]/$subDir
-U use the above default [DATASET_NAME] and [INPUT_DIR]""" >&2
}
Expand All @@ -39,12 +44,6 @@ if [ $# -eq 0 ]; then
fi

# parse options
inputDir=""
subDir=""
dataset=""
useDefaults=false
printDatasetOnly=false
printInputDirOnly=false
while getopts "d:i:Us:hDI" opt; do
case $opt in
d)
Expand Down

0 comments on commit 12f6e06

Please sign in to comment.