mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
download latest web client as fallback
This commit is contained in:
+38
-21
@@ -97,6 +97,36 @@ class AssetHandler:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def process_release(release: dict, path: Path):
|
||||||
|
"""
|
||||||
|
Processes a release from the GitHub API.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# INFO: find the client.zip asset
|
||||||
|
for asset in release["assets"]:
|
||||||
|
if asset["name"] == "client.zip":
|
||||||
|
# download and extract client
|
||||||
|
clientzip = requests.get(asset["browser_download_url"])
|
||||||
|
mem_file = io.BytesIO(clientzip.content)
|
||||||
|
file = zipfile.ZipFile(mem_file)
|
||||||
|
|
||||||
|
# create new dir for extraction
|
||||||
|
with tempfile.TemporaryDirectory() as temp_folder:
|
||||||
|
file.extractall(temp_folder)
|
||||||
|
|
||||||
|
shutil.copytree(
|
||||||
|
Path(temp_folder) / "client",
|
||||||
|
path,
|
||||||
|
copy_function=shutil.copy2,
|
||||||
|
dirs_exist_ok=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
log.info("Client downloaded successfully.")
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def download_client_from_github():
|
def download_client_from_github():
|
||||||
"""
|
"""
|
||||||
@@ -113,28 +143,15 @@ class AssetHandler:
|
|||||||
# INFO: find the release for the current version
|
# INFO: find the release for the current version
|
||||||
for release in releases:
|
for release in releases:
|
||||||
if release["tag_name"] == f"v{Metadata.version}":
|
if release["tag_name"] == f"v{Metadata.version}":
|
||||||
# INFO: find the client.zip asset
|
if AssetHandler.process_release(release, path):
|
||||||
for asset in release["assets"]:
|
return True
|
||||||
if asset["name"] == "client.zip":
|
pass
|
||||||
# download and extract client
|
|
||||||
clientzip = requests.get(asset["browser_download_url"])
|
|
||||||
mem_file = io.BytesIO(clientzip.content)
|
|
||||||
file = zipfile.ZipFile(mem_file)
|
|
||||||
|
|
||||||
# create new dir for extraction
|
# INFO: if no release is found, download the latest release
|
||||||
with tempfile.TemporaryDirectory() as temp_folder:
|
log.error(
|
||||||
file.extractall(temp_folder)
|
f"No release found for the v{Metadata.version}. Downloading latest version ..."
|
||||||
|
)
|
||||||
shutil.copytree(
|
return AssetHandler.process_release(releases[0], path)
|
||||||
Path(temp_folder) / "client",
|
|
||||||
path,
|
|
||||||
copy_function=shutil.copy2,
|
|
||||||
dirs_exist_ok=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
log.info("Client downloaded successfully.")
|
|
||||||
break
|
|
||||||
break
|
|
||||||
|
|
||||||
except (
|
except (
|
||||||
requests.exceptions.RequestException,
|
requests.exceptions.RequestException,
|
||||||
|
|||||||
Reference in New Issue
Block a user