From ab1119c25b952c99c743078fa32d9c7922edbc28 Mon Sep 17 00:00:00 2001 From: "yaoyy.hi" <> Date: Wed, 23 Nov 2022 11:07:06 +0800 Subject: [PATCH] update download_weights.sh to suppress download failure --- scripts/download_weights.sh | 51 +++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/scripts/download_weights.sh b/scripts/download_weights.sh index e5768f75..6584d314 100644 --- a/scripts/download_weights.sh +++ b/scripts/download_weights.sh @@ -1,7 +1,7 @@ #! /bin/sh # Usage: bash /esm/scripts/download_weights.sh /path/to/weights/ # re run the command to continue downloading incomplete files. - +echo $0 run_dir=$(readlink -f $(dirname $0)) ; if [[ "$(which aria2c)" == "" ]];then @@ -9,6 +9,15 @@ if [[ "$(which aria2c)" == "" ]];then exit 1 fi +for _sh_exec in /bin/sh bash zsh;do + # only bash and zsh are tested. + _sh_exec=$(which ${_sh_exec}) + if [[ "$(${_sh_exec} --version)" =~ "bash" || "$(${_sh_exec} --version)" =~ "zsh" ]];then + echo $(which ${_sh_exec}); + break + fi +done + model_pth=$1 if [[ "$model_pth" == "" ]];then model_pth=$PWD @@ -18,24 +27,34 @@ mkdir -p $model_pth/checkpoints pushd $model_pth/checkpoints cat $run_dir/../README.md |grep -e '^|' |grep -e 'fair-esm/models' |tr -d '|' | \ - awk '{ - # read urls started with https - split($0,arr,"https"); - url="https"arr[2]; - print url; + awk 'BEGIN{print "set -e"}; + { + # read urls starts with https + split($0,arr,"https"); + url="https"arr[2]; + + # remove blank spaces after url string + split(url,url_arr," ") + url=url_arr[1] + + # guessing regression pt url + url_regression=url; + sub("models","regression",url_regression); + sub(".pt","-contact-regression.pt",url_regression); + + # downloading weight + url_basename_idx=split(url,url_arr,"/") + url_basename=url_arr[url_basename_idx] + print "if [[ ! -f "url_basename" || -f "url_basename".aria2 ]];then echo Download not complete: "url_basename";aria2c -x 10 "url";else echo Download complete: "url_basename";fi" - # inspect regression pt url - url_regression=url; - sub("models","regression",url_regression); - sub(".pt","-contact-regression.pt",url_regression); - print url_regression; + # downloading regression, if not existing and through an error, we just ignore it. + url_regression_basename_idx=split(url_regression,url_arr,"/") + url_regression_basename=url_arr[url_regression_basename_idx] + print "if [[ ! -f "url_regression_basename" || -f "url_regression_basename".aria2 ]];then echo Download not complete: "url_regression_basename";aria2c -x 10 "url_regression" 2>/dev/null || echo Never mind. "url_regression_basename" may not exist. ;else echo Download complete: "url_regression_basename";fi" - # download weight - system("if [[ ! -f $(basename "url") || -f $(basename "url").aria2 ]];then echo Download not complete: $(basename "url");aria2c -x 10 "url";else echo Download complete: $(basename "url");fi") + }' |$_sh_exec - # download regression - system("if [[ ! -f $(basename "url_regression") || -f $(basename "url_regression").aria2 ]];then echo Download not complete: $(basename "url_regression");aria2c -x 10 "url_regression";else echo Download complete: $(basename "url_regression");fi") - }' +echo "Your model directory is located at \`$(readlink -f ${model_pth})\`." popd \ No newline at end of file