forked from anixart-mod/patcher
Исправление загрузки файлов с прогресс-баром
This commit is contained in:
@@ -75,11 +75,19 @@ def run(cmd: List[str], hide_output=True):
|
|||||||
|
|
||||||
def download(url: str, dest: Path):
|
def download(url: str, dest: Path):
|
||||||
console.print(f"[cyan]Скачивание {url} → {dest.name}")
|
console.print(f"[cyan]Скачивание {url} → {dest.name}")
|
||||||
with httpx.stream("GET", url, timeout=30) as r:
|
|
||||||
r.raise_for_status()
|
with httpx.Client(follow_redirects=True, timeout=60.0) as client:
|
||||||
with open(dest, "wb") as f:
|
with client.stream("GET", url) as response:
|
||||||
for chunk in r.iter_bytes():
|
response.raise_for_status()
|
||||||
f.write(chunk)
|
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 =========================
|
# ======================= INIT =========================
|
||||||
@@ -91,10 +99,9 @@ def init():
|
|||||||
|
|
||||||
if not (TOOLS / "apktool.jar").exists():
|
if not (TOOLS / "apktool.jar").exists():
|
||||||
download(conf.base.tools.apktool_jar_url, TOOLS / "apktool.jar")
|
download(conf.base.tools.apktool_jar_url, TOOLS / "apktool.jar")
|
||||||
wrapper = httpx.get(
|
|
||||||
conf.base.tools.apktool_wrapper_url, timeout=30, follow_redirects=True
|
if not (TOOLS / "apktool").exists():
|
||||||
).text
|
download(conf.base.tools.apktool_wrapper_url, TOOLS / "apktool")
|
||||||
(TOOLS / "apktool").write_text(wrapper, encoding="utf-8")
|
|
||||||
(TOOLS / "apktool").chmod(0o755)
|
(TOOLS / "apktool").chmod(0o755)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user