Erminig/erminig/controllers/govel/build.py
2025-05-05 16:16:24 +02:00

63 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#
# Erminig - Lancement de la construction du paquet
# Copyright (C) 2025 L0m1g
# Sous licence DOUARN - Voir le fichier LICENCE pour les détails
#
# Ce fichier fait partie du projet Erminig.
# Libre comme lair, stable comme un menhir, et salé comme le beurre.
#
import os
import subprocess
from erminig.core.config import Config
from erminig.core.security import check_root, check_user_exists, run_as_user
check_root
check_user_exists("pak")
def run_pakva_function(pakva_path, name, version, func_name):
"""
Exécute une fonction dun fichier Pakva donné (ex: build, pak).
"""
build_root = Config.BUILD_DIR / f"{name}-{version}"
src_dir = build_root / "src"
tmp_dir = build_root / "tmp"
os.makedirs(src_dir, exist_ok=True)
os.makedirs(tmp_dir, exist_ok=True)
env = os.environ.copy()
env["SRC"] = str(src_dir)
env["TMP"] = str(tmp_dir)
try:
result = subprocess.run(
f"""
set -e
source "{pakva_path}"
{func_name}
""",
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
executable="/bin/bash",
text=True,
env=env,
)
print(f"[{func_name.upper()}] Succès : {pakva_path.name}")
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"[{func_name.upper()}] Échec : {pakva_path.name}")
print(e.stderr)
return False
@run_as_user("pak")
def run_build_function(pakva_path, name, version):
return run_pakva_function(pakva_path, name, version, "build")
def run_pak_function(pakva_path, name, version):
return run_pakva_function(pakva_path, name, version, "pak")