From 4325833b9c500a569f2adbbbd47fc0f644022019 Mon Sep 17 00:00:00 2001 From: Kirill Pushkarev Date: Fri, 21 Jun 2024 11:11:43 +0700 Subject: [PATCH] Adapt Ubuntu20to22Upgrader to new dist-upgrader version --- ubuntu20to22/upgrader.py | 44 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/ubuntu20to22/upgrader.py b/ubuntu20to22/upgrader.py index 94fecfa..3cbfe2a 100644 --- a/ubuntu20to22/upgrader.py +++ b/ubuntu20to22/upgrader.py @@ -7,24 +7,21 @@ from pleskdistup import actions from pleskdistup.common import action, feedback from pleskdistup.phase import Phase -from pleskdistup.upgrader import DistUpgrader, DistUpgraderFactory, PathType, SystemDescription +from pleskdistup.upgrader import dist, DistUpgrader, DistUpgraderFactory, PathType import ubuntu20to22.config class Ubuntu20to22Upgrader(DistUpgrader): - _os_from_name = "Ubuntu" - _os_from_version = "20" - _os_to_name = "Ubuntu" - _os_to_version = "22" + _distro_from = dist.Ubuntu("20") + _distro_to = dist.Ubuntu("22") def __init__(self): super().__init__() def __repr__(self) -> str: attrs = ", ".join(f"{k}={getattr(self, k)!r}" for k in ( - "_os_from_name", "_os_from_version", - "_os_to_name", "_os_to_version", + "_distro_from", "_distro_to", )) return f"{self.__class__.__name__}({attrs})" @@ -34,22 +31,12 @@ def __str__(self) -> str: @classmethod def supports( cls, - from_system: typing.Optional[SystemDescription] = None, - to_system: typing.Optional[SystemDescription] = None + from_system: typing.Optional[dist.Distro] = None, + to_system: typing.Optional[dist.Distro] = None ) -> bool: - def matching_system( - system: SystemDescription, - os_name: str, - os_version: str, - ) -> bool: - return ( - (system.os_name is None or system.os_name == os_name) - and (system.os_version is None or system.os_version == os_version) - ) - return ( - (from_system is None or matching_system(from_system, cls._os_from_name, cls._os_from_version)) - and (to_system is None or matching_system(to_system, cls._os_to_name, cls._os_to_version)) + (from_system is None or cls._distro_from == from_system) + and (to_system is None or cls._distro_to == to_system) ) @property @@ -82,7 +69,7 @@ def construct_actions( options: typing.Any, phase: Phase ) -> typing.Dict[str, typing.List[action.ActiveAction]]: - new_os = f"{self._os_to_name} {self._os_to_version}" + new_os = str(self._distro_to) return { "Prepare": [ actions.HandleConversionStatus( @@ -124,7 +111,12 @@ def construct_actions( actions.EnableEnhancedSecurityMode(), ], "Switch repositories": [ - actions.SetupUbuntuRepositories("focal", "jammy"), + actions.SetupUbuntuRepositories( + from_codename="focal", + from_version="20.04", + to_codename="jammy", + to_version="22.04" + ), actions.SwitchPleskRepositories(to_os_version="22.04"), ], "Dist-upgrade": [ @@ -179,7 +171,7 @@ def get_check_actions( ] def parse_args(self, args: typing.Sequence[str]) -> None: - DESC_MESSAGE = f"""Use this upgrader to dist-upgrade an {self._os_from_name} {self._os_from_version} server with Plesk to {self._os_to_name} {self._os_to_version}. + DESC_MESSAGE = f"""Use this upgrader to dist-upgrade an {self._distro_from} server with Plesk to {self._distro_to}. The process consists of the following general stages: -- Preparation (about 5 minutes) - The OS is prepared for the conversion. @@ -220,8 +212,8 @@ def __str__(self) -> str: def supports( self, - from_system: typing.Optional[SystemDescription] = None, - to_system: typing.Optional[SystemDescription] = None + from_system: typing.Optional[dist.Distro] = None, + to_system: typing.Optional[dist.Distro] = None ) -> bool: return Ubuntu20to22Upgrader.supports(from_system, to_system)