update_manager: remove unused reinstall functionality

This functionality was intended to allow for an automated
reinstallation between "git_repo" and "zip" types.  The
"zip" type remains unused, and attempting to automate
this would likely be unreliable.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-02-12 12:16:09 -05:00
parent b2d84bc733
commit 357276b1d9
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
4 changed files with 28 additions and 92 deletions

View File

@ -37,8 +37,7 @@ SUPPORTED_CHANNELS = {
"git_repo": ["dev", "beta"] "git_repo": ["dev", "beta"]
} }
TYPE_TO_CHANNEL = { TYPE_TO_CHANNEL = {
"zip": "stable", "zip": "beta",
"zip_beta": "beta",
"git_repo": "dev" "git_repo": "dev"
} }
@ -57,12 +56,17 @@ class AppDeploy(BaseDeploy):
self.channel = config.get( self.channel = config.get(
"channel", TYPE_TO_CHANNEL[self.type] "channel", TYPE_TO_CHANNEL[self.type]
) )
if self.type == "zip_beta": self.channel_invalid: bool = False
if self.channel not in SUPPORTED_CHANNELS[self.type]:
self.channel_invalid = True
invalid_channel = self.channel
self.channel = TYPE_TO_CHANNEL[self.type]
self.server.add_warning( self.server.add_warning(
f"Config Section [{config.get_name()}], Option 'type: " f"[{config.get_name()}]: Invalid value '{invalid_channel}' for "
"zip_beta', value 'zip_beta' is deprecated. Set 'type' " f"option 'channel'. Type '{self.type}' supports the following "
"to zip and 'channel' to 'beta'") f"channels: {SUPPORTED_CHANNELS[self.type]}. Falling back to "
self.type = "zip" f"channel '{self.channel}"
)
self.path = pathlib.Path( self.path = pathlib.Path(
config.get('path')).expanduser().resolve() config.get('path')).expanduser().resolve()
if ( if (
@ -72,10 +76,6 @@ class AppDeploy(BaseDeploy):
fm: FileManager = self.server.lookup_component("file_manager") fm: FileManager = self.server.lookup_component("file_manager")
fm.add_reserved_path(f"update_manager {self.name}", self.path) fm.add_reserved_path(f"update_manager {self.name}", self.path)
executable = config.get('env', None) executable = config.get('env', None)
if self.channel not in SUPPORTED_CHANNELS[self.type]:
raise config.error(
f"Invalid Channel '{self.channel}' for config "
f"section [{config.get_name()}], type: {self.type}")
self._verify_path(config, 'path', self.path, check_file=False) self._verify_path(config, 'path', self.path, check_file=False)
self.executable: Optional[pathlib.Path] = None self.executable: Optional[pathlib.Path] = None
self.py_exec: Optional[pathlib.Path] = None self.py_exec: Optional[pathlib.Path] = None
@ -184,7 +184,6 @@ class AppDeploy(BaseDeploy):
async def initialize(self) -> Dict[str, Any]: async def initialize(self) -> Dict[str, Any]:
storage = await super().initialize() storage = await super().initialize()
self.need_channel_update = storage.get("need_channel_update", False)
self._is_valid = storage.get("is_valid", False) self._is_valid = storage.get("is_valid", False)
self.pip_version = tuple(storage.get("pip_version", [])) self.pip_version = tuple(storage.get("pip_version", []))
if self.pip_version: if self.pip_version:
@ -211,9 +210,6 @@ class AppDeploy(BaseDeploy):
if check_exe and not os.access(path, os.X_OK): if check_exe and not os.access(path, os.X_OK):
raise config.error(f"{base_msg} is not executable") raise config.error(f"{base_msg} is not executable")
def check_need_channel_swap(self) -> bool:
return self.need_channel_update
def get_configured_type(self) -> str: def get_configured_type(self) -> str:
return self.type return self.type
@ -241,9 +237,6 @@ class AppDeploy(BaseDeploy):
) -> None: ) -> None:
raise NotImplementedError raise NotImplementedError
async def reinstall(self):
raise NotImplementedError
async def restart_service(self) -> None: async def restart_service(self) -> None:
if not self.managed_services: if not self.managed_services:
return return
@ -270,7 +263,7 @@ class AppDeploy(BaseDeploy):
return { return {
'channel': self.channel, 'channel': self.channel,
'debug_enabled': self.server.is_debug_enabled(), 'debug_enabled': self.server.is_debug_enabled(),
'need_channel_update': self.need_channel_update, 'channel_invalid': self.channel_invalid,
'is_valid': self._is_valid, 'is_valid': self._is_valid,
'configured_type': self.type, 'configured_type': self.type,
'info_tags': self.info_tags 'info_tags': self.info_tags
@ -279,7 +272,6 @@ class AppDeploy(BaseDeploy):
def get_persistent_data(self) -> Dict[str, Any]: def get_persistent_data(self) -> Dict[str, Any]:
storage = super().get_persistent_data() storage = super().get_persistent_data()
storage['is_valid'] = self._is_valid storage['is_valid'] = self._is_valid
storage['need_channel_update'] = self.need_channel_update
storage['pip_version'] = list(self.pip_version) storage['pip_version'] = list(self.pip_version)
return storage return storage

View File

@ -35,14 +35,6 @@ class GitDeploy(AppDeploy):
cmd_helper, self.path, self.name, self.origin, cmd_helper, self.path, self.name, self.origin,
self.moved_origin, self.primary_branch, self.channel self.moved_origin, self.primary_branch, self.channel
) )
if self.type != 'git_repo':
self.need_channel_update = True
@staticmethod
async def from_application(app: AppDeploy) -> GitDeploy:
new_app = GitDeploy(app.config, app.cmd_helper)
await new_app.reinstall()
return new_app
async def initialize(self) -> Dict[str, Any]: async def initialize(self) -> Dict[str, Any]:
storage = await super().initialize() storage = await super().initialize()
@ -60,10 +52,7 @@ class GitDeploy(AppDeploy):
async def _update_repo_state(self, need_fetch: bool = True) -> None: async def _update_repo_state(self, need_fetch: bool = True) -> None:
self._is_valid = False self._is_valid = False
await self.repo.initialize(need_fetch=need_fetch) await self.repo.initialize(need_fetch=need_fetch)
self.log_info( self.log_info(f"Channel: {self.channel}")
f"Channel: {self.channel}, "
f"Need Channel Update: {self.need_channel_update}"
)
if not self.repo.check_is_valid(): if not self.repo.check_is_valid():
self.log_info("Repo validation check failed") self.log_info("Repo validation check failed")
if self.server.is_debug_enabled(): if self.server.is_debug_enabled():

