nfdos/src/bootstrap.py
neoricalex 666bf0b1bd
Some checks are pending
Build NFDOS ISO / build (push) Waiting to run
Primeiro Commit
2025-11-11 04:35:55 +01:00

62 lines
2.1 KiB
Python

import os
import shutil
import subprocess
import sys
from pathlib import Path
class Application(object):
def __init__(self, *args, **kwargs):
for key in kwargs:
setattr(self, key, kwargs[key])
self._hello()
def _hello(self):
print(f"NFDOS {getattr(self, 'version', '')} — inicializador de ambiente")
def run(self):
self._ensure_venv()
self._install_mkdocs()
self._build_site()
self.launch_welcome()
def _ensure_venv(self):
"""Cria e ativa o ambiente virtual, caso ainda não exista."""
python_working_directory = ("src")
os.chdir(python_working_directory)
venv_path = Path("venv")
if not venv_path.exists():
print("[+] A criar ambiente virtual...")
subprocess.run([sys.executable, "-m", "venv", "venv"], check=True)
else:
print("[=] Ambiente virtual já existente.")
def _install_mkdocs(self):
"""Instala o MkDocs dentro do ambiente virtual."""
print("[+] A instalar o MkDocs e o tema Material...")
subprocess.run(["venv/bin/pip", "install", "-U", "mkdocs", "mkdocs-material"], check=True)
subprocess.run(["venv/bin/pip", "install", "-U", "colorama", "rich"], check=True)
def _build_site(self):
"""Gera o site estático a partir da pasta docs/."""
print("[+] A compilar o site com o MkDocs...")
subprocess.run(["venv/bin/mkdocs", "build", "--clean"], check=True)
print("[✓] Site compilado com sucesso na diretoria 'site/'.")
def detect_environment(self):
"""Deteta se o ambiente possui interface gráfica GNOME disponível."""
if os.environ.get("DISPLAY") and shutil.which("gnome-shell"):
return "tui"
return "tui"
def launch_welcome(self):
"""Lança o modo de boas-vindas (texto ou gráfico) consoante o ambiente detetado."""
mode = self.detect_environment()
print(f"[✓] Ambiente detetado: {mode}")
if mode == "gui":
subprocess.run(["python3", "gui/terminal.py"])
else:
subprocess.run(["python3", "tui/main.py"])