30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
"""Paths and process helpers shared by UE, Blender launchers and plain Python."""
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
|
|
PROJECT = Path(__file__).resolve().parents[3]
|
|
GENERATED = "/Game/Workshop/Generated"
|
|
|
|
|
|
def slug(value):
|
|
if not re.fullmatch(r"[A-Za-z][A-Za-z0-9_]*", value):
|
|
raise ValueError("Nazwa musi zaczynac sie litera i zawierac tylko litery ASCII, cyfry lub _.")
|
|
return value
|
|
|
|
|
|
def executable(name, explicit=None):
|
|
candidate = explicit or os.environ.get("WORKSHOP_" + name.upper()) or shutil.which(name)
|
|
if not candidate and name == "blender" and os.name == "nt":
|
|
# Standard Windows installs do not necessarily add Blender to PATH.
|
|
root = Path(os.environ.get("PROGRAMFILES", r"C:\Program Files")) / "Blender Foundation"
|
|
installed = [path for path in root.glob("Blender */blender.exe") if path.is_file()]
|
|
if installed:
|
|
candidate = max(installed, key=lambda path: tuple(int(part) for part in re.findall(r"\d+", path.parent.name)))
|
|
if candidate and Path(candidate).is_file():
|
|
return str(Path(candidate).resolve())
|
|
raise FileNotFoundError(
|
|
f"Nie znaleziono {name}. Dodaj program do PATH lub ustaw WORKSHOP_{name.upper()} "
|
|
"na pelna sciezke do pliku wykonywalnego.")
|