Skip to content

Commit

Permalink
Adapt Ubuntu20to22Upgrader to new dist-upgrader version
Browse files Browse the repository at this point in the history
  • Loading branch information
kpushkaryov committed Jun 21, 2024
1 parent c14a01a commit e1d2d07
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions ubuntu20to22/upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})"

Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -179,7 +166,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.
Expand Down Expand Up @@ -220,8 +207,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)

Expand Down

0 comments on commit e1d2d07

Please sign in to comment.