more refactoring , more unit tests...sigh

This commit is contained in:
Microchip
2026-09-26 13:59:56 -04:00
parent b5a40903ff
commit 8ed33d52e3
14 changed files with 2092 additions and 516 deletions
+57 -1
View File
@@ -4,7 +4,10 @@ import shutil
import subprocess
import sys
from pathlib import Path
import hashlib
import platform
#from .config import APP_DATA_DIR, DOWNLOAD_TIMEOUT, ensure_dir
from .app_log import log
# Windows: %LOCALAPPDATA%\octo-updater\
@@ -143,4 +146,57 @@ def display_info() -> dict:
# NOTE: Returns a path to an aria2c executable , otherwise returns none
def find_aria2c() -> str | None:
return shutil.which("aria2c")
# NOTE: Function that installs the exe for aria2c on windows devices, takes path as input , returns
# path to aria2c exe
def install_aria2c_windows( APP_DATA_DIR,
ALLOWED_DOWNLOAD_HOSTS,
log_fn) -> Path:
ARIA2C_PATH = os.path.join(APP_DATA_DIR, "aria2c.exe")
ARIA2_ZIP_SHA256 = "35f6514cc5dd7e98a87b3c4c2d25a0754b9b063dbe59bc0f22d483464f61e5b6"
ARIA2_ZIP_URL = (
"https://github.com/aria2/aria2/releases/download/"
"release-1.37.0/aria2-1.37.0-win-32bit-build1.zip"
)
#req = urllib.request.Request(ARIA2_ZIP_URL, headers={"User-Agent": UA})
req = urllib.request.Request(ARIA2_ZIP_URL)
log_fn("Fetching aria2c (one-time, ~2.5 MB)…", "acct")
with secure_urlopen(req, timeout=60, allowed_hosts=ALLOWED_DOWNLOAD_HOSTS) as r:
data = r.read()
digest = hashlib.sha256(data).hexdigest()
if digest != ARIA2_ZIP_SHA256:
raise RuntimeError(
f"aria2 checksum mismatch (got {digest[:12]}…); refusing to run it")
import zipfile, io
with zipfile.ZipFile(io.BytesIO(data)) as zf:
name = next((n for n in zf.namelist()
if n.lower().endswith("aria2c.exe")), None)
if not name:
raise RuntimeError("aria2c.exe not found in the aria2 archive")
exe = zf.read(name)
ensure_dir(APP_DATA_DIR)
tmp = ARIA2C_PATH + ".part"
with open(tmp, "wb") as f:
f.write(exe)
os.replace(tmp, ARIA2C_PATH)
log_fn("aria2c ready.", "ok")
return ARIA2C_PATH