update_manager: add support for python applications

Signed-off-by:  Eric Callahan <arksine.code@gmail.com
This commit is contained in:
Eric Callahan
2024-05-26 14:20:04 -04:00
parent b8921ca593
commit 96b1c22e28
3 changed files with 25 additions and 16 deletions

View File

@@ -52,25 +52,30 @@ class AppType(ExtendedEnum):
WEB = 2
GIT_REPO = 3
ZIP = 4
PYTHON = 5
@classmethod
def detect(cls, app_path: Union[str, pathlib.Path, None] = None):
# If app path is None, detect Moonraker
if isinstance(app_path, str):
app_path = pathlib.Path(app_path).expanduser()
if source_info.is_git_repo(app_path):
return AppType.GIT_REPO
elif app_path is None and source_info.is_vitualenv_project():
return AppType.PYTHON
else:
return AppType.NONE
class Channel(ExtendedEnum):
STABLE = 1
BETA = 2
DEV = 3
def get_app_type(app_path: Union[str, pathlib.Path]) -> AppType:
if isinstance(app_path, str):
app_path = pathlib.Path(app_path).expanduser()
# None type will perform checks on Moonraker
if source_info.is_git_repo(app_path):
return AppType.GIT_REPO
else:
return AppType.NONE
def get_base_configuration(config: ConfigHelper) -> ConfigHelper:
server = config.get_server()
base_cfg = copy.deepcopy(BASE_CONFIG)
base_cfg["moonraker"]["type"] = str(get_app_type(source_info.source_path()))
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
@@ -78,7 +83,7 @@ def get_base_configuration(config: ConfigHelper) -> ConfigHelper:
base_cfg["klipper"]["env"] = db.get_item(
"moonraker", "update_manager.klipper_exec", KLIPPER_DEFAULT_EXEC
).result()
base_cfg["klipper"]["type"] = str(get_app_type(base_cfg["klipper"]["path"]))
base_cfg["klipper"]["type"] = str(AppType.detect(base_cfg["klipper"]["path"]))
channel = config.get("channel", "dev")
base_cfg["moonraker"]["channel"] = channel
base_cfg["klipper"]["channel"] = channel