Исправление загрузки файлов с прогресс-баром

This commit is contained in:
2025-09-15 23:22:48 +03:00
parent c1bb2f8845
commit 5b39aec161
+16 -9
View File
@@ -75,11 +75,19 @@ def run(cmd: List[str], hide_output=True):
def download(url: str, dest: Path):
console.print(f"[cyan]Скачивание {url}{dest.name}")
with httpx.stream("GET", url, timeout=30) as r:
r.raise_for_status()
with open(dest, "wb") as f:
for chunk in r.iter_bytes():
f.write(chunk)
with httpx.Client(follow_redirects=True, timeout=60.0) as client:
with client.stream("GET", url) as response:
response.raise_for_status()
total = int(response.headers.get("Content-Length", 0))
dest.parent.mkdir(parents=True, exist_ok=True)
with open(dest, "wb") as f, Progress(console=console) as progress:
task = progress.add_task("Загрузка", total=total if total else None)
for chunk in response.iter_bytes(chunk_size=8192):
f.write(chunk)
progress.update(task, advance=len(chunk))
# ======================= INIT =========================
@@ -91,10 +99,9 @@ def init():
if not (TOOLS / "apktool.jar").exists():
download(conf.base.tools.apktool_jar_url, TOOLS / "apktool.jar")
wrapper = httpx.get(
conf.base.tools.apktool_wrapper_url, timeout=30, follow_redirects=True
).text
(TOOLS / "apktool").write_text(wrapper, encoding="utf-8")
if not (TOOLS / "apktool").exists():
download(conf.base.tools.apktool_wrapper_url, TOOLS / "apktool")
(TOOLS / "apktool").chmod(0o755)
try: