From 79bac2c0fd2ea694b5148411e0b98f48eb093b3b Mon Sep 17 00:00:00 2001 From: Kirill Pushkarev Date: Wed, 24 Jan 2024 18:19:15 +0700 Subject: [PATCH] Declare setters for name/description properties of actions They are attributes of the base class, so we need overriding properties to be data descriptors (having both a getter and a setter). --- pleskdistup/actions/packages.py | 4 ++++ pleskdistup/actions/plesk.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pleskdistup/actions/packages.py b/pleskdistup/actions/packages.py index 53be2bb..4eb0b5a 100644 --- a/pleskdistup/actions/packages.py +++ b/pleskdistup/actions/packages.py @@ -55,6 +55,10 @@ def __init__( def name(self) -> str: return f"{self._name}: {', '.join(self.packages_to_install)}" + @name.setter + def name(self, val: str) -> None: + self._name = val + def _prepare_action(self) -> action.ActionResult: dpkg.safely_install_packages(self.packages_to_install, protected_pkgs=self.protected_packages) return action.ActionResult() diff --git a/pleskdistup/actions/plesk.py b/pleskdistup/actions/plesk.py index fe4a7b4..73f4dd8 100644 --- a/pleskdistup/actions/plesk.py +++ b/pleskdistup/actions/plesk.py @@ -125,6 +125,10 @@ def __init__( def name(self) -> str: return f"{self._name}: {', '.join(self.components_to_remove)}" + @name.setter + def name(self, val: str) -> None: + self._name = val + @property def _removed_components_list_file(self) -> str: return os.path.join(self.state_dir, f"plesk-dist-upgrade-{self.__class__.__name__}.txt") @@ -367,6 +371,10 @@ def name(self) -> str: res += f" {', '.join(comp_list)}" return res + @name.setter + def name(self, val: str) -> None: + self._name = val + @property def description(self) -> str: desc: typing.List[str] = [] @@ -378,6 +386,10 @@ def description(self) -> str: return "\n".join(desc) return "Plesk components state check passed" + @description.setter + def description(self, val: str) -> None: + raise NotImplementedError + def _do_check(self) -> bool: comp_list = plesk.list_installed_components() log.debug(f"Detected installed Plesk components: {comp_list}") @@ -434,10 +446,18 @@ def __init__( def name(self) -> str: return self._name.format(min_version=self.min_version_str) + @name.setter + def name(self, val: str) -> None: + self._name = val + @property def description(self) -> str: return self._description.format(min_version=self.min_version_str) + @description.setter + def description(self, val: str) -> None: + self._description = val + @property def min_version_str(self) -> str: return ".".join(str(v) for v in self.min_version)