From c84ada445b85c569b3fdcbfc028d728e930460a7 Mon Sep 17 00:00:00 2001 From: Leviaria <113382526+Leviaria@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:45:15 +0200 Subject: [PATCH] Update emulator.py --- clashroyalebuildabot/emulator/emulator.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/clashroyalebuildabot/emulator/emulator.py b/clashroyalebuildabot/emulator/emulator.py index 69b68cd..8cedd68 100644 --- a/clashroyalebuildabot/emulator/emulator.py +++ b/clashroyalebuildabot/emulator/emulator.py @@ -6,6 +6,7 @@ import platform import socket import subprocess +import sys import threading import time import zipfile @@ -133,14 +134,35 @@ def _install_adb(): response = requests.get(adb_url, stream=True, timeout=60) response.raise_for_status() + total_size = int(response.headers.get("content-length", 0)) + downloaded_size = 0 + with open(zip_path, "wb") as file: for chunk in response.iter_content(chunk_size=1024): if chunk: file.write(chunk) + downloaded_size += len(chunk) + done = int(50 * downloaded_size / total_size) + progress_message = ( + f"\r[{'█' * done}{'.' * (50-done)}] " + f"{downloaded_size} of {total_size} bytes " + f"({downloaded_size/total_size*100:.2f}%) Downloading Platform-Tools" + ) + sys.stdout.write(progress_message) + sys.stdout.flush() + + logger.info("\nDownload completed. Extracting files...") + + with zipfile.ZipFile(zip_path, "r") as zip_ref: + zip_ref.extractall(EMULATOR_DIR) + + logger.info("Extraction completed.") with zipfile.ZipFile(zip_path, "r") as zip_ref: zip_ref.extractall(EMULATOR_DIR) + logger.info("Extraction completed.") + def __exit__(self, exc_type, exc_value, traceback): self.quit()