klippy_connection: update configuration
Use the ConfigHelper's getpath() method to configure the unix socket. The option may now be a template where the datapath is passed into the context. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
b291d94596
commit
36536535bc
|
@ -11,7 +11,6 @@ import time
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import getpass
|
import getpass
|
||||||
import confighelper
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
@ -31,8 +30,10 @@ from typing import (
|
||||||
Set,
|
Set,
|
||||||
)
|
)
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from moonraker import Server
|
||||||
from app import MoonrakerApp
|
from app import MoonrakerApp
|
||||||
from websockets import WebRequest, Subscribable
|
from websockets import WebRequest, Subscribable
|
||||||
|
from confighelper import ConfigHelper
|
||||||
from components.klippy_apis import KlippyAPI
|
from components.klippy_apis import KlippyAPI
|
||||||
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
|
||||||
|
@ -45,11 +46,9 @@ MAX_LOG_ATTEMPTS = 10 * LOG_ATTEMPT_INTERVAL
|
||||||
UNIX_BUFFER_LIMIT = 20 * 1024 * 1024
|
UNIX_BUFFER_LIMIT = 20 * 1024 * 1024
|
||||||
|
|
||||||
class KlippyConnection:
|
class KlippyConnection:
|
||||||
def __init__(self, config: confighelper.ConfigHelper) -> None:
|
def __init__(self, server: Server) -> None:
|
||||||
self.server = config.get_server()
|
self.server = server
|
||||||
uds_addr: str = config.get(
|
self.uds_address = pathlib.Path("/tmp/klippy_uds")
|
||||||
'klippy_uds_address', "/tmp/klippy_uds")
|
|
||||||
self.uds_address = pathlib.Path(uds_addr).expanduser().resolve()
|
|
||||||
self.writer: Optional[asyncio.StreamWriter] = None
|
self.writer: Optional[asyncio.StreamWriter] = None
|
||||||
self.connection_mutex: asyncio.Lock = asyncio.Lock()
|
self.connection_mutex: asyncio.Lock = asyncio.Lock()
|
||||||
self.event_loop = self.server.get_event_loop()
|
self.event_loop = self.server.get_event_loop()
|
||||||
|
@ -81,6 +80,11 @@ class KlippyConnection:
|
||||||
need_klippy_reg=False)
|
need_klippy_reg=False)
|
||||||
self.server.register_component("klippy_connection", self)
|
self.server.register_component("klippy_connection", self)
|
||||||
|
|
||||||
|
def configure(self, config: ConfigHelper):
|
||||||
|
self.uds_address = config.getpath(
|
||||||
|
"klippy_uds_address", self.uds_address
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def klippy_apis(self) -> KlippyAPI:
|
def klippy_apis(self) -> KlippyAPI:
|
||||||
return self.server.lookup_component("klippy_apis")
|
return self.server.lookup_component("klippy_apis")
|
||||||
|
|
|
@ -82,8 +82,7 @@ class Server:
|
||||||
log_level = logging.DEBUG if args["verbose"] else logging.INFO
|
log_level = logging.DEBUG if args["verbose"] else logging.INFO
|
||||||
logging.getLogger().setLevel(log_level)
|
logging.getLogger().setLevel(log_level)
|
||||||
self.event_loop.set_debug(args["asyncio_debug"])
|
self.event_loop.set_debug(args["asyncio_debug"])
|
||||||
|
self.klippy_connection = KlippyConnection(self)
|
||||||
self.klippy_connection = KlippyConnection(config)
|
|
||||||
|
|
||||||
# Tornado Application/Server
|
# Tornado Application/Server
|
||||||
self.moonraker_app = app = MoonrakerApp(config)
|
self.moonraker_app = app = MoonrakerApp(config)
|
||||||
|
@ -232,6 +231,7 @@ class Server:
|
||||||
for section in cfg_sections:
|
for section in cfg_sections:
|
||||||
self.load_component(config, section, None)
|
self.load_component(config, section, None)
|
||||||
|
|
||||||
|
self.klippy_connection.configure(config)
|
||||||
config.validate_config()
|
config.validate_config()
|
||||||
|
|
||||||
def load_component(self,
|
def load_component(self,
|
||||||
|
|
Loading…
Reference in New Issue