force rewrited code
This commit is contained in:
109
main.py
Normal file
109
main.py
Normal file
@@ -0,0 +1,109 @@
|
||||
"""Archivium Launcher"""
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
|
||||
|
||||
def check_dependencies():
|
||||
"""Check if required packages are installed"""
|
||||
packages = ["uvicorn", "fastapi", "sqlalchemy", "passlib"]
|
||||
missing = []
|
||||
|
||||
for package in packages:
|
||||
try:
|
||||
__import__(package.split("[")[0].replace("-", "_"))
|
||||
except ImportError:
|
||||
missing.append(package)
|
||||
|
||||
if missing:
|
||||
print(f"Missing dependencies: {', '.join(missing)}")
|
||||
print("\nInstall with:")
|
||||
print(" cd backend/app")
|
||||
print(" uv sync")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_node_js():
|
||||
"""Check if Node.js is available"""
|
||||
return shutil.which("node") is not None and shutil.which("npm") is not None
|
||||
|
||||
|
||||
def run_backend():
|
||||
"""Run backend only"""
|
||||
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
backend_dir = os.path.join(base_dir, "backend", "app")
|
||||
|
||||
print("Starting backend on port 8000...")
|
||||
|
||||
backend_process = subprocess.Popen(
|
||||
["uv", "run", "python", "main.py"],
|
||||
cwd=backend_dir
|
||||
)
|
||||
|
||||
try:
|
||||
backend_process.wait()
|
||||
except KeyboardInterrupt:
|
||||
backend_process.terminate()
|
||||
backend_process.wait()
|
||||
|
||||
|
||||
def run_full_stack():
|
||||
"""Run backend and frontend"""
|
||||
check_dependencies()
|
||||
|
||||
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")
|
||||
|
||||
if not check_node_js():
|
||||
if not sys.stdin.isatty():
|
||||
run_backend()
|
||||
return
|
||||
|
||||
response = input("Node.js not found. Run backend only? (y/n): ").strip().lower()
|
||||
if response == 'y':
|
||||
run_backend()
|
||||
return
|
||||
|
||||
print("Starting backend and frontend...")
|
||||
|
||||
backend_process = subprocess.Popen(
|
||||
["uv", "run", "python", "main.py"],
|
||||
cwd=backend_dir
|
||||
)
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
frontend_process = subprocess.Popen(
|
||||
"npm start",
|
||||
shell=True,
|
||||
cwd=frontend_dir,
|
||||
)
|
||||
|
||||
try:
|
||||
backend_process.wait()
|
||||
frontend_process.wait()
|
||||
except KeyboardInterrupt:
|
||||
backend_process.terminate()
|
||||
frontend_process.terminate()
|
||||
backend_process.wait()
|
||||
frontend_process.wait()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] == "--backend-only":
|
||||
check_dependencies()
|
||||
run_backend()
|
||||
elif sys.argv[1] == "--help":
|
||||
print("Usage: python main.py [option]")
|
||||
print("\nOptions:")
|
||||
print(" --backend-only Run backend only")
|
||||
print(" --help Show this message")
|
||||
else:
|
||||
print(f"Unknown option: {sys.argv[1]}")
|
||||
else:
|
||||
run_full_stack()
|
||||
|
||||
Reference in New Issue
Block a user