From d782e5f2af45d0296cca4f085bff1cb6a542d5a1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 24 Apr 2021 15:53:15 +0200 Subject: [PATCH] Update download() for tar.gz files (#2919) * Update download() for tar.gz files * Update general.py (cherry picked from commit 45632b27049734e5c73289b10d90a5dc7c2dd6f3) --- utils/general.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/utils/general.py b/utils/general.py index 64fd524e16b7..e8ed792d4044 100644 --- a/utils/general.py +++ b/utils/general.py @@ -187,14 +187,19 @@ def check_dataset(dict): def download(url, dir='.', multi_thread=False): - # Multi-threaded file download function + # Multi-threaded file download and unzip function def download_one(url, dir): # Download 1 file f = dir / Path(url).name # filename - print(f'Downloading {url} to {f}...') - torch.hub.download_url_to_file(url, f, progress=True) # download - if f.suffix == '.zip': - os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite + if not f.exists(): + print(f'Downloading {url} to {f}...') + torch.hub.download_url_to_file(url, f, progress=True) # download + if f.suffix in ('.zip', '.gz'): + print(f'Unzipping {f}...') + if f.suffix == '.zip': + os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite + elif f.suffix == '.gz': + os.system(f'tar xfz {f} --directory {f.parent} && rm {f}') # unzip dir = Path(dir) dir.mkdir(parents=True, exist_ok=True) # make directory