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.
from __future__ import annotations
import os
import sys
import copy
import pathlib
@ -20,10 +19,7 @@ from typing import (
if TYPE_CHECKING:
from ...confighelper import ConfigHelper
from ..database import MoonrakerDatabase
KLIPPER_DEFAULT_PATH = os.path.expanduser("~/klipper")
KLIPPER_DEFAULT_EXEC = os.path.expanduser("~/klippy-env/bin/python")
from ..klippy_connection import KlippyConnection
BASE_CONFIG: Dict[str, Dict[str, str]] = {
"moonraker": {
@ -98,15 +94,11 @@ class Channel(ExtendedEnum):
def get_base_configuration(config: ConfigHelper) -> ConfigHelper:
server = config.get_server()
base_cfg = copy.deepcopy(BASE_CONFIG)
kconn: KlippyConnection = server.lookup_component("klippy_connection")
base_cfg["moonraker"]["type"] = str(AppType.detect())
db: MoonrakerDatabase = server.lookup_component('database')
base_cfg["klipper"]["path"] = db.get_item(
"moonraker", "update_manager.klipper_path", KLIPPER_DEFAULT_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"]))
base_cfg["klipper"]["path"] = str(kconn.path)
base_cfg["klipper"]["env"] = str(kconn.executable)
base_cfg["klipper"]["type"] = str(AppType.detect(kconn.path))
default_channel = config.get("channel", None)
# Check for configuration overrides
for app_name in base_cfg.keys():

View File

@ -204,28 +204,20 @@ class UpdateManager:
def _set_klipper_repo(self) -> None:
if self.klippy_identified_evt is not None:
self.klippy_identified_evt.set()
kinfo = self.server.get_klippy_info()
if not kinfo:
logging.info("No valid klippy info received")
return
kpath: str = kinfo['klipper_path']
executable: str = kinfo['python_path']
kconn: KlippyConnection = self.server.lookup_component("klippy_connection")
kupdater = self.updaters.get('klipper')
app_type = AppType.detect(kpath)
app_type = AppType.detect(kconn.path)
if (
(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)
):
# Current Klipper Updater is valid or unnecessary
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.set_option("path", kpath)
kcfg.set_option("env", executable)
kcfg.set_option("path", str(kconn.path))
kcfg.set_option("env", str(kconn.executable))
kcfg.set_option("type", str(app_type))
notify = not isinstance(kupdater, AppDeploy)
kclass = get_deploy_class(app_type, BaseDeploy)