Revert "ulwgl_dl_util: fix bug for print statements"

This reverts commit 5a28836a8cb461b95be6264acbc8135f0f9645b6.
This commit is contained in:
R1kaB3rN 2024-02-19 10:23:44 -08:00
parent 5a28836a8c
commit 6fdf4f3c3d
No known key found for this signature in database

View File

@ -8,7 +8,6 @@ from http.client import HTTPSConnection, HTTPResponse, HTTPException, HTTPConnec
from ssl import create_default_context from ssl import create_default_context
from json import loads as loads_json from json import loads as loads_json
from urllib.request import urlretrieve from urllib.request import urlretrieve
from sys import stderr
def get_ulwgl_proton(env: Dict[str, str]) -> Union[Dict[str, str]]: def get_ulwgl_proton(env: Dict[str, str]) -> Union[Dict[str, str]]:
@ -22,7 +21,7 @@ def get_ulwgl_proton(env: Dict[str, str]) -> Union[Dict[str, str]]:
try: try:
files = _fetch_releases() files = _fetch_releases()
except HTTPException: except HTTPException:
print("Offline.\nContinuing ...", file=stderr) print("Offline.\nContinuing ...")
cache: Path = Path.home().joinpath(".cache/ULWGL") cache: Path = Path.home().joinpath(".cache/ULWGL")
steam_compat: Path = Path.home().joinpath(".local/share/Steam/compatibilitytools.d") steam_compat: Path = Path.home().joinpath(".local/share/Steam/compatibilitytools.d")
@ -115,12 +114,12 @@ def _fetch_proton(
proton_dir: str = proton[: proton.find(".tar.gz")] # Proton dir proton_dir: str = proton[: proton.find(".tar.gz")] # Proton dir
# TODO: Parallelize this # TODO: Parallelize this
print(f"Downloading {hash} ...", file=stderr) print(f"Downloading {hash} ...")
urlretrieve(hash_url, cache.joinpath(hash).as_posix()) urlretrieve(hash_url, cache.joinpath(hash).as_posix())
print(f"Downloading {proton} ...", file=stderr) print(f"Downloading {proton} ...")
urlretrieve(proton_url, cache.joinpath(proton).as_posix()) urlretrieve(proton_url, cache.joinpath(proton).as_posix())
print("Completed.", file=stderr) print("Completed.")
with cache.joinpath(proton).open(mode="rb") as file: with cache.joinpath(proton).open(mode="rb") as file:
if ( if (
@ -129,7 +128,7 @@ def _fetch_proton(
): ):
err: str = "Digests mismatched.\nFalling back to cache ..." err: str = "Digests mismatched.\nFalling back to cache ..."
raise ValueError(err) raise ValueError(err)
print(f"{proton}: SHA512 is OK", file=stderr) print(f"{proton}: SHA512 is OK")
_extract_dir(cache.joinpath(proton), steam_compat) _extract_dir(cache.joinpath(proton), steam_compat)
environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix() environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix()
@ -141,9 +140,9 @@ def _fetch_proton(
def _extract_dir(proton: Path, steam_compat: Path) -> None: def _extract_dir(proton: Path, steam_compat: Path) -> None:
"""Extract from the cache to another location.""" """Extract from the cache to another location."""
with tar_open(proton.as_posix(), "r:gz") as tar: with tar_open(proton.as_posix(), "r:gz") as tar:
print(f"Extracting {proton} -> {steam_compat.as_posix()} ...", file=stderr) print(f"Extracting {proton} -> {steam_compat.as_posix()} ...")
tar.extractall(path=steam_compat.as_posix()) tar.extractall(path=steam_compat.as_posix())
print("Completed.", file=stderr) print("Completed.")
def _cleanup(tarball: str, proton: str, cache: Path, steam_compat: Path) -> None: def _cleanup(tarball: str, proton: str, cache: Path, steam_compat: Path) -> None:
@ -151,13 +150,13 @@ def _cleanup(tarball: str, proton: str, cache: Path, steam_compat: Path) -> None
We want to do this when a download for a new release is interrupted We want to do this when a download for a new release is interrupted
""" """
print("Keyboard Interrupt.\nCleaning ...", file=stderr) print("Keyboard Interrupt.\nCleaning ...")
if cache.joinpath(tarball).is_file(): if cache.joinpath(tarball).is_file():
print(f"Purging {tarball} in {cache} ...", file=stderr) print(f"Purging {tarball} in {cache} ...")
cache.joinpath(tarball).unlink() cache.joinpath(tarball).unlink()
if steam_compat.joinpath(proton).is_dir(): if steam_compat.joinpath(proton).is_dir():
print(f"Purging {proton} in {steam_compat} ...", file=stderr) print(f"Purging {proton} in {steam_compat} ...")
rmtree(steam_compat.joinpath(proton).as_posix()) rmtree(steam_compat.joinpath(proton).as_posix())
@ -171,7 +170,7 @@ def _get_from_steamcompat(
proton_dir: str = files[1][0][: files[1][0].find(".tar.gz")] proton_dir: str = files[1][0][: files[1][0].find(".tar.gz")]
for proton in steam_compat.glob("ULWGL-Proton*"): for proton in steam_compat.glob("ULWGL-Proton*"):
print(f"{proton.name} found in: {steam_compat.as_posix()}", file=stderr) print(f"{proton.name} found in: {steam_compat.as_posix()}")
environ["PROTONPATH"] = proton.as_posix() environ["PROTONPATH"] = proton.as_posix()
env["PROTONPATH"] = environ["PROTONPATH"] env["PROTONPATH"] = environ["PROTONPATH"]
@ -179,8 +178,7 @@ def _get_from_steamcompat(
if proton_dir and proton.name != proton_dir: if proton_dir and proton.name != proton_dir:
print( print(
"ULWGL-Proton is outdated.\nFor latest release, please download " "ULWGL-Proton is outdated.\nFor latest release, please download "
+ files[1][1], + files[1][1]
file=stderr,
) )
return env return env
@ -216,7 +214,7 @@ def _get_from_cache(
if path: if path:
proton_dir: str = name[: name.find(".tar.gz")] # Proton dir proton_dir: str = name[: name.find(".tar.gz")] # Proton dir
print(f"{name} found in: {path}", file=stderr) print(f"{name} found in: {path}")
try: try:
_extract_dir(path, steam_compat) _extract_dir(path, steam_compat)
environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix() environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix()
@ -225,7 +223,7 @@ def _get_from_cache(
return env return env
except KeyboardInterrupt: except KeyboardInterrupt:
if steam_compat.joinpath(proton_dir).is_dir(): if steam_compat.joinpath(proton_dir).is_dir():
print(f"Purging {proton_dir} in {steam_compat} ...", file=stderr) print(f"Purging {proton_dir} in {steam_compat} ...")
rmtree(steam_compat.joinpath(proton_dir).as_posix()) rmtree(steam_compat.joinpath(proton_dir).as_posix())
raise raise
@ -240,7 +238,7 @@ def _get_latest(
When the digests mismatched or when interrupted, refer to cache for an old version When the digests mismatched or when interrupted, refer to cache for an old version
""" """
if files: if files:
print("Fetching latest release ...", file=stderr) print("Fetching latest release ...")
try: try:
_fetch_proton(env, steam_compat, cache, files) _fetch_proton(env, steam_compat, cache, files)
env["PROTONPATH"] = environ["PROTONPATH"] env["PROTONPATH"] = environ["PROTONPATH"]