59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
from pathlib import Path
|
|
|
|
from app.dependencies import DependencyManager
|
|
from app.paths import AppPaths
|
|
from app.ui import ConsoleUI
|
|
from app.venv_manager import VirtualEnvManager
|
|
|
|
|
|
class AppRunner:
|
|
def __init__(self, base_dir: Path, entry_script: Path) -> None:
|
|
self.paths = AppPaths(base_dir=base_dir)
|
|
self.entry_script = entry_script
|
|
|
|
def run(self) -> None:
|
|
ConsoleUI.headline("StFV Backup Bootstrap")
|
|
|
|
venv = VirtualEnvManager(self.paths.venv_dir, self.entry_script)
|
|
if not venv.in_virtualenv():
|
|
ConsoleUI.info("Virtuelle Umgebung wird vorbereitet...")
|
|
venv.ensure_and_reexec_if_needed()
|
|
|
|
deps = DependencyManager(self.paths.requirements_path)
|
|
missing = deps.install_missing()
|
|
if missing:
|
|
ConsoleUI.success(f"Abhaengigkeiten installiert: {', '.join(missing)}")
|
|
else:
|
|
ConsoleUI.info("Alle Abhaengigkeiten sind bereits installiert.")
|
|
|
|
from app.config_store import ConfigStore
|
|
from app.setup_wizard import SetupWizard
|
|
from app.web_server import FlaskServer
|
|
|
|
store = ConfigStore(self.paths.db_path)
|
|
store.ensure_schema()
|
|
|
|
config = store.load_config()
|
|
if config is None:
|
|
ConsoleUI.warn("Keine vollstaendige Konfiguration gefunden.")
|
|
setup_data = SetupWizard().collect_initial()
|
|
store.save_config(setup_data.config)
|
|
store.create_user(
|
|
setup_data.admin_username,
|
|
setup_data.admin_password_hash,
|
|
is_admin=True,
|
|
)
|
|
config = setup_data.config
|
|
ConsoleUI.success("Konfiguration und Admin-Benutzer wurden gespeichert.")
|
|
elif not store.has_any_user():
|
|
ConsoleUI.warn("Keine Benutzer gefunden.")
|
|
admin_username, admin_hash = SetupWizard().collect_admin_user()
|
|
store.create_user(admin_username, admin_hash, is_admin=True)
|
|
ConsoleUI.success("Admin-Benutzer wurde gespeichert.")
|
|
|
|
ConsoleUI.success("System ist bereit.")
|
|
ConsoleUI.info(
|
|
f"Flask startet auf http://{config.ip}:{config.port} (debug={config.debug})"
|
|
)
|
|
FlaskServer(config=config, store=store).run()
|