Обновление структуры проекта, использование pydantic для конфигураций, улучшение отчёта о патчах

This commit is contained in:
2025-10-01 23:07:37 +03:00
parent 5ba590cc31
commit fbc8b3e017
25 changed files with 406 additions and 315 deletions
+30
View File
@@ -0,0 +1,30 @@
from pydantic import BaseModel, Field, ValidationError
from rich.console import Console
from typing import Dict, Any
from pathlib import Path
import typer
class ToolsConfig(BaseModel):
apktool_jar_url: str
apktool_wrapper_url: str
class Config(BaseModel):
tools: ToolsConfig
base: Dict[str, Any]
class PatchConfig(BaseModel):
enabled: bool = Field(True, description="Включить или отключить патч")
def load_config(console: Console) -> Config:
try:
return Config.model_validate_json(Path("config.json").read_text())
except FileNotFoundError:
console.print("[red]Файл config.json не найден")
raise typer.Exit(1)
except ValidationError as e:
console.print("[red]Ошибка валидации config.json:", e)
raise typer.Exit(1)
+45
View File
@@ -0,0 +1,45 @@
from plumbum import local, ProcessExecutionError
from rich.progress import Progress
from rich.console import Console
from pathlib import Path
from typing import List
import httpx
import typer
TOOLS = Path("tools")
ORIGINAL = Path("original")
MODIFIED = Path("modified")
DECOMPILED = Path("decompiled")
PATCHES = Path("patches")
CONFIGS = Path("configs")
def ensure_dirs():
for d in [TOOLS, ORIGINAL, MODIFIED, DECOMPILED, PATCHES, CONFIGS]:
d.mkdir(exist_ok=True)
def run(console: Console, cmd: List[str], hide_output=True):
prog = local[cmd[0]][cmd[1:]]
try:
prog() if hide_output else prog & FG # type: ignore [reportUndefinedVariable]
except ProcessExecutionError as e:
console.print(f"[red]Ошибка при выполнении команды: {' '.join(cmd)}")
console.print(e.stderr)
raise typer.Exit(1)
def download(console: Console, url: str, dest: Path):
console.print(f"[cyan]Скачивание {url}{dest.name}")
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))