View File

@ -68,6 +68,11 @@ def get_deploy_class(app_path: str) -> Type:
class UpdateManager: class UpdateManager:
def __init__(self, config: ConfigHelper) -> None: def __init__(self, config: ConfigHelper) -> None:
_deployers = {
"web": WebClientDeploy,
"git_repo": GitDeploy,
"zip": ZipDeploy
}
self.server = config.get_server() self.server = config.get_server()
self.event_loop = self.server.get_event_loop() self.event_loop = self.server.get_event_loop()
self.kconn: KlippyConnection self.kconn: KlippyConnection
@ -118,15 +123,12 @@ class UpdateManager:
continue continue
try: try:
client_type = cfg.get("type") client_type = cfg.get("type")
if client_type in ["web", "web_beta"]: deployer = _deployers.get(client_type, None)
self.updaters[name] = WebClientDeploy(cfg, self.cmd_helper) if deployer is None:
elif client_type in ["git_repo", "zip", "zip_beta"]:
path = os.path.expanduser(cfg.get('path'))
dclass = get_deploy_class(path)
self.updaters[name] = dclass(cfg, self.cmd_helper)
else:
self.server.add_warning( self.server.add_warning(
f"Invalid type '{client_type}' for section [{section}]") f"Invalid type '{client_type}' for section [{section}]")
else:
self.updaters[name] = deployer(cfg, self.cmd_helper)
except Exception as e: except Exception as e:
self.server.add_warning( self.server.add_warning(
f"[update_manager]: Failed to load extension {name}: {e}" f"[update_manager]: Failed to load extension {name}: {e}"
@ -281,7 +283,6 @@ class UpdateManager:
async with self.cmd_request_lock: async with self.cmd_request_lock:
self.cmd_helper.set_update_info(app, id(web_request)) self.cmd_helper.set_update_info(app, id(web_request))
try: try:
if not await self._check_need_reinstall(app):
await updater.update() await updater.update()
except Exception as e: except Exception as e:
self.cmd_helper.notify_update_response( self.cmd_helper.notify_update_response(
@ -310,7 +311,6 @@ class UpdateManager:
if name in ['klipper', 'moonraker', 'system']: if name in ['klipper', 'moonraker', 'system']:
continue continue
app_name = name app_name = name
if not await self._check_need_reinstall(app_name):
await updater.update() await updater.update()
# Update Klipper # Update Klipper
@ -318,8 +318,6 @@ class UpdateManager:
kupdater = self.updaters.get('klipper') kupdater = self.updaters.get('klipper')
if isinstance(kupdater, AppDeploy): if isinstance(kupdater, AppDeploy):
self.klippy_identified_evt = asyncio.Event() self.klippy_identified_evt = asyncio.Event()
check_restart = True
if not await self._check_need_reinstall(app_name):
check_restart = await kupdater.update() check_restart = await kupdater.update()
if self.cmd_helper.needs_service_restart(app_name): if self.cmd_helper.needs_service_restart(app_name):
await kupdater.restart_service() await kupdater.restart_service()
@ -336,13 +334,12 @@ class UpdateManager:
"Klippy reconnect timed out...") "Klippy reconnect timed out...")
else: else:
self.cmd_helper.notify_update_response( self.cmd_helper.notify_update_response(
f"Klippy Reconnected") "Klippy Reconnected")
self.klippy_identified_evt = None self.klippy_identified_evt = None
# Update Moonraker # Update Moonraker
app_name = 'moonraker' app_name = 'moonraker'
moon_updater = cast(AppDeploy, self.updaters["moonraker"]) moon_updater = cast(AppDeploy, self.updaters["moonraker"])
if not await self._check_need_reinstall(app_name):
await moon_updater.update() await moon_updater.update()
if self.cmd_helper.needs_service_restart(app_name): if self.cmd_helper.needs_service_restart(app_name):
await moon_updater.restart_service() await moon_updater.restart_service()
@ -357,28 +354,6 @@ class UpdateManager:
self.cmd_helper.clear_update_info() self.cmd_helper.clear_update_info()
return "ok" return "ok"
async def _check_need_reinstall(self, name: str) -> bool:
if name not in self.updaters:
return False
updater = self.updaters[name]
if not isinstance(updater, AppDeploy):
return False
if not updater.check_need_channel_swap():
return False
app_type = updater.get_configured_type()
if app_type == "git_repo":
deploy_class: Type = GitDeploy
else:
deploy_class = ZipDeploy
if isinstance(updater, deploy_class):
# Here the channel swap can be done without instantiating a new
# class, as it will automatically be done when the user updates.
return False
# Instantiate the new updater. This will perform a reinstallation
new_updater = await deploy_class.from_application(updater)
self.updaters[name] = new_updater
return True
async def _handle_status_request(self, async def _handle_status_request(self,
web_request: WebRequest web_request: WebRequest
) -> Dict[str, Any]: ) -> Dict[str, Any]:
@ -1187,15 +1162,7 @@ class WebClientDeploy(BaseDeploy):
self.owner, self.project_name = self.repo.split("/", 1) self.owner, self.project_name = self.repo.split("/", 1)
self.path = pathlib.Path(config.get("path")).expanduser().resolve() self.path = pathlib.Path(config.get("path")).expanduser().resolve()
self.type = config.get('type') self.type = config.get('type')
def_channel = "stable" self.channel = config.get("channel", "stable")
if self.type == "web_beta":
def_channel = "beta"
self.server.add_warning(
f"Config Section [{config.get_name()}], option 'type': "
"web_beta', value 'web_beta' is deprecated. Set 'type' to "
"web and 'channel' to 'beta'")
self.type = "zip"
self.channel = config.get("channel", def_channel)
if self.channel not in ["stable", "beta"]: if self.channel not in ["stable", "beta"]:
raise config.error( raise config.error(
f"Invalid Channel '{self.channel}' for config " f"Invalid Channel '{self.channel}' for config "

View File

@ -37,7 +37,6 @@ RINFO_KEYS = [
class ZipDeploy(AppDeploy): class ZipDeploy(AppDeploy):
def __init__(self, config: ConfigHelper, cmd_helper: CommandHelper) -> None: def __init__(self, config: ConfigHelper, cmd_helper: CommandHelper) -> None:
super().__init__(config, cmd_helper) super().__init__(config, cmd_helper)
self.need_channel_update = self.type != "zip"
self.official_repo: str = "?" self.official_repo: str = "?"
self.owner: str = "?" self.owner: str = "?"
# Extract repo from origin for validation # Extract repo from origin for validation
@ -55,12 +54,6 @@ class ZipDeploy(AppDeploy):
self.python_pkg_list: List[str] = [] self.python_pkg_list: List[str] = []
self.release_download_info: Tuple[str, str, int] = ("?", "?", 0) self.release_download_info: Tuple[str, str, int] = ("?", "?", 0)
@staticmethod
async def from_application(app: AppDeploy) -> ZipDeploy:
new_app = ZipDeploy(app.config, app.cmd_helper)
await new_app.reinstall()
return new_app
async def initialize(self) -> Dict[str, Any]: async def initialize(self) -> Dict[str, Any]:
storage = await super().initialize() storage = await super().initialize()
self.source_checksum: str = storage.get("source_checksum", "?") self.source_checksum: str = storage.get("source_checksum", "?")
@ -134,10 +127,6 @@ class ZipDeploy(AppDeploy):
for key in RINFO_KEYS: for key in RINFO_KEYS:
if key not in release_info: if key not in release_info:
self._add_error(f"Missing release info item: {key}") self._add_error(f"Missing release info item: {key}")
if 'channel' in release_info:
local_channel = release_info['channel']
if self.channel == "stable" and local_channel == "beta":
self.need_channel_update = True
self.full_version = release_info.get('long_version', "?") self.full_version = release_info.get('long_version', "?")
self.short_version = self._get_tag_version( self.short_version = self._get_tag_version(
release_info.get('git_version', "")) release_info.get('git_version', ""))
@ -306,7 +295,6 @@ class ZipDeploy(AppDeploy):
f" Repo: {self.official_repo}\n" f" Repo: {self.official_repo}\n"
f" Path: {self.path}\n" f" Path: {self.path}\n"
f" Pristine: {self.pristine}\n" f" Pristine: {self.pristine}\n"
f" Need Channel Update: {self.need_channel_update}\n"
f" Commits Behind: {len(self.commit_log)}\n" f" Commits Behind: {len(self.commit_log)}\n"
f"Current Release Info:\n" f"Current Release Info:\n"
f" Source Checksum: {self.source_checksum}\n" f" Source Checksum: {self.source_checksum}\n"