Skip to content

Commit

Permalink
ulwgl_dl_util: add log.console
Browse files Browse the repository at this point in the history
- Fixes the undefined name for console_log in the CI because git didn't seem to track the new changes
  • Loading branch information
R1kaB3rN committed Mar 17, 2024
1 parent aff3640 commit bfc6d65
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions ULWGL/ulwgl_dl_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _fetch_proton(
proton, proton_url = files[1]
proton_dir: str = proton[: proton.find(".tar.gz")] # Proton dir

console_log(f"Downloading {hash} ...")
log.console(f"Downloading {hash} ...")

# Verify the scheme from Github for resources
if not proton_url.startswith("https:") or not hash_url.startswith("https:"):
Expand Down Expand Up @@ -162,7 +162,7 @@ def _fetch_proton(
err: str = f"Unable to download {proton}\ngithub.com request timed out"
raise TimeoutError(err)
except FileNotFoundError:
console_log(f"Downloading {proton} ...")
log.console(f"Downloading {proton} ...")

with urlopen(proton_url, timeout=180, context=create_default_context()) as resp: # noqa: S310
# Without Proton, the launcher will not work
Expand All @@ -176,7 +176,7 @@ def _fetch_proton(
with cache.joinpath(proton).open(mode="wb") as file:
file.write(resp.read())

console_log("Completed.")
log.console("Completed.")

with cache.joinpath(proton).open(mode="rb") as file:
if (
Expand All @@ -185,7 +185,7 @@ def _fetch_proton(
):
err: str = "Digests mismatched.\nFalling back to cache ..."
raise ValueError(err)
console_log(f"{proton}: SHA512 is OK")
log.console(f"{proton}: SHA512 is OK")

_extract_dir(cache.joinpath(proton), steam_compat)
environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix()
Expand All @@ -204,23 +204,23 @@ def _extract_dir(proton: Path, steam_compat: Path) -> None:
log.debug("Using no filter for archive")
log.warning("Archive will be extracted insecurely")

console_log(f"Extracting {proton} -> {steam_compat} ...")
log.console(f"Extracting {proton} -> {steam_compat} ...")
tar.extractall(path=steam_compat.as_posix()) # noqa: S202
console_log("Completed.")
log.console("Completed.")


def _cleanup(tarball: str, proton: str, cache: Path, steam_compat: Path) -> None:
"""Remove files that may have been left in an incomplete state to avoid corruption.
We want to do this when a download for a new release is interrupted
"""
console_log("Keyboard Interrupt.\nCleaning ...")
log.console("Keyboard Interrupt.\nCleaning ...")

if cache.joinpath(tarball).is_file():
console_log(f"Purging {tarball} in {cache} ...")
log.console(f"Purging {tarball} in {cache} ...")
cache.joinpath(tarball).unlink()
if steam_compat.joinpath(proton).is_dir():
console_log(f"Purging {proton} in {steam_compat} ...")
log.console(f"Purging {proton} in {steam_compat} ...")
rmtree(steam_compat.joinpath(proton).as_posix())


Expand All @@ -234,16 +234,16 @@ def _get_from_steamcompat(
proton_dir: str = files[1][0][: files[1][0].find(".tar.gz")]

for proton in steam_compat.glob("ULWGL-Proton*"):
console_log(f"{proton.name} found in: {steam_compat}")
console_log(f"Using {proton.name}")
log.console(f"{proton.name} found in: {steam_compat}")
log.console(f"Using {proton.name}")

environ["PROTONPATH"] = proton.as_posix()
env["PROTONPATH"] = environ["PROTONPATH"]

# Notify the user that they're not using the latest
if proton_dir and proton.name != proton_dir:
link: str = files[1][1]
console_log(
log.console(
"ULWGL-Proton is outdated.\n"
f"For latest release, please download {link}"
)
Expand Down Expand Up @@ -284,18 +284,18 @@ def _get_from_cache(
if path:
proton_dir: str = name[: name.find(".tar.gz")] # Proton dir

console_log(f"{name} found in: {path}")
log.console(f"{name} found in: {path}")
try:
_extract_dir(path, steam_compat)

console_log(f"Using {proton_dir}")
log.console(f"Using {proton_dir}")
environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix()
env["PROTONPATH"] = environ["PROTONPATH"]

return env
except KeyboardInterrupt:
if steam_compat.joinpath(proton_dir).is_dir():
console_log(f"Purging {proton_dir} in {steam_compat} ...")
log.console(f"Purging {proton_dir} in {steam_compat} ...")
rmtree(steam_compat.joinpath(proton_dir).as_posix())
raise

Expand All @@ -310,15 +310,15 @@ def _get_latest(
When the digests mismatched or when interrupted, refer to cache for an old version
"""
if files:
console_log("Fetching latest release ...")
log.console("Fetching latest release ...")

try:
tarball: str = files[1][0]
proton_dir: str = tarball[: tarball.find(".tar.gz")] # Proton dir

_fetch_proton(env, steam_compat, cache, files)

console_log(f"Using {proton_dir}")
log.console(f"Using {proton_dir}")
env["PROTONPATH"] = environ["PROTONPATH"]
except ValueError:
log.exception("Exception")
Expand Down

0 comments on commit bfc6d65

Please sign in to comment.