foamCloneCase: added -template option to search for source cases
in template directory paths, e.g. $FOAM_ETC/templates.
Earlier commit (f414afba2c) copies
scripts and 0.orig by default if present.
This commit is contained in:
@ -41,13 +41,17 @@ options:
|
|||||||
-latestTime clone the latest time directory
|
-latestTime clone the latest time directory
|
||||||
-no-orig do not copy 0.orig directory
|
-no-orig do not copy 0.orig directory
|
||||||
-no-scripts do not copy shell scripts
|
-no-scripts do not copy shell scripts
|
||||||
|
-template search for source case directory in template directory paths
|
||||||
|
|
||||||
Create a new <targetCase> case directory that includes time, system and constant
|
Create a new <targetCase> case directory that includes time, system and constant
|
||||||
directories, and shell scripts, of <sourceCase> directory.
|
directories, and shell scripts, of <sourceCase> directory.
|
||||||
The time directory is the first time directory by default. If no time directory
|
The time directory is the first time directory by default. If no time directory
|
||||||
exists, or it is 0, an exitsting 0.orig directory is copied by default.
|
exists, or it is 0, an exitsting 0.orig directory is copied by default.
|
||||||
|
|
||||||
|
Template directory paths are:
|
||||||
USAGE
|
USAGE
|
||||||
|
for _tp in $TEMPLATE_DIRS ; do echo " $_tp" ; done
|
||||||
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
@ -61,9 +65,28 @@ cpIfPresent() {
|
|||||||
[ -e "$1" ] && echo "... ${1##*/}" && cp -r "$1" "$2"
|
[ -e "$1" ] && echo "... ${1##*/}" && cp -r "$1" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ver=$WM_PROJECT_VERSION
|
||||||
|
tmp_dir=templates
|
||||||
|
TEMPLATE_DIRS="
|
||||||
|
${HOME}/.OpenFOAM/appTemplates/$ver
|
||||||
|
${HOME}/.OpenFOAM/$ver/$tmp_dir
|
||||||
|
${HOME}/.OpenFOAM/$tmp_dir
|
||||||
|
${WM_PROJECT_SITE:-$WM_PROJECT_INST_DIR/site}/$ver/$tmp_dir
|
||||||
|
${WM_PROJECT_SITE:-$WM_PROJECT_INST_DIR/site}/$tmp_dir
|
||||||
|
$WM_PROJECT_DIR/etc/$tmp_dir"
|
||||||
|
|
||||||
|
templateDir() {
|
||||||
|
for t in $TEMPLATE_DIRS
|
||||||
|
do
|
||||||
|
[ -d "$t/$1" ] && echo "$t/$1" && exit 0
|
||||||
|
done
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
time_option="head -1"
|
time_option="head -1"
|
||||||
no_orig=""
|
no_orig=""
|
||||||
no_scripts=""
|
no_scripts=""
|
||||||
|
template=""
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
@ -84,6 +107,10 @@ do
|
|||||||
no_scripts="true"
|
no_scripts="true"
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
|
-template)
|
||||||
|
template="true"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
-*)
|
-*)
|
||||||
error "unknown option: '$*'"
|
error "unknown option: '$*'"
|
||||||
;;
|
;;
|
||||||
@ -94,29 +121,38 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
[ $# -eq 2 ] || error "Incorrect arguments specified"
|
[ $# -eq 2 ] || error "Incorrect arguments specified"
|
||||||
foamListTimes -case "$1" >/dev/null 2>&1 || \
|
|
||||||
error "'$1' is not a valid case directory"
|
|
||||||
|
|
||||||
[ -e "$2" ] && error "'$2' file/directory already exists, delete and re-run"
|
srcDir="$1"
|
||||||
|
[ -z "$template" ] || \
|
||||||
|
srcDir="$(templateDir "$1")" || \
|
||||||
|
error "'$1' not found in template directories"
|
||||||
|
|
||||||
echo "Making $2 case directory"
|
foamListTimes -case "$srcDir" >/dev/null 2>&1 || \
|
||||||
mkdir "$2"
|
error "'$srcDir' is not a valid case directory"
|
||||||
|
|
||||||
echo "Copying directories from $1 to $2:"
|
tgtDir=$2
|
||||||
cpIfPresent "$1/system" "$2"
|
|
||||||
cpIfPresent "$1/constant" "$2"
|
|
||||||
|
|
||||||
time_dir="$(foamListTimes -withZero -case "$1" | $time_option)"
|
[ -e "$tgtDir" ] && \
|
||||||
cpIfPresent "$1/${time_dir}" "$2"
|
error "'$tgtDir' file/directory already exists, delete and re-run"
|
||||||
|
|
||||||
|
echo "Making $tgtDir case directory"
|
||||||
|
mkdir "$tgtDir"
|
||||||
|
|
||||||
|
echo "Copying directories from $srcDir to $tgtDir:"
|
||||||
|
cpIfPresent "$srcDir/system" "$tgtDir"
|
||||||
|
cpIfPresent "$srcDir/constant" "$tgtDir"
|
||||||
|
|
||||||
|
time_dir="$(foamListTimes -withZero -case "$srcDir" | $time_option)"
|
||||||
|
cpIfPresent "$srcDir/${time_dir}" "$tgtDir"
|
||||||
|
|
||||||
[ "${time_dir}" = "0" -o -z "${time_dir}" ] && [ -z "$no_orig" ] && \
|
[ "${time_dir}" = "0" -o -z "${time_dir}" ] && [ -z "$no_orig" ] && \
|
||||||
cpIfPresent "$1/0.orig" "$2"
|
cpIfPresent "$srcDir/0.orig" "$tgtDir"
|
||||||
|
|
||||||
[ "$no_scripts" ] || \
|
[ "$no_scripts" ] || \
|
||||||
scripts="$(find "$1" -maxdepth 1 -type f -exec file {} \; | \
|
scripts="$(find "$srcDir" -maxdepth 1 -type f -exec file {} \; | \
|
||||||
grep "shell script" | \
|
grep "shell script" | \
|
||||||
cut -d: -f1)"
|
cut -d: -f1)"
|
||||||
[ "$scripts" ] && echo "Copying scripts from $1 to $2:" && \
|
[ "$scripts" ] && echo "Copying scripts from $srcDir to $tgtDir:" && \
|
||||||
for s in $scripts ; do cpIfPresent "$s" "$2" ; done
|
for s in $scripts ; do cpIfPresent "$s" "$tgtDir" ; done
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user