generated from Labyricorn/labyricorn-project-template
Implement CyberSim-OS Phase 1 MVP simulation environment
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
CyberSim OS - Standalone Offline Local Launcher
|
||||
Zero external dependencies. Binds strictly to 127.0.0.1 and opens default browser.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import http.server
|
||||
import socketserver
|
||||
import webbrowser
|
||||
import threading
|
||||
import time
|
||||
|
||||
PORT = 8080
|
||||
HOST = '127.0.0.1'
|
||||
|
||||
class CustomHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
src_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'src')
|
||||
super().__init__(*args, directory=src_dir, **kwargs)
|
||||
|
||||
def log_message(self, format, *args):
|
||||
pass
|
||||
|
||||
def start_server():
|
||||
server = None
|
||||
for port in range(PORT, PORT + 20):
|
||||
try:
|
||||
server = socketserver.TCPServer((HOST, port), CustomHandler)
|
||||
print(f"============================================================")
|
||||
print(f" CyberSim OS - Offline Simulation Environment")
|
||||
print(f" Running locally at: http://{HOST}:{port}")
|
||||
print(f" Press Ctrl+C to stop the launcher")
|
||||
print(f"============================================================")
|
||||
|
||||
def open_browser():
|
||||
time.sleep(0.6)
|
||||
webbrowser.open(f"http://{HOST}:{port}")
|
||||
|
||||
threading.Thread(target=open_browser, daemon=True).start()
|
||||
server.serve_forever()
|
||||
break
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
start_server()
|
||||
except KeyboardInterrupt:
|
||||
print("\nCyberSim OS stopped.")
|
||||
sys.exit(0)
|
||||
Reference in New Issue
Block a user