update_manager: fetch klipper paths from klippy_connection

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-07-20 13:58:21 -04:00
parent 9097cfcce7
commit 003acd5f64
2 changed files with 11 additions and 27 deletions

View File

@ -5,7 +5,6 @@
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
from __future__ import annotations from __future__ import annotations
import os
import sys import sys
import copy import copy
import pathlib import pathlib
@ -20,10 +19,7 @@ from typing import (
if TYPE_CHECKING: if TYPE_CHECKING:
from ...confighelper import ConfigHelper from ...confighelper import ConfigHelper
from ..database import MoonrakerDatabase from ..klippy_connection import KlippyConnection
KLIPPER_DEFAULT_PATH = os.path.expanduser("~/klipper")
KLIPPER_DEFAULT_EXEC = os.path.expanduser("~/klippy-env/bin/python")
BASE_CONFIG: Dict[str, Dict[str, str]] = { BASE_CONFIG: Dict[str, Dict[str, str]] = {
"moonraker": { "moonraker": {
@ -98,15 +94,11 @@ class Channel(ExtendedEnum):
def get_base_configuration(config: ConfigHelper) -> ConfigHelper: def get_base_configuration(config: ConfigHelper) -> ConfigHelper:
server = config.get_server() server = config.get_server()
base_cfg = copy.deepcopy(BASE_CONFIG) base_cfg = copy.deepcopy(BASE_CONFIG)
kconn: KlippyConnection = server.lookup_component("klippy_connection")
base_cfg["moonraker"]["type"] = str(AppType.detect()) base_cfg["moonraker"]["type"] = str(AppType.detect())
db: MoonrakerDatabase = server.lookup_component('database') base_cfg["klipper"]["path"] = str(kconn.path)
base_cfg["klipper"]["path"] = db.get_item( base_cfg["klipper"]["env"] = str(kconn.executable)
"moonraker", "update_manager.klipper_path", KLIPPER_DEFAULT_PATH base_cfg["klipper"]["type"] = str(AppType.detect(kconn.path))
).result()
base_cfg["klipper"]["env"] = db.get_item(
"moonraker", "update_manager.klipper_exec", KLIPPER_DEFAULT_EXEC
).result()
base_cfg["klipper"]["type"] = str(AppType.detect(base_cfg["klipper"]["path"]))
default_channel = config.get("channel", None) default_channel = config.get("channel", None)
# Check for configuration overrides # Check for configuration overrides
for app_name in base_cfg.keys(): for app_name in base_cfg.keys():

View File

@ -204,28 +204,20 @@ class UpdateManager:
def _set_klipper_repo(self) -> None: def _set_klipper_repo(self) -> None:
if self.klippy_identified_evt is not None: if self.klippy_identified_evt is not None:
self.klippy_identified_evt.set() self.klippy_identified_evt.set()
kinfo = self.server.get_klippy_info()
if not kinfo: kconn: KlippyConnection = self.server.lookup_component("klippy_connection")
logging.info("No valid klippy info received")
return
kpath: str = kinfo['klipper_path']
executable: str = kinfo['python_path']
kupdater = self.updaters.get('klipper') kupdater = self.updaters.get('klipper')
app_type = AppType.detect(kpath) app_type = AppType.detect(kconn.path)
if ( if (
(isinstance(kupdater, AppDeploy) and (isinstance(kupdater, AppDeploy) and
kupdater.check_same_paths(kpath, executable)) or kupdater.check_same_paths(kconn.path, kconn.executable)) or
(app_type == AppType.NONE and type(kupdater) is BaseDeploy) (app_type == AppType.NONE and type(kupdater) is BaseDeploy)
): ):
# Current Klipper Updater is valid or unnecessary # Current Klipper Updater is valid or unnecessary
return return
# Update paths in the database
db: DBComp = self.server.lookup_component('database')
db.insert_item("moonraker", "update_manager.klipper_path", kpath)
db.insert_item("moonraker", "update_manager.klipper_exec", executable)
kcfg = self.app_config["klipper"] kcfg = self.app_config["klipper"]
kcfg.set_option("path", kpath) kcfg.set_option("path", str(kconn.path))
kcfg.set_option("env", executable) kcfg.set_option("env", str(kconn.executable))
kcfg.set_option("type", str(app_type)) kcfg.set_option("type", str(app_type))
notify = not isinstance(kupdater, AppDeploy) notify = not isinstance(kupdater, AppDeploy)
kclass = get_deploy_class(app_type, BaseDeploy) kclass = get_deploy_class(app_type, BaseDeploy)