-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hikari
committed
Aug 31, 2024
1 parent
a8aa655
commit c338be1
Showing
24 changed files
with
563 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"first_run": false, "use_mirror": true, "autorun": "", "debug": false, "direct_mode": false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import core | ||
from . import webui | ||
from . import utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from . import config | ||
from . import java | ||
from . import main | ||
from . import server | ||
from . import workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#config | ||
import os | ||
import json | ||
|
||
CONFIG_FILE = 'hsl-config.json' | ||
class Config: | ||
first_run: bool = True | ||
use_mirror: bool = False | ||
workspace_dir: str = 'workspace' | ||
workspace_file: str = 'workspace.json' | ||
autorun: str = '' | ||
debug: bool = False | ||
direct_mode: bool = False | ||
|
||
@classmethod | ||
def load(cls): | ||
try: | ||
with open(CONFIG_FILE, 'r') as f: | ||
config = json.load(f) | ||
cls.first_run = config['first_run'] | ||
cls.use_mirror = config['use_mirror'] | ||
cls.workspace_dir = config['workspace_dir'] | ||
cls.workspace_file = config['workspace_file'] | ||
cls.autorun = config['autorun'] | ||
cls.debug = config['debug'] | ||
cls.direct_mode = config['direct_mode'] | ||
except (FileNotFoundError, KeyError): | ||
cls.save() | ||
@classmethod | ||
def save(cls): | ||
with open(CONFIG_FILE, 'w') as f: | ||
json.dump({ | ||
'first_run': cls.first_run, | ||
'use_mirror': cls.use_mirror, | ||
'autorun': cls.autorun, | ||
'debug': cls.debug, | ||
'direct_mode': cls.direct_mode | ||
}, f) | ||
# class Config: | ||
# def __init__(self): | ||
# self.first_run: bool = True | ||
# self.use_mirror: bool = False | ||
# self.workspace_dir: str = 'workspace' | ||
# self.config_dir: str = 'hsl-config' | ||
# self.config_file: str = 'config.json' | ||
# self.workspace_file: str = 'workspace.json' | ||
# self.config_path: str = os.path.join(self.config_dir, self.config_file) | ||
# self.workspace_path: str = os.path.join(self.workspace_dir, self.workspace_file) | ||
# self.autorun: str = '' | ||
# self.debug: bool = False | ||
# self.direct_mode: bool = False | ||
# self.initialize() | ||
|
||
# def initialize(self): | ||
# try: | ||
# self.load_config() | ||
# except FileNotFoundError: | ||
# #not found, create | ||
# if not os.path.exists(self.config_path): | ||
# os.makedirs(self.config_dir) | ||
# self.save_config() | ||
# except KeyError: | ||
# #delete config | ||
# os.remove(self.config_path) | ||
# self.save_config() | ||
# def save_config(self): | ||
# with open(self.config_path, 'w') as f: | ||
# json.dump({ | ||
# 'first_run': self.first_run, | ||
# 'use_mirror': self.use_mirror, | ||
# 'autorun': self.autorun, | ||
# 'debug': self.debug, | ||
# 'direct_mode': self.direct_mode | ||
# }, f) | ||
# self.load_config() | ||
# def load_config(self): | ||
# with open(self.config_path, 'r') as f: | ||
# config = json.load(f) | ||
# self.first_run = config['first_run'] | ||
# self.use_mirror = config['use_mirror'] | ||
# self.autorun = config['autorun'] | ||
# self.debug = config['debug'] | ||
# self.direct_mode = config['direct_mode'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .main import HSL_WEBUI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import asyncio | ||
from starlette.requests import Request | ||
from starlette.applications import Starlette | ||
from starlette.responses import HTMLResponse | ||
from starlette.routing import Route, WebSocketRoute | ||
from starlette.staticfiles import StaticFiles | ||
from starlette.websockets import WebSocket, WebSocketDisconnect | ||
import uvicorn | ||
import os | ||
import logging | ||
import sys | ||
import time | ||
|
||
from hsl.core.main import HSL | ||
logging.basicConfig(stream=sys.stdout, level=logging.INFO) | ||
logger = logging.getLogger('hsl') | ||
def load_page(path) -> str: | ||
with open(os.path.join("hsl", "webui", "templates", path + ".html"), "r", encoding="utf-8") as f: | ||
return f.read() | ||
class HSL_WEBUI(HSL): | ||
async def firstpage(self, request: Request): | ||
return HTMLResponse( | ||
#load_page("home") | ||
load_page("first") | ||
) | ||
async def homepage(self, request: Request): | ||
return HTMLResponse( | ||
load_page("home") | ||
) | ||
|
||
async def websocket_init(self, websocket: WebSocket): | ||
await websocket.accept() | ||
logger.info(f"HSL Init accepted") | ||
await websocket.close() | ||
await self.init() | ||
|
||
async def websocket_status(self, websocket: WebSocket): | ||
await websocket.accept() | ||
logger.info(f"HSL Status accepted, init: {self.flag_init}") | ||
try: | ||
try: | ||
while True: | ||
await asyncio.sleep(0.5) | ||
await websocket.send_json({"init": self.flag_init, "timestamp": time.time()}) | ||
except WebSocketDisconnect: | ||
logger.info(f"WebSocket Disconnected") | ||
finally: | ||
await websocket.close() | ||
except RuntimeError: | ||
pass | ||
|
||
def __init__(self, host, port): | ||
super().__init__() | ||
routes = [ | ||
Route("/", endpoint=self.firstpage), | ||
Route("/home", endpoint=self.homepage), | ||
WebSocketRoute("/ws/init", endpoint=self.websocket_init), | ||
WebSocketRoute("/ws/status", endpoint=self.websocket_status), | ||
] | ||
self.app = Starlette(debug=True, routes=routes) | ||
self.app.mount("/static", StaticFiles(directory="hsl/webui/templates/static"), name="static") | ||
self.app.mount("/", StaticFiles(directory="hsl/webui/templates/"), name="templates") | ||
uvicorn.run(self.app, host=host, port=port, log_level="info") | ||
|
||
if __name__ == "__main__": | ||
HSL_WEBUI('0.0.0.0', 15432) |
Oops, something went wrong.