From 74a03fca5903ed5341c3efc65a582547c6904c32 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 2 Dec 2021 08:45:30 -0500 Subject: [PATCH] app_deploy: add support for persistent state Signed-off-by: Eric Callahan --- .../components/update_manager/app_deploy.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/moonraker/components/update_manager/app_deploy.py b/moonraker/components/update_manager/app_deploy.py index 8f549df..a457842 100644 --- a/moonraker/components/update_manager/app_deploy.py +++ b/moonraker/components/update_manager/app_deploy.py @@ -8,6 +8,7 @@ from __future__ import annotations import pathlib import shutil import hashlib +import json from .base_deploy import BaseDeploy # Annotation imports @@ -40,9 +41,11 @@ class AppDeploy(BaseDeploy): cmd_helper: CommandHelper, app_params: Optional[Dict[str, Any]] ) -> None: - super().__init__(config, cmd_helper) self.config = config self.app_params = app_params + cfg_hash = self._calc_config_hash() + super().__init__(config, cmd_helper, prefix="Application", + cfg_hash=cfg_hash) self.debug = self.cmd_helper.is_debug_enabled() if app_params is not None: self.channel: str = app_params['channel'] @@ -69,8 +72,9 @@ class AppDeploy(BaseDeploy): self.venv_args = config.get('venv_args', None) self.is_service = config.getboolean("is_system_service", True) - self.need_channel_update = False - self._is_valid = False + storage = self._load_storage() + self.need_channel_update = storage.get('need_channel_upate', False) + self._is_valid = storage.get('is_valid', False) # We need to fetch all potential options for an Application. Not # all options apply to each subtype, however we can't limit the @@ -99,6 +103,15 @@ class AppDeploy(BaseDeploy): app_path = pathlib.Path(app_path).expanduser() return app_path.joinpath('.git').exists() + def _calc_config_hash(self) -> str: + cfg_hash = self.config.get_hash() + if self.app_params is None: + return cfg_hash.hexdigest() + else: + app_bytes = json.dumps(self.app_params).encode() + cfg_hash.update(app_bytes) + return cfg_hash.hexdigest() + def _verify_path(self, config: ConfigHelper, option: str, @@ -173,6 +186,12 @@ class AppDeploy(BaseDeploy): 'configured_type': self.type } + def get_persistent_data(self) -> Dict[str, Any]: + storage = super().get_persistent_data() + storage['is_valid'] = self._is_valid + storage['need_channel_update'] = self.need_channel_update + return storage + async def _get_file_hash(self, filename: Optional[pathlib.Path] ) -> Optional[str]: