Skip to content

Commit

Permalink
Use dist.Debian instead of SystemDescription; new submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
ukablan-wpc committed Sep 30, 2024
1 parent 1d202e6 commit 6739d1f
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions debian11to12/upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,37 @@
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 debian11to12.config


class Debian11to12Upgrader(DistUpgrader):
_os_from_name = "Debian"
_os_from_version = "11"
_os_to_name = "Debian"
_os_to_version = "12"
_distro_from = dist.Debian("11")
_distro_to = dist.Debian("12")


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",
))
return f"{self.__class__.__name__}({attrs})"
return f"{self.__class__.__name__}(From {self._distro_from}, To {self._distro_to})"

def __str__(self) -> str:
return f"{self.__class__.__name__}"

@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
def upgrader_name(self) -> str:
return "Plesk::Debian11to12Upgrader"
Expand Down Expand Up @@ -78,7 +68,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 = f"{self._distro_to}"
return {
"Prepare": [
actions.HandleConversionStatus(options.status_flag_path, options.completion_flag_path),
Expand Down Expand Up @@ -141,7 +131,7 @@ def get_check_actions(self, options: typing.Any, phase: Phase) -> typing.List[ac
]

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}. The process consists of the following general stages:
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.
-- Conversion (about 15 minutes) - Plesk and system dist-upgrade is performed.
Expand Down Expand Up @@ -180,8 +170,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 Debian11to12Upgrader.supports(from_system, to_system)

Expand Down

0 comments on commit 6739d1f

Please sign in to comment.