150 lines
4.6 KiB
Python
150 lines
4.6 KiB
Python
"""Archivium Launcher - Uruchamia całą aplikację"""
|
|
import subprocess
|
|
import os
|
|
import sys
|
|
import time
|
|
import webbrowser
|
|
import shutil
|
|
|
|
|
|
def install_missing_packages():
|
|
"""Instaluj brakujące pakiety"""
|
|
packages = ["uvicorn", "fastapi", "sqlalchemy", "passlib[argon2]"]
|
|
for package in packages:
|
|
try:
|
|
__import__(package.split("[")[0].replace("-", "_"))
|
|
except ImportError:
|
|
print(f"[*] Instalowanie: {package}...")
|
|
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
|
|
|
|
|
def check_node_js():
|
|
"""Sprawdź czy Node.js jest zainstalowany"""
|
|
return shutil.which("node") is not None and shutil.which("npm") is not None
|
|
|
|
|
|
def run_backend_only():
|
|
"""Uruchom tylko backend"""
|
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
backend_dir = os.path.join(base_dir, "backend", "app")
|
|
|
|
print("\n" + "="*60)
|
|
print(" ARCHIVIUM - Backend Only Mode")
|
|
print("="*60 + "\n")
|
|
|
|
print("[*] Startuje backend FastAPI na porcie 8000...")
|
|
print("[*] Czekaj 2-3 sekundy na zainicjalizowanie...\n")
|
|
|
|
backend_process = subprocess.Popen(
|
|
[sys.executable, "main.py"],
|
|
cwd=backend_dir
|
|
)
|
|
|
|
time.sleep(2)
|
|
|
|
print("\n" + "="*60)
|
|
print("✓ Backend uruchomiony!")
|
|
print("="*60)
|
|
print("\n📡 API dostępne:")
|
|
print(" http://localhost:8000/api/status")
|
|
print(" http://localhost:8000/docs (Swagger UI)")
|
|
print("\n🔧 Testy API:")
|
|
print(" curl http://localhost:8000/api/status")
|
|
print(" curl -X POST http://localhost:8000/api/init \\")
|
|
print(" -H 'Content-Type: application/json' \\")
|
|
print(" -d '{\"password\": \"TestPassword123\"}'")
|
|
print("\n❌ Frontend nie dostępny (Node.js nie zainstalowany)")
|
|
print("\n📝 Aby zainstalować Node.js na Fedora Atomic:")
|
|
print(" 1. Za pomocą toolbox:")
|
|
print(" toolbox create")
|
|
print(" toolbox run sudo dnf install nodejs npm")
|
|
print(" 2. Za pomocą brew:")
|
|
print(" brew install node")
|
|
print(" 3. Lub pobrać z https://nodejs.org/")
|
|
print("\n Po instalacji Node.js, uruchom:")
|
|
print(" cd frontend && npm install && npm start")
|
|
print("\nAby zatrzymać backend: Ctrl+C\n")
|
|
|
|
try:
|
|
backend_process.wait()
|
|
except KeyboardInterrupt:
|
|
print("\n[*] Zatrzymywanie backendu...")
|
|
backend_process.terminate()
|
|
backend_process.wait()
|
|
print("[✓] Backend zatrzymany")
|
|
|
|
|
|
def run_archivium():
|
|
"""Uruchom całą aplikację Archivium"""
|
|
install_missing_packages()
|
|
|
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
backend_dir = os.path.join(base_dir, "backend", "app")
|
|
frontend_dir = os.path.join(base_dir, "frontend")
|
|
|
|
# Sprawdź czy Node.js jest dostępny
|
|
has_node = check_node_js()
|
|
|
|
if not has_node:
|
|
print("\n⚠️ Node.js/npm nie znaleziony!")
|
|
print("\nOpcje:")
|
|
print("1. Uruchomić tylko backend (Enter)")
|
|
print("2. Wyjść i zainstalować Node.js (q)\n")
|
|
choice = input("Wybór [1/q]: ").strip().lower()
|
|
|
|
if choice == 'q':
|
|
print("[*] Wyjście. Zainstaluj Node.js i uruchom ponownie.")
|
|
sys.exit(1)
|
|
else:
|
|
run_backend_only()
|
|
return
|
|
|
|
print("\n" + "="*50)
|
|
print(" ARCHIVIUM - System Zarządzania Archiwum")
|
|
print("="*50 + "\n")
|
|
|
|
print("[1/3] Startuje backend (Port 8000)...")
|
|
backend_process = subprocess.Popen(
|
|
[sys.executable, "main.py"],
|
|
cwd=backend_dir
|
|
)
|
|
|
|
print("[2/3] Startuje frontend (Port 3000)...")
|
|
frontend_process = subprocess.Popen(
|
|
"npm start",
|
|
shell=True,
|
|
cwd=frontend_dir,
|
|
)
|
|
|
|
print("[3/3] Otwieranie przeglądarki...")
|
|
time.sleep(3)
|
|
|
|
try:
|
|
webbrowser.open("http://localhost:3000")
|
|
except Exception as e:
|
|
print(f"[!] Nie udało się otworzyć przeglądarki: {e}")
|
|
print("[*] Otwórz ręcznie: http://localhost:3000")
|
|
|
|
print("\n" + "="*50)
|
|
print("✓ Aplikacja uruchomiona!")
|
|
print(" Backend: http://localhost:8000")
|
|
print(" Frontend: http://localhost:3000")
|
|
print(" Docs: http://localhost:8000/docs")
|
|
print("="*50)
|
|
print("\nAby zatrzymać: Ctrl+C\n")
|
|
|
|
try:
|
|
backend_process.wait()
|
|
frontend_process.wait()
|
|
except KeyboardInterrupt:
|
|
print("\n[*] Zatrzymywanie systemu...")
|
|
backend_process.terminate()
|
|
frontend_process.terminate()
|
|
backend_process.wait()
|
|
frontend_process.wait()
|
|
print("[✓] System zatrzymany")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_archivium()
|