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:
parent
b2d84bc733
commit
357276b1d9
|
@ -37,8 +37,7 @@ SUPPORTED_CHANNELS = {
|
|||
"git_repo": ["dev", "beta"]
|
||||
}
|
||||
TYPE_TO_CHANNEL = {
|
||||
"zip": "stable",
|
||||
"zip_beta": "beta",
|
||||
"zip": "beta",
|
||||
"git_repo": "dev"
|
||||
}
|
||||
|
||||
|
@ -57,12 +56,17 @@ class AppDeploy(BaseDeploy):
|
|||
self.channel = config.get(
|
||||
"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(
|
||||
f"Config Section [{config.get_name()}], Option 'type: "
|
||||
"zip_beta', value 'zip_beta' is deprecated. Set 'type' "
|
||||
"to zip and 'channel' to 'beta'")
|
||||
self.type = "zip"
|
||||
f"[{config.get_name()}]: Invalid value '{invalid_channel}' for "
|
||||
f"option 'channel'. Type '{self.type}' supports the following "
|
||||
f"channels: {SUPPORTED_CHANNELS[self.type]}. Falling back to "
|
||||
f"channel '{self.channel}"
|
||||
)
|
||||
self.path = pathlib.Path(
|
||||
config.get('path')).expanduser().resolve()
|
||||
if (
|
||||
|
@ -72,10 +76,6 @@ class AppDeploy(BaseDeploy):
|
|||
fm: FileManager = self.server.lookup_component("file_manager")
|
||||
fm.add_reserved_path(f"update_manager {self.name}", self.path)
|
||||
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.executable: 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]:
|
||||
storage = await super().initialize()
|
||||
self.need_channel_update = storage.get("need_channel_update", False)
|
||||
self._is_valid = storage.get("is_valid", False)
|
||||
self.pip_version = tuple(storage.get("pip_version", []))
|
||||
if self.pip_version:
|
||||
|
@ -211,9 +210,6 @@ class AppDeploy(BaseDeploy):
|
|||
if check_exe and not os.access(path, os.X_OK):
|
||||
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:
|
||||
return self.type
|
||||
|
||||
|
@ -241,9 +237,6 @@ class AppDeploy(BaseDeploy):
|
|||
) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
async def reinstall(self):
|
||||
raise NotImplementedError
|
||||
|
||||
async def restart_service(self) -> None:
|
||||
if not self.managed_services:
|
||||
return
|
||||
|
@ -270,7 +263,7 @@ class AppDeploy(BaseDeploy):
|
|||
return {
|
||||
'channel': self.channel,
|
||||
'debug_enabled': self.server.is_debug_enabled(),
|
||||
'need_channel_update': self.need_channel_update,
|
||||
'channel_invalid': self.channel_invalid,
|
||||
'is_valid': self._is_valid,
|
||||
'configured_type': self.type,
|
||||
'info_tags': self.info_tags
|
||||
|
@ -279,7 +272,6 @@ class AppDeploy(BaseDeploy):
|
|||
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
|
||||
storage['pip_version'] = list(self.pip_version)
|
||||
return storage
|
||||
|
||||
|
|
|
@ -35,14 +35,6 @@ class GitDeploy(AppDeploy):
|
|||
cmd_helper, self.path, self.name, self.origin,
|
||||
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]:
|
||||
storage = await super().initialize()
|
||||
|
@ -60,10 +52,7 @@ class GitDeploy(AppDeploy):
|
|||
async def _update_repo_state(self, need_fetch: bool = True) -> None:
|
||||
self._is_valid = False
|
||||
await self.repo.initialize(need_fetch=need_fetch)
|
||||
self.log_info(
|
||||
f"Channel: {self.channel}, "
|
||||
f"Need Channel Update: {self.need_channel_update}"
|
||||
)
|
||||
self.log_info(f"Channel: {self.channel}")
|
||||
if not self.repo.check_is_valid():
|
||||
self.log_info("Repo validation check failed")
|
||||
if self.server.is_debug_enabled():
|
||||
|
|
|
@ -68,6 +68,11 @@ def get_deploy_class(app_path: str) -> Type:
|
|||
|
||||
class UpdateManager:
|
||||
def __init__(self, config: ConfigHelper) -> None:
|
||||
_deployers = {
|
||||
"web": WebClientDeploy,
|
||||
"git_repo": GitDeploy,
|
||||
"zip": ZipDeploy
|
||||
}
|
||||
self.server = config.get_server()
|
||||
self.event_loop = self.server.get_event_loop()
|
||||
self.kconn: KlippyConnection
|
||||
|
@ -118,15 +123,12 @@ class UpdateManager:
|
|||
continue
|
||||
try:
|
||||
client_type = cfg.get("type")
|
||||
if client_type in ["web", "web_beta"]:
|
||||
self.updaters[name] = WebClientDeploy(cfg, self.cmd_helper)
|
||||
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:
|
||||
deployer = _deployers.get(client_type, None)
|
||||
if deployer is None:
|
||||
self.server.add_warning(
|
||||
f"Invalid type '{client_type}' for section [{section}]")
|
||||
else:
|
||||
self.updaters[name] = deployer(cfg, self.cmd_helper)
|
||||
except Exception as e:
|
||||
self.server.add_warning(
|
||||
f"[update_manager]: Failed to load extension {name}: {e}"
|
||||
|
@ -281,8 +283,7 @@ class UpdateManager:
|
|||
async with self.cmd_request_lock:
|
||||
self.cmd_helper.set_update_info(app, id(web_request))
|
||||
try:
|
||||
if not await self._check_need_reinstall(app):
|
||||
await updater.update()
|
||||
await updater.update()
|
||||
except Exception as e:
|
||||
self.cmd_helper.notify_update_response(
|
||||
f"Error updating {app}: {e}", is_complete=True)
|
||||
|
@ -310,17 +311,14 @@ class UpdateManager:
|
|||
if name in ['klipper', 'moonraker', 'system']:
|
||||
continue
|
||||
app_name = name
|
||||
if not await self._check_need_reinstall(app_name):
|
||||
await updater.update()
|
||||
await updater.update()
|
||||
|
||||
# Update Klipper
|
||||
app_name = 'klipper'
|
||||
kupdater = self.updaters.get('klipper')
|
||||
if isinstance(kupdater, AppDeploy):
|
||||
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):
|
||||
await kupdater.restart_service()
|
||||
check_restart = True
|
||||
|
@ -336,14 +334,13 @@ class UpdateManager:
|
|||
"Klippy reconnect timed out...")
|
||||
else:
|
||||
self.cmd_helper.notify_update_response(
|
||||
f"Klippy Reconnected")
|
||||
"Klippy Reconnected")
|
||||
self.klippy_identified_evt = None
|
||||
|
||||
# Update Moonraker
|
||||
app_name = '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):
|
||||
await moon_updater.restart_service()
|
||||
self.cmd_helper.set_full_complete(True)
|
||||
|
@ -357,28 +354,6 @@ class UpdateManager:
|
|||
self.cmd_helper.clear_update_info()
|
||||
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,
|
||||
web_request: WebRequest
|
||||
) -> Dict[str, Any]:
|
||||
|
@ -1187,15 +1162,7 @@ class WebClientDeploy(BaseDeploy):
|
|||
self.owner, self.project_name = self.repo.split("/", 1)
|
||||
self.path = pathlib.Path(config.get("path")).expanduser().resolve()
|
||||
self.type = config.get('type')
|
||||
def_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)
|
||||
self.channel = config.get("channel", "stable")
|
||||
if self.channel not in ["stable", "beta"]:
|
||||
raise config.error(
|
||||
f"Invalid Channel '{self.channel}' for config "
|
||||
|
|
|
@ -37,7 +37,6 @@ RINFO_KEYS = [
|
|||
class ZipDeploy(AppDeploy):
|
||||
def __init__(self, config: ConfigHelper, cmd_helper: CommandHelper) -> None:
|
||||
super().__init__(config, cmd_helper)
|
||||
self.need_channel_update = self.type != "zip"
|
||||
self.official_repo: str = "?"
|
||||
self.owner: str = "?"
|
||||
# Extract repo from origin for validation
|
||||
|
@ -55,12 +54,6 @@ class ZipDeploy(AppDeploy):
|
|||
self.python_pkg_list: List[str] = []
|
||||
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]:
|
||||
storage = await super().initialize()
|
||||
self.source_checksum: str = storage.get("source_checksum", "?")
|
||||
|
@ -134,10 +127,6 @@ class ZipDeploy(AppDeploy):
|
|||
for key in RINFO_KEYS:
|
||||
if key not in release_info:
|
||||
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.short_version = self._get_tag_version(
|
||||
release_info.get('git_version', ""))
|
||||
|
@ -306,7 +295,6 @@ class ZipDeploy(AppDeploy):
|
|||
f" Repo: {self.official_repo}\n"
|
||||
f" Path: {self.path}\n"
|
||||
f" Pristine: {self.pristine}\n"
|
||||
f" Need Channel Update: {self.need_channel_update}\n"
|
||||
f" Commits Behind: {len(self.commit_log)}\n"
|
||||
f"Current Release Info:\n"
|
||||
f" Source Checksum: {self.source_checksum}\n"
|
||||
|
|
Loading…
Reference in New Issue