Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperrc committed Aug 26, 2024
2 parents 37b4cf1 + fdc744a commit 38ce7e1
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions middleware/invoke
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
# tool
#

# Copy all files from a source directory to a target directory that matches
# a specific file type suffix.
# Arg 1: The file type. e.g. md, csv, npz
# Arg 2: The source directory path.
# Arg 3: The target directory path
copyFileType () {
fileType=$1
sourceDir=$2
targetDir=$3

# Get a list of file from the source directory that has the file type
# suffix.
for file in $(find ${sourceDir} -name "*.${fileType}")
do
# Get the copy file name without the source directory path
# attached. Preserve the directory path within the source
# directory.
copyFile=$(echo ${file} | sed "s:^${sourceDir}/::")

# Get the directory name of the copyFile
copyDir=$(dirname $copyFile)

# If the directory does not exist within the target directory
# create the directory path for the copy file.
if [ ! -d ${targetDir}/${copyDir} ]; then
mkdir -p ${targetDir}/${copyDir}
fi

# Copy the file from the source directory to the target directory.
cp ${file} ${targetDir}/${copyFile}
done
}

# Get the middleware and tool directories, the tool directory will be used to copy the
# symlinks to the user directory.
middlewareDirectory=$(readlink -f $(dirname $0))
Expand All @@ -14,20 +47,26 @@ revision=$(basename $(realpath ${toolDirectory}))
# containing the links will be ${HOME}/COMPMECH
userDirectory=${HOME}/COMPMECH/${revision}

# If the user directory path does not exist, then create it.
mkdir -p ${userDirectory}

# If the user directory does not exist then create the user directory.
if [ -d ${userDirectory} ]; then
# Copy and overrid the symlinks in the user directory.
cp -sRf ${toolDirectory}/* ${userDirectory}
if [ ! -d ${userDirectory} ]; then
# Create the user directory.
mkdir -p ${userDirectory}

# Copy all files matching .md, .npz, or .csv file types.
copyFileType "md" ${toolDirectory} ${userDirectory}
copyFileType "npz" ${toolDirectory} ${userDirectory}
copyFileType "csv" ${toolDirectory} ${userDirectory}

# Copy all other file as symlinks, do not override alreadying
# exisiting hard copied files.
cp -sRf --no-clobber ${toolDirectory}/* ${userDirectory}
fi

# Invoke the start_jupyter script, look for the Jupyter files in the user
# directory containing links to the files.
/usr/bin/invoke_app "$@" -t compmech \
-C "start_jupyter --themes README.md" \
-C "start_jupyter --themes" \
-u anaconda-7 \
-w headless \
-d $userDirectory \
-d "${HOME}" \
-r none

0 comments on commit 38ce7e1

Please sign in to comment.