Skip to content

Commit

Permalink
remove .sh from launcher_finder (looks cleaner)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmathis committed Nov 15, 2023
1 parent beb5051 commit 5a2e240
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 5 deletions.
101 changes: 101 additions & 0 deletions emmet-cli/emmet/cli/bash_scripts/launcher_finder
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

UTC() { date -u "+%Y%m%d-%H%M%S"; }

block_search () {
find "$1" -type f -name "vasprun.xml*" > "$2"

awk -F/ '{
for (i = 1; i < NF; i++) {
printf "%s", $i
if ($i ~ /block/) {
break
}
printf FS
}
print ""
}' "$2" | sort | uniq -c > "$3"
}

generate_report() {
backup=$(mktemp)
re_org=$(mktemp)
quar=$(mktemp)

exec 3>"${backup}" 5>"${re_org}" 7>"${quar}"

sep="===================================================================="

printf "%s\nBLOCKS THAT CAN BE BACKED UP:\n" "${sep}" >&3
printf "%s\nLAUNCHERS TO RE-ORG:\n" "${sep}" >&5
printf "%s\nQUARANTINED LAUNCHERS FOUND, CHECK VALIDATION:\n" "${sep}" >&7

local report="$1"
shift
local counts=("${@}")

for file in "${counts[@]}"; do
awk '/block/ { print $0 }' "${file}" >&3
awk '!/block/ { print $0 }' "${file}" >&5
awk '/quarantine/ { print $0 }' "${file}" >&7
done

if [[ -n "${report}" ]]; then
cat "${backup}" "${re_org}" "${quar}" >> "${report}"
else
cat "${backup}" "${re_org}" "${quar}"
fi

rm "${backup}" "${re_org}" "${quar}"
exec 3>&- 5>&- 7>&-
}

dir=$(pwd)
file_name=''

usage="Invocation: $(basename "$0") [-h] [-d root-directory] [-f output-file-name] -- searches for directories containing VASP files
where:
-h show this help text
-d set root directory to search for VASP files (default: PWD)
-f set output file name to store search results (default: reports directly to stdout)
If a file name is set, the file weill be stored at: root-directory/.emmet/output-file-name"

while getopts ':hd:f:v' flag; do
case "${flag}" in
h) echo "${usage}"
exit
;;
d) dir="${OPTARG}" ;;
f) file_name="${OPTARG}" ;;
*) echo "Unexpected option ${flag}"
echo "${usage}"
exit
;;
esac
done

IFS=$'\n'
dirs=($(find "${dir}" -maxdepth 1 -mindepth 1 -type d -not -path "${dir}/.emmet"))
unset IFS

search_logs=()
counts=()

for i in "${dirs[@]}"; do
mkdir -p "${i}/.emmet"
emmet="${i}/.emmet"
search_logs+=("${emmet}/emmet-launcher-search-$(UTC).txt")
counts+=("${emmet}/emmet-launcher-counts-$(UTC).txt")
done

export -f block_search

parallel --link block_search ::: "${dirs[@]}" ::: "${search_logs[@]}" ::: "${counts[@]}"

if [[ -n "${file_name}" ]]; then
mkdir -p "${dir}/.emmet"
report_file="${dir}/.emmet/${file_name}"
fi

generate_report "${report_file}" "${counts[@]}"
17 changes: 13 additions & 4 deletions emmet-cli/emmet/cli/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,18 +755,27 @@ def survey(ctx):
run = ctx.parent.parent.params["run"]
root_dir = ctx.parent.params['directory']

ts = datetime.utcnow().strftime("%y%m%d-%h%m%s")
args = shlex.split(
f"launcher_finder -d {root_dir} -f emmet-launcher-report-{ts}.txt"
)
for line in run_command(args, []):
logger.info(line.strip())

logger.info(f"launcher search results stored in {root_dir}/.emmet/")

if run:
ts = datetime.utcnow().strftime("%Y%m%d-%H%M%S")
ts = datetime.utcnow().strftime("%y%m%d-%h%m%s")
args = shlex.split(
f"launcher_finder.sh -d {root_dir} -f emmet-launcher-report-{ts}.txt"
f"launcher_finder -d {root_dir} -f emmet-launcher-report-{ts}.txt"
)
for line in run_command(args, []):
logger.info(line.strip())

logger.info(f"Launcher search results stored in {root_dir}/.emmet/")
logger.info(f"launcher search results stored in {root_dir}/.emmet/")
else:
logger.info(f"Would recursively search for directories containing VASP files in {root_dir}")
logger.info(f"Run 'launcher_finder.sh {root_dir}' if you want to search without GH issue tracking")
logger.info(f"Run 'launcher_finder {root_dir}' if you want to search without GH issue tracking")

return ReturnCodes.SUCCESS

2 changes: 1 addition & 1 deletion emmet-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
long_description_content_type="text/markdown",
url="https://github.com/materialsproject/emmet",
packages=["emmet.cli"],
scripts=["emmet/cli/bash_scripts/launcher_finder.sh"],
scripts=["emmet/cli/bash_scripts/launcher_finder"],
install_requires=[
"log4mongo",
"click",
Expand Down

0 comments on commit 5a2e240

Please sign in to comment.