2023-11-01 12:33:19 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
|
2023-11-02 12:50:29 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
import util
|
2023-08-31 14:53:59 +02:00
|
|
|
from pathlib import Path
|
2023-11-02 12:50:29 +01:00
|
|
|
import defines
|
|
|
|
import util
|
2023-08-31 14:53:59 +02:00
|
|
|
|
2023-11-16 09:41:11 +01:00
|
|
|
def download_godot(exe_zip_filename: str, export_templates: str, download_destination_path: str) -> bool:
|
|
|
|
# https://github.com/godotengine/godot-builds/releases/download/4.2-beta6/Godot_v4.2-beta6_win64.exe.zip
|
|
|
|
subfolder = f"{defines.GODOT_VERSION}-{defines.GODOT_RELEASE_TYPE}"
|
|
|
|
base_url = f"{defines.GODOT_DOWNLOAD_SERVER}/{subfolder}"
|
|
|
|
|
|
|
|
download_export_templates = f"{base_url}/{export_templates}"
|
2023-11-02 12:50:29 +01:00
|
|
|
exe_destination_filepath = os.path.join(
|
|
|
|
download_destination_path, exe_zip_filename)
|
|
|
|
export_templates_destination_path = os.path.join(
|
|
|
|
download_destination_path, export_templates)
|
2023-08-31 14:53:59 +02:00
|
|
|
|
2023-11-16 09:41:11 +01:00
|
|
|
# Godot adds ".stable" to the folder names for full releases: "AppData/Roaming/Godot/templates/4.2.stable":
|
|
|
|
download_editor = f"{base_url}/{exe_zip_filename}"
|
|
|
|
print(f"⬇️ Downloading Godot editor {download_editor}")
|
|
|
|
util.download(download_editor, exe_destination_filepath, False)
|
|
|
|
print(f"⬇️ Downloading Godot export templates {download_export_templates}")
|
2023-11-02 12:50:29 +01:00
|
|
|
util.download(download_export_templates,
|
|
|
|
export_templates_destination_path, False)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def unzip_godot(exe_zip_filepath: str, export_templates_filepath: str, destination_path: str) -> bool:
|
2023-11-16 09:41:11 +01:00
|
|
|
print("🪛 Unzip Godot")
|
2023-11-02 12:50:29 +01:00
|
|
|
util.unzip(exe_zip_filepath, destination_path)
|
|
|
|
|
|
|
|
# The export templates contain a templates subfolder in which the content is. This is bad because it clashes
|
2023-11-16 09:52:35 +01:00
|
|
|
# with the folder structure where the version comes after: /home/eli/.local/share/godot/export_templates/
|
|
|
|
# Rename: AppData\Roaming\Godot\export_templates\templates
|
|
|
|
# to : AppData\Roaming\Godot\export_templates\3.4.stable
|
2023-11-02 12:50:29 +01:00
|
|
|
godot_templates_dir = ""
|
|
|
|
if sys.platform == "win32":
|
|
|
|
godot_templates_dir = os.path.join(
|
2023-11-16 09:52:35 +01:00
|
|
|
os.getenv('APPDATA'), "Godot/export_templates")
|
2023-11-02 12:50:29 +01:00
|
|
|
elif sys.platform == "linux":
|
|
|
|
godot_templates_dir = os.path.join(
|
2023-11-16 09:52:35 +01:00
|
|
|
str(Path.home()), ".local/share/godot/export_templates")
|
2023-11-02 12:50:29 +01:00
|
|
|
os.makedirs(godot_templates_dir, exist_ok=True)
|
|
|
|
export_templates_destination_version = f"{godot_templates_dir}/{defines.GODOT_VERSION}.{defines.GODOT_RELEASE_TYPE}"
|
|
|
|
|
|
|
|
# Remove previous folder
|
|
|
|
if os.path.exists(export_templates_destination_version):
|
|
|
|
print(f"Remove previous export templates folder: {export_templates_destination_version}")
|
|
|
|
shutil.rmtree(export_templates_destination_version)
|
|
|
|
|
|
|
|
util.unzip(export_templates_filepath, godot_templates_dir)
|
|
|
|
os.rename(os.path.join(godot_templates_dir, "templates"),
|
|
|
|
export_templates_destination_version)
|
|
|
|
|
2023-11-16 09:41:11 +01:00
|
|
|
print(f"🚮 Remove {exe_zip_filepath}")
|
2023-11-02 12:50:29 +01:00
|
|
|
try:
|
|
|
|
os.remove(exe_zip_filepath)
|
|
|
|
except OSError as error:
|
|
|
|
print(f"Error deleting file: {error}")
|
|
|
|
return False
|
|
|
|
|
2023-11-16 09:41:11 +01:00
|
|
|
print(f"🚮 Remove {export_templates_filepath}")
|
2023-11-02 12:50:29 +01:00
|
|
|
try:
|
|
|
|
os.remove(export_templates_filepath)
|
|
|
|
except OSError as error:
|
|
|
|
print(f"Error deleting file: {error}")
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def setup_godot() -> bool:
|
2023-11-16 09:41:11 +01:00
|
|
|
print(f"🚀 Set up GODOT version {defines.GODOT_VERSION} {defines.GODOT_RELEASE_TYPE}")
|
2023-11-02 12:50:29 +01:00
|
|
|
destination_path = os.path.join(defines.THIRDPATH_PATH, "Godot")
|
|
|
|
export_templates = f"Godot_v{defines.GODOT_VERSION}-{defines.GODOT_RELEASE_TYPE}_export_templates.tpz"
|
|
|
|
export_templates_filepath = os.path.join(
|
|
|
|
destination_path, export_templates)
|
2023-11-16 09:41:11 +01:00
|
|
|
exe_zip_filepath = os.path.join(destination_path, defines.GODOT_EDITOR_DOWNLOAD_NAME)
|
|
|
|
download_godot( defines.GODOT_EDITOR_DOWNLOAD_NAME,
|
2023-11-02 12:50:29 +01:00
|
|
|
export_templates, destination_path)
|
|
|
|
if not unzip_godot(exe_zip_filepath, export_templates_filepath, destination_path):
|
|
|
|
return False
|
2023-11-16 09:41:11 +01:00
|
|
|
|
2023-11-02 12:50:29 +01:00
|
|
|
# Linux needs to change file permission to be able to run godot
|
|
|
|
if sys.platform == "linux":
|
2023-11-16 09:41:11 +01:00
|
|
|
command = f"chmod +x {defines.GODOT_EDITOR_EXECUTABLE}"
|
|
|
|
print(f"Make editor executable: {command} at {destination_path}")
|
|
|
|
util.run(command,destination_path)
|
2023-11-02 12:50:29 +01:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def execute() -> bool:
|
2023-08-31 14:53:59 +02:00
|
|
|
# Assuming repo_root_path() returns the git repo root path
|
2023-11-02 12:50:29 +01:00
|
|
|
repo_path = Path(util.repo_root_path())
|
|
|
|
godot_path = repo_path / "ThirdParty" / "Godot"
|
2023-08-31 14:53:59 +02:00
|
|
|
|
|
|
|
# Create the directory if it doesn't exist
|
|
|
|
godot_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
# Check if Godot executable already exists
|
|
|
|
for file in godot_path.iterdir():
|
2023-11-09 10:30:01 +01:00
|
|
|
if defines.GODOT_EDITOR_EXECUTABLE in str(file):
|
|
|
|
print(f"Godot v{defines.GODOT_EDITOR_EXECUTABLE} already exists.")
|
2023-11-02 12:50:29 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
return setup_godot()
|
2023-08-31 14:53:59 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
execute()
|