refactor: convert application into a component

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-01-13 10:44:39 -05:00
parent 94b1896e28
commit d506c9241f
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
6 changed files with 24 additions and 21 deletions

View File

@ -22,8 +22,8 @@ from tornado.escape import url_unescape, url_escape
from tornado.routing import Rule, PathMatches, AnyMatches
from tornado.http1connection import HTTP1Connection
from tornado.log import access_log
from .utils import ServerError, source_info, parse_ip_address
from .common import (
from ..utils import ServerError, source_info, parse_ip_address
from ..common import (
JsonRPC,
WebRequest,
APIDefinition,
@ -32,8 +32,8 @@ from .common import (
RequestType,
KlippyState
)
from .utils import json_wrapper as jsonw
from .websockets import (
from ..utils import json_wrapper as jsonw
from ..websockets import (
WebsocketManager,
WebSocket,
BridgeSocket
@ -55,17 +55,17 @@ from typing import (
)
if TYPE_CHECKING:
from tornado.httpserver import HTTPServer
from .server import Server
from .eventloop import EventLoop
from .confighelper import ConfigHelper
from .klippy_connection import KlippyConnection as Klippy
from .utils import IPAddress
from .components.file_manager.file_manager import FileManager
from .components.announcements import Announcements
from .components.machine import Machine
from ..server import Server
from ..eventloop import EventLoop
from ..confighelper import ConfigHelper
from ..klippy_connection import KlippyConnection as Klippy
from ..utils import IPAddress
from .file_manager.file_manager import FileManager
from .announcements import Announcements
from .machine import Machine
from io import BufferedReader
from .components.authorization import Authorization
from .components.template import TemplateFactory, JinjaTemplate
from .authorization import Authorization
from .template import TemplateFactory, JinjaTemplate
MessageDelgate = Optional[tornado.httputil.HTTPMessageDelegate]
AuthComp = Optional[Authorization]
APICallback = Callable[[WebRequest], Coroutine]
@ -217,7 +217,6 @@ class MoonrakerApp:
self.register_upload_handler("/server/files/upload")
# Register Server Components
self.server.register_component("application", self)
self.server.register_component("jsonrpc", self.json_rpc)
self.server.register_component("internal_transport", self.internal_transport)
@ -1111,3 +1110,6 @@ class WelcomeHandler(tornado.web.RequestHandler):
welcome_template = await app.load_template("welcome.html")
ret = await welcome_template.render_async(context)
self.finish(ret)
def load_component(config: ConfigHelper) -> MoonrakerApp:
return MoonrakerApp(config)

View File

@ -14,7 +14,7 @@ from typing import (
)
if TYPE_CHECKING:
from ..confighelper import ConfigHelper
from ..app import InternalTransport as ITransport
from .application import InternalTransport as ITransport
class ButtonManager:

View File

@ -42,7 +42,7 @@ from typing import (
if TYPE_CHECKING:
from ..confighelper import ConfigHelper
from ..common import WebRequest
from ..app import MoonrakerApp
from .application import MoonrakerApp
from ..klippy_connection import KlippyConnection
from .shell_command import ShellCommandFactory as SCMDComp
from .database import MoonrakerDatabase

View File

@ -31,7 +31,7 @@ from typing import (
Callable,
)
if TYPE_CHECKING:
from ..app import InternalTransport
from .application import InternalTransport
from ..confighelper import ConfigHelper
from ..websockets import WebsocketManager
from ..common import BaseRemoteConnection

View File

@ -29,7 +29,7 @@ from typing import (
if TYPE_CHECKING:
from ..confighelper import ConfigHelper
from ..common import WebRequest
from ..app import MoonrakerApp
from .application import MoonrakerApp
from .machine import Machine
ZC_SERVICE_TYPE = "_moonraker._tcp.local."

View File

@ -21,7 +21,6 @@ import uuid
import traceback
from . import confighelper
from .eventloop import EventLoop
from .app import MoonrakerApp
from .klippy_connection import KlippyConnection
from .utils import (
ServerError,
@ -50,6 +49,7 @@ from typing import (
)
if TYPE_CHECKING:
from .common import WebRequest
from .components.application import MoonrakerApp
from .components.file_manager.file_manager import FileManager
from .components.machine import Machine
from .components.extensions import ExtensionManager
@ -99,7 +99,8 @@ class Server:
self.klippy_connection = KlippyConnection(self)
# Tornado Application/Server
self.moonraker_app = app = MoonrakerApp(config)
self.moonraker_app: MoonrakerApp = self.load_component(config, "application")
app = self.moonraker_app
self.register_endpoint = app.register_endpoint
self.register_debug_endpoint = app.register_debug_endpoint
self.register_static_file_handler = app.register_static_file_handler