FactsDB/factsdb/main.py

76 lines
2.4 KiB
Python

"""
Main entry point for FactsDB service
"""
import sys
import os
from .config import Config
from .database import DatabaseManager
from .scheduler import get_scheduler
from .ftp_server import FTPServerManager
def main():
"""Main entry point"""
if len(sys.argv) < 2:
print("Usage: python -m factsdb.main [command]")
print("Commands:")
print(" cli - Start CLI interface")
print(" api - Start REST API server")
print(" ftp - Start FTP server")
print(" scheduler - Start scheduler")
print(" onboard - Onboard a directory (use with --directory and --table-name)")
return
command = sys.argv[1]
config = Config()
if command == "cli":
# Import and run CLI
from .cli import cli
cli()
elif command == "api":
# Start API server
from .api import app
print("Starting FactsDB REST API server...")
app.run(debug=False, host='0.0.0.0', port=5000)
elif command == "ftp":
# Start FTP server
ftp_manager = FTPServerManager(config.ftp)
# Add current directory as allowed directory
current_dir = os.path.abspath('.')
ftp_manager.add_allowed_directory(current_dir)
print("Starting FactsDB FTP server...")
try:
ftp_manager.start_server()
print("FTP Server running. Press Ctrl+C to stop.")
try:
import time
while True:
time.sleep(1)
except KeyboardInterrupt:
ftp_manager.stop_server()
print("FTP Server stopped.")
except Exception as e:
print(f"Error starting FTP server: {e}")
elif command == "scheduler":
# Start scheduler
scheduler = get_scheduler(config)
scheduler.start()
print("FactsDB Scheduler started.")
print("Press Ctrl+C to stop.")
try:
import time
while True:
time.sleep(1)
except KeyboardInterrupt:
scheduler.stop()
print("Scheduler stopped.")
elif command == "onboard":
# This would be handled by CLI
print("Use 'python -m factsdb.cli onboard' for onboarding")
else:
print(f"Unknown command: {command}")
print("Use 'python -m factsdb.main cli' for CLI interface")
if __name__ == "__main__":
main()