fixed ttsdk, again.
Some checks failed
Build-nightly / docker (push) Has been cancelled

This commit is contained in:
Umiko 2025-05-18 09:21:27 +07:00
parent 2d513bbcab
commit 776fb7da75

View File

@ -9,40 +9,45 @@ import platform
import shutil
import sys
# Setup path
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.dirname(path)
sys.path.append(path)
import downloader
url = "https://bearware.dk/teamtalksdk"
def get_url_suffix_from_platform() -> str:
machine = platform.machine()
if sys.platform == "win32":
architecture = platform.architecture()
if machine in ["AMD64", "x86"]:
return "win64" if architecture[0] == "64bit" else "win32"
if machine == "AMD64" or machine == "x86":
if architecture[0] == "64bit":
return "win64"
else:
return "win32"
else:
sys.exit("Native Windows on ARM is not supported.")
sys.exit("Native Windows on ARM is not supported")
elif sys.platform == "darwin":
sys.exit("macOS is not supported.")
sys.exit("Darwin is not supported")
else:
if machine in ["AMD64", "x86_64"]:
return "ubuntu18_x86_64"
if machine == "AMD64" or machine == "x86_64":
return "ubuntu22_x86_64"
elif "arm" in machine:
return "raspbian_armhf"
else:
sys.exit("Your system architecture is not supported.")
sys.exit("Your architecture is not supported")
def download() -> None:
headers = {'User-Agent': 'Mozilla/5.0'}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
r = requests.get(url, headers=headers)
page = bs4.BeautifulSoup(r.text, features="html.parser")
# The last tested version series is v5.15x
versions = page.find_all("li")
version = [i for i in versions if "5.12" in i.text][-1].a.get("href")[0:-1]
version = [i for i in versions if "5.15" in i.text][-1].a.get("href")[0:-1]
download_url = (
url
+ "/"
@ -50,7 +55,7 @@ def download() -> None:
+ "/"
+ "tt5sdk_{v}_{p}.7z".format(v=version, p=get_url_suffix_from_platform())
)
print("Downloading from: " + download_url)
print("Downloading from " + download_url)
downloader.download_file(download_url, os.path.join(os.getcwd(), "ttsdk.7z"))
@ -61,51 +66,32 @@ def extract() -> None:
shutil.rmtree(os.path.join(os.getcwd(), "ttsdk"))
os.mkdir(os.path.join(os.getcwd(), "ttsdk"))
patoolib.extract_archive(
os.path.join(os.getcwd(), "ttsdk.7z"),
outdir=os.path.join(os.getcwd(), "ttsdk")
os.path.join(os.getcwd(), "ttsdk.7z"), outdir=os.path.join(os.getcwd(), "ttsdk")
)
def move() -> None:
sdk_root = os.path.join(os.getcwd(), "ttsdk")
contents = os.listdir(sdk_root)
if not contents:
raise RuntimeError("SDK extraction failed: 'ttsdk/' folder is empty.")
for entry in contents:
entry_path = os.path.join(sdk_root, entry)
if os.path.isdir(entry_path) and os.path.isdir(os.path.join(entry_path, "Library")):
path = entry_path
break
else:
raise RuntimeError("No 'Library' folder found in extracted SDK.")
path = os.path.join(os.getcwd(), "ttsdk", os.listdir(os.path.join(os.getcwd(), "ttsdk"))[0])
libraries = ["TeamTalk_DLL", "TeamTalkPy"]
dest_dir = os.path.join(os.getcwd(), os.pardir) if os.path.basename(os.getcwd()) == "tools" else os.getcwd()
for library in libraries:
src = os.path.join(path, "Library", library)
dst = os.path.join(dest_dir, library)
if not os.path.exists(src):
print(f"WARNING: {library} not found.")
continue
try:
os.rename(src, dst)
os.rename(
os.path.join(path, "Library", library), os.path.join(dest_dir, library)
)
except OSError:
if os.path.exists(dst):
shutil.rmtree(dst)
os.rename(src, dst)
license_path = os.path.join(path, "License.txt")
dst_license = os.path.join(dest_dir, "TTSDK_license.txt")
if os.path.exists(license_path):
if os.path.exists(dst_license):
os.remove(dst_license)
os.rename(license_path, dst_license)
shutil.rmtree(os.path.join(dest_dir, library))
os.rename(
os.path.join(path, "Library", library), os.path.join(dest_dir, library)
)
try:
os.rename(
os.path.join(path, "License.txt"), os.path.join(dest_dir, "TTSDK_license.txt")
)
except FileExistsError:
os.remove(os.path.join(dest_dir, "TTSDK_license.txt"))
os.rename(
os.path.join(path, "License.txt"), os.path.join(dest_dir, "TTSDK_license.txt")
)
def clean() -> None:
@ -114,18 +100,17 @@ def clean() -> None:
def install() -> None:
print("Starting TeamTalk SDK installation...")
print("Downloading the latest SDK version...")
print("Installing TeamTalk sdk components")
print("Downloading latest sdk version")
download()
print("Download complete. Extracting...")
print("Downloaded. extracting")
extract()
print("Extraction complete. Moving files...")
print("Extracted. moving")
move()
print("Move complete. Cleaning up...")
print("moved. cleaning")
clean()
print("Cleanup done.")
print("TeamTalk SDK successfully installed.")
print("cleaned.")
print("Installed, exiting.")
if __name__ == "__main__":
install()