From 9cb18a26c43d7044264d53e211da070a0415704e Mon Sep 17 00:00:00 2001 From: tretrauit Date: Sat, 17 Jun 2023 09:18:09 +0700 Subject: [PATCH] feat: add re-exports --- vollerei/hsr/__init__.py | 6 ++++++ vollerei/hsr/launcher/__init__.py | 5 +++++ vollerei/utils/git/__init__.py | 31 ++++++++++++++++++++++-------- vollerei/utils/xdelta3/__init__.py | 2 +- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/vollerei/hsr/__init__.py b/vollerei/hsr/__init__.py index e69de29..bbe083c 100644 --- a/vollerei/hsr/__init__.py +++ b/vollerei/hsr/__init__.py @@ -0,0 +1,6 @@ +# Re-exports +from vollerei.hsr.patcher import Patcher +from vollerei.hsr.launcher import Game, GameChannel + + +__all__ = ["Patcher", "Game", "GameChannel"] diff --git a/vollerei/hsr/launcher/__init__.py b/vollerei/hsr/launcher/__init__.py index e69de29..daa8244 100644 --- a/vollerei/hsr/launcher/__init__.py +++ b/vollerei/hsr/launcher/__init__.py @@ -0,0 +1,5 @@ +# Re-exports +from vollerei.hsr.launcher.game import Game, GameChannel + + +__all__ = ["Game", "GameChannel"] diff --git a/vollerei/utils/git/__init__.py b/vollerei/utils/git/__init__.py index ea280f7..655559c 100644 --- a/vollerei/utils/git/__init__.py +++ b/vollerei/utils/git/__init__.py @@ -1,12 +1,13 @@ +from io import BytesIO import subprocess +from zipfile import ZipFile import requests import json from pathlib import Path from shutil import which, rmtree from urllib.parse import urlparse -from vollerei.constants import utils_cache_path +from vollerei.paths import utils_cache_path from vollerei.utils.git.exceptions import GitCloneError -from vollerei.utils import download_and_extract class Git: @@ -36,7 +37,7 @@ class Git: """ Check if the url is a Gitea server """ - rsp = requests.get(f"https://{netloc}/api/v1/meta") + rsp = requests.get(f"https://{netloc}/api/v1/version") try: data: dict = rsp.json() except json.JSONDecodeError: @@ -61,7 +62,15 @@ class Git: return data[0]["sha"] def _download_and_extract_zip(self, url: str, path: Path) -> None: - download_and_extract(url, path) + # Copied code so it doesn't depend on vollerei.utils.download_and_extract + rsp = requests.get(url, stream=True) + rsp.raise_for_status() + with BytesIO() as f: + for chunk in rsp.iter_content(chunk_size=32768): + f.write(chunk) + f.seek(0) + with ZipFile(f) as z: + z.extractall(path) path.joinpath(".git/PLEASE_INSTALL_GIT").touch() def _clone(self, url: str, path: str = None) -> None: @@ -91,8 +100,7 @@ class Git: else: raise NotImplementedError - def get_latest_release_dl(self, url: str) -> list[str]: - dl = [] + def get_latest_release(self, url: str) -> dict: if Path(url).suffix == ".git": url = url[:-4] url_info = urlparse(url) @@ -103,11 +111,18 @@ class Git: ) rsp.raise_for_status() data = rsp.json() - for asset in data["assets"]: - dl.append(asset["browser_download_url"]) + return data else: raise NotImplementedError + def get_latest_release_dl(self, data: dict) -> list[str]: + dl = [] + if not data.get("assets"): + return dl + for asset in data["assets"]: + dl.append(asset["browser_download_url"]) + return dl + def pull_or_clone(self, url: str, path: str = None) -> None: """ Pulls or clones a git repository diff --git a/vollerei/utils/xdelta3/__init__.py b/vollerei/utils/xdelta3/__init__.py index 9dcc04d..cbe8af3 100644 --- a/vollerei/utils/xdelta3/__init__.py +++ b/vollerei/utils/xdelta3/__init__.py @@ -4,7 +4,7 @@ import requests from os import PathLike from zipfile import ZipFile from shutil import which -from vollerei.constants import tools_cache_path +from vollerei.paths import tools_cache_path from vollerei.utils.xdelta3.exceptions import ( Xdelta3NotInstalledError, Xdelta3PatchError,