-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove .sh from launcher_finder (looks cleaner)
- Loading branch information
Showing
3 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[@]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters