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

View File

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

View File

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

View File

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

View File

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

View File

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