external assets for thesis now handled more robustly

we can now find all external.assets file in the entire assets/ tree
also copy operation does not overwrite
master
Taha Ahmed 4 years ago
parent 0109401636
commit 52f8fb5ea8

@ -30,7 +30,12 @@ else
echo "--- This job did not request LaTeXMK RC file" echo "--- This job did not request LaTeXMK RC file"
fi fi
# define some commands # define some constants
path_wd=${PWD}
dir_wd=$(basename $path_wd)
path_thesis="/media/bay/taha/chepec/thesis"
# define some file types
Rfiletype="R" Rfiletype="R"
TeXfiletype="tex" TeXfiletype="tex"
tikzfiles="*.tikz" tikzfiles="*.tikz"
@ -120,30 +125,23 @@ if [ $# -eq 1 ]; then
fi fi
#### Special treatment for thesis #### Special treatment for thesis
if [[ ${PWD} == "/media/bay/taha/chepec/thesis" && $jobname == "thesis" ]]; then if [[ $path_wd == "$path_thesis" && $jobname == "$dir_wd" ]]; then
# Fetch external assets by reading any assets.external files in assets/ tree # Fetch external assets by reading any assets.external files in assets/ tree
# NOTE: be careful NOT to leave empty lines in your assets.external files # NOTE: be careful NOT to leave empty lines in your assets.external files
echo "<thesis> -------------------------------" echo "<thesis> -------------------------------"
echo "<thesis> Getting external assets" echo "<thesis> Getting external assets"
echo "<thesis> -------------------------------" echo "<thesis> -------------------------------"
# summary of operations in this if-clause: # find all files named "assets.external" in the assets/ tree
# trawl the assets/ subdirectories looking for a file "external.assets", if found, assetsexternalfiles=$(find "$path_wd/assets/" -type f -name "assets.external")
# read its contents line-by-line (each line is a path) and copy that file at that path to the current assets/ subdir for externalfilepath in $assetsexternalfiles; do
# note that we only look for assets.external inside the subdirectories, and not in assets/ itself # this weird-looking while-loop reads the assets.external file line-by-line and copies each asset into the target path inside the thesis' assets/ tree
assetsubdirectories="$(find /media/bay/taha/chepec/thesis/assets/ -maxdepth 1 -mindepth 1 -type d)" # https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable
# loop through $assetdirs, and look for the file external.assets in each path while IFS='' read -r asset || [[ -n "$asset" ]]; do
for assetdir in $assetsubdirectories; do assetpathtarget=$(dirname "$externalfilepath")
assetfilename="assets.external" echo "Copying $asset to $assetpathtarget"
if [ -e ${assetdir}/${assetfilename} ]; then # cp but don't overwwrite existing files
# https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable cp --preserve=timestamps --no-clobber $asset $assetpathtarget
# $assets is the current assets.external file done < "$externalfilepath"
assets="${assetdir}/${assetfilename}"
while IFS='' read -r asset || [[ -n "$asset" ]]; do
echo "$asset"
# copy this filepath into the current assets subdirectory
cp --preserve=timestamps $asset $assetdir
done < "$assets"
fi
done done
# Create low-res photos on-the-fly from existing photos/ # Create low-res photos on-the-fly from existing photos/
@ -157,15 +155,15 @@ if [ $# -eq 1 ]; then
# rsync can't do that. We need to use a different tool. See e.g. # rsync can't do that. We need to use a different tool. See e.g.
# https://superuser.com/questions/260092/rsync-switch-to-only-compare-timestamps # https://superuser.com/questions/260092/rsync-switch-to-only-compare-timestamps
# copy only the "large" photos that have file modtimes more recent than the last time this operation was run # copy only the "large" photos that have file modtimes more recent than the last time this operation was run
photoslastrun="/media/bay/taha/chepec/thesis/assets/photos/.lowres/lastrun" photoslastrun="$path_wd/assets/photos/.lowres/lastrun"
if [ ! -f "$photoslastrun" ]; then if [ ! -f "$photoslastrun" ]; then
# if, for some reason, the lastrun file does not exist # if, for some reason, the lastrun file does not exist
# copy over everything and then create the file # copy over everything and then create the file
rsync -av /media/bay/taha/chepec/thesis/assets/photos/* /media/bay/taha/chepec/thesis/assets/photos/.lowres/ --exclude /media/bay/taha/chepec/thesis/assets/photos/.lowres/ rsync -av "$path_wd/assets/photos/*" "$path_wd/assets/photos/.lowres/" --exclude "$path_wd/assets/photos/.lowres/"
touch "$photoslastrun" touch "$photoslastrun"
fi fi
# cd and use --parents arg to preserve directory structure in .lowres target # cd and use --parents arg to preserve directory structure in .lowres target
cd /media/bay/taha/chepec/thesis/assets/photos cd "$path_wd/assets/photos"
newphotos="$(find . -type f -cnewer $photoslastrun ! -path './.lowres/*')" newphotos="$(find . -type f -cnewer $photoslastrun ! -path './.lowres/*')"
if [ -n "$newphotos" ]; then if [ -n "$newphotos" ]; then
for newphoto in $newphotos; do for newphoto in $newphotos; do
@ -175,7 +173,7 @@ if [ $# -eq 1 ]; then
# revert the effects of cd above. Redirect to null suppresses the output. # revert the effects of cd above. Redirect to null suppresses the output.
cd - >/dev/null cd - >/dev/null
# in the low-res tree, find any photo larger than specific size (500kB) # in the low-res tree, find any photo larger than specific size (500kB)
largephotos="$(find /media/bay/taha/chepec/thesis/assets/photos/.lowres/ -size +500k)" largephotos="$(find $path_wd/assets/photos/.lowres/ -size +500k)"
for largephotofilename in $largephotos; do for largephotofilename in $largephotos; do
# for the next statement to work reliably, we should probably convert other formats to JPEG # for the next statement to work reliably, we should probably convert other formats to JPEG
# detect file extension, and based on it, convert to jpg using mogrify # detect file extension, and based on it, convert to jpg using mogrify
@ -299,8 +297,8 @@ else
# exit 1 # exit 1
# fi # fi
#else #else
# # There is exactly one *.Rnw file is current directory ## There is exactly one *.Rnw file is current directory
# # Fetch the jobname from the .Rnw filename by stripping off the file extension ## Fetch the jobname from the .Rnw filename by stripping off the file extension
# Rnwfilename=$(ls -1 $Rnwfiles) # Rnwfilename=$(ls -1 $Rnwfiles)
# jobname=${Rnwfilename%.*} # jobname=${Rnwfilename%.*}
#fi #fi
@ -407,9 +405,7 @@ runtime=$(( $endtime - $starttime ))
# send push message via Gotify CLI # send push message via Gotify CLI
# if runtime is longer than X minutes (suitable limit perhaps 3 min) # if runtime is longer than X minutes (suitable limit perhaps 3 min)
if (( $runtime > 180 )); then if (( $runtime > 180 )); then
# cwd is the current directory (basename) gotify push --quiet --title "$dir_wd" --priority 5 "chertex.sh $@ \nCompleted in $runtime s"
cwd=$(basename $PWD)
gotify push --quiet --title "$cwd" --priority 5 "chertex.sh $@ \nCompleted in $runtime s"
fi fi
echo "-------------------------------------" echo "-------------------------------------"

Loading…
Cancel
Save