's'
This commit is contained in:
@@ -25,6 +25,15 @@ def get_download_dir():
|
||||
def get_image_dir():
|
||||
return ensure_dir(IMAGE_ROOT)
|
||||
|
||||
|
||||
def file_md5(path, block_size=1024 * 1024):
|
||||
hasher = hashlib.md5()
|
||||
with open(path, "rb") as handle:
|
||||
for chunk in iter(lambda: handle.read(block_size), b""):
|
||||
hasher.update(chunk)
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
def run(args):
|
||||
result = subprocess.run(args=args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if result.stderr:
|
||||
@@ -36,23 +45,31 @@ def run(args):
|
||||
)
|
||||
return result
|
||||
|
||||
def download_file(url, f_name):
|
||||
md5 = ""
|
||||
response = requests.get(url, stream=True)
|
||||
total_size_in_bytes = int(response.headers.get('content-length', 0))
|
||||
block_size = 1024 # 1 Kibibyte
|
||||
progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True)
|
||||
with open(f_name, 'wb') as file:
|
||||
for data in response.iter_content(block_size):
|
||||
progress_bar.update(len(data))
|
||||
file.write(data)
|
||||
progress_bar.close()
|
||||
with open(f_name, "rb") as f:
|
||||
bytes = f.read()
|
||||
md5 = hashlib.md5(bytes).hexdigest()
|
||||
|
||||
def download_file(url, f_name, timeout=60):
|
||||
response = requests.get(url, stream=True, timeout=timeout)
|
||||
response.raise_for_status()
|
||||
|
||||
total_size_in_bytes = int(response.headers.get("content-length", 0))
|
||||
block_size = 1024 * 1024
|
||||
progress_bar = tqdm(total=total_size_in_bytes, unit="iB", unit_scale=True)
|
||||
hasher = hashlib.md5()
|
||||
|
||||
try:
|
||||
with open(f_name, "wb") as file:
|
||||
for data in response.iter_content(block_size):
|
||||
if not data:
|
||||
continue
|
||||
progress_bar.update(len(data))
|
||||
file.write(data)
|
||||
hasher.update(data)
|
||||
finally:
|
||||
progress_bar.close()
|
||||
response.close()
|
||||
|
||||
if total_size_in_bytes != 0 and progress_bar.n != total_size_in_bytes:
|
||||
raise ValueError("Something went wrong while downloading")
|
||||
return md5
|
||||
return hasher.hexdigest()
|
||||
|
||||
def host():
|
||||
machine = platform.machine().lower()
|
||||
|
||||
Reference in New Issue
Block a user