33 lines
937 B
Python
33 lines
937 B
Python
"""Пути к ресурсам как в исходниках, так и в PyInstaller-сборке."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
def is_frozen() -> bool:
|
|
return bool(getattr(sys, "frozen", False) or getattr(sys, "_MEIPASS", None))
|
|
|
|
|
|
def resource_root() -> str:
|
|
if is_frozen():
|
|
return str(getattr(sys, "_MEIPASS", os.path.dirname(sys.executable)))
|
|
return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
|
|
|
|
def resource_path(*parts: str) -> str:
|
|
return os.path.join(resource_root(), *parts)
|
|
|
|
|
|
def bundled_models_dirs() -> list[str]:
|
|
roots = [resource_root()]
|
|
if is_frozen():
|
|
roots.append(os.path.dirname(os.path.abspath(sys.executable)))
|
|
out: list[str] = []
|
|
for root in roots:
|
|
path = os.path.abspath(os.path.join(root, "models"))
|
|
if os.path.isdir(path) and path not in out:
|
|
out.append(path)
|
|
return out
|