Skip to content

Commit

Permalink
update: Add download logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Artrajz committed Oct 16, 2023
1 parent 0d2bc4b commit bed145e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion utils/download.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import hashlib
import tarfile
Expand All @@ -18,6 +19,7 @@ def update_to(self, b=1, bsize=1, tsize=None):


def download_file(url, dest_path):
logging.info(f"Downloading: {url}")
with TqdmUpTo(unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc=url.split('/')[-1]) as t:
urllib.request.urlretrieve(url, dest_path, reporthook=t.update_to)

Expand All @@ -37,6 +39,8 @@ def extract_file(file_path, destination=None):
if destination is None:
destination = Path(file_path).parent

logging.info(f"Extracting to {destination}")

if file_path.endswith('.zip'):
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall(destination)
Expand All @@ -50,7 +54,7 @@ def extract_file(file_path, destination=None):
with SevenZipFile(file_path, mode='r') as z:
z.extractall(destination)
else:
print(f"Unsupported compression format for file {file_path}")
logging.error(f"Unsupported compression format for file {file_path}")


def download_and_verify(urls, target_path, expected_md5=None, extract_destination=None):
Expand Down

0 comments on commit bed145e

Please sign in to comment.