Add build functionality

This commit is contained in:
Maarceeli 2025-05-24 10:11:38 +02:00
parent 3dd172621d
commit 69260388ef
Signed by: Marceeli
GPG key ID: ABC955B3D1495923

View file

@ -1,37 +1,80 @@
import flet as ft
import tempfile, subprocess, os, re, uuid
import PyInstaller.__main__
def main(page: ft.Page):
page.title = "AFBT"
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
def build(e):
print("Build clicked!") # Placeholder action
ruuid = uuid.uuid4().hex
base_temp_dir = os.path.join(os.getcwd(), "temp")
temp_dir = os.path.join(base_temp_dir, f"clone-{ruuid}")
def clone_and_set_version(version: str, repo_url: str):
if not (version and repo_url):
return
# Create a temp directory inside the current project directory
os.makedirs(base_temp_dir, exist_ok=True)
os.makedirs(temp_dir)
subprocess.run(["git", "clone", repo_url, temp_dir], check=True)
version_file = os.path.join(temp_dir, "src", "version.py")
with open(version_file, "r", encoding="utf-8") as f:
contents = f.read()
new_contents = re.sub(
r'^version\s*=\s*["\'].*?["\']',
f'version = "{version}"',
contents,
flags=re.MULTILINE,
)
with open(version_file, "w", encoding="utf-8") as f:
f.write(new_contents)
print(f"Updated {version_file} to version = \"{version}\"")
print(f"Cloned project located at: {temp_dir}")
versionprompt = ft.TextField(label="Version", expand=True)
repoprompt = ft.TextField(label="Fuji Repository", expand=True, value="https://git.marceeli.ovh/Fuji/Fuji")
button = ft.ElevatedButton(
text="Build",
on_click=build,
height=40,
expand=True, # This makes the button expand horizontally
bgcolor=ft.Colors.with_opacity(0.4, ft.Colors.BLUE)
)
def build(e):
clone_and_set_version(versionprompt.value.strip(), repoprompt.value.strip())
main_file = os.path.join(temp_dir, "src", "main.py")
locales_dir = os.path.join(temp_dir, "src", "locales")
assets_dir = os.path.join(temp_dir, "src", "assets")
PyInstaller.__main__.run([
main_file,
'--clean',
'--noconfirm',
f"--add-data={locales_dir}:locales",
f"--add-data={assets_dir}:assets"
])
button = ft.ElevatedButton(text="Build", on_click=build, height=40, expand=True, bgcolor=ft.Colors.with_opacity(0.4, ft.Colors.BLUE))
card = ft.Card(
content=ft.Container(
content=ft.Column(
controls=[versionprompt, button],
spacing=10,
expand=True,
controls=[versionprompt, repoprompt, button],
spacing=10, expand=True,
horizontal_alignment=ft.CrossAxisAlignment.STRETCH
),
alignment=ft.alignment.center,
border_radius=20,
padding=25,
width=500,
),
alignment=ft.alignment.center,
border_radius=20,
padding=25,
width=500
)
)
page.add(card)