Skip to content

Commit

Permalink
Declare setters for name/description properties of actions
Browse files Browse the repository at this point in the history
They are attributes of the base class, so we need overriding properties
to be data descriptors (having both a getter and a setter).
  • Loading branch information
kpushkaryov committed Jan 24, 2024
1 parent c491000 commit 79bac2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pleskdistup/actions/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions pleskdistup/actions/plesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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] = []
Expand All @@ -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}")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 79bac2c

Please sign in to comment.