From 0af2886d628cca31c2926e5cb97b7c29501eed67 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Fri, 2 Aug 2024 15:53:11 +0300 Subject: [PATCH 1/2] Do not delete the action data JSON file if an error occurs during the final stage --- pleskdistup/common/src/action.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pleskdistup/common/src/action.py b/pleskdistup/common/src/action.py index 24db1ee..25aa25c 100644 --- a/pleskdistup/common/src/action.py +++ b/pleskdistup/common/src/action.py @@ -393,7 +393,9 @@ def __enter__(self): return self def __exit__(self, *kwargs): - if os.path.exists(self.path_to_actions_data): + # Do not remove the actions data if an error occurs because + # customer will likely want to retry after correcting the error on their end + if self.error is not None and os.path.exists(self.path_to_actions_data): os.remove(self.path_to_actions_data) def _get_flow(self) -> typing.Dict[str, typing.List[ActiveAction]]: From 1cc108433ad8ef79590aa205db5bb5c4bd1089b0 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Fri, 2 Aug 2024 15:54:21 +0300 Subject: [PATCH 2/2] Switch get_installed_packages_list to return tuple, not specifically formatter string --- pleskdistup/actions/common_checks.py | 2 +- pleskdistup/common/src/dpkg.py | 12 ++++++++---- pleskdistup/common/src/packages.py | 2 +- pleskdistup/common/src/rpm.py | 10 +++++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pleskdistup/actions/common_checks.py b/pleskdistup/actions/common_checks.py index fa45dd5..828116c 100644 --- a/pleskdistup/actions/common_checks.py +++ b/pleskdistup/actions/common_checks.py @@ -652,5 +652,5 @@ def _do_check(self) -> bool: if len(kernel_devel_packages) <= 1: return True - self.description = self.description.format("\n\t- ".join([pkg.replace(" ", "-") for pkg in kernel_devel_packages])) + self.description = self.description.format("\n\t- ".join([pkg[0] + "-" + pkg[1] for pkg, _ in kernel_devel_packages])) return False diff --git a/pleskdistup/common/src/dpkg.py b/pleskdistup/common/src/dpkg.py index 9e05cb3..6ccf416 100644 --- a/pleskdistup/common/src/dpkg.py +++ b/pleskdistup/common/src/dpkg.py @@ -193,7 +193,11 @@ def do_distupgrade() -> None: env={"PATH": os.environ["PATH"], "DEBIAN_FRONTEND": "noninteractive"}) -def get_installed_packages_list(regex: str) -> typing.List[str]: - res = subprocess.check_output(["/usr/bin/dpkg-query", "-W", "-f", "${binary:Package} ${Version}\n", regex], - universal_newlines=True) - return res.splitlines() +def get_installed_packages_list(regex: str) -> typing.List[typing.Tuple[str, str]]: + pkgs_info = subprocess.check_output(["/usr/bin/dpkg-query", "-W", "-f", "${binary:Package} ${Version}\n", regex], + universal_newlines=True) + result = [] + for pkg in pkgs_info.splitlines(): + name, version = pkg.split(" ", 1) + result.append((name, version)) + return result diff --git a/pleskdistup/common/src/packages.py b/pleskdistup/common/src/packages.py index 7c20700..bcf04c3 100644 --- a/pleskdistup/common/src/packages.py +++ b/pleskdistup/common/src/packages.py @@ -78,7 +78,7 @@ def autoremove_outdated_packages() -> None: raise NotImplementedError(f"Unsupported distro {started_on}") -def get_installed_packages_list(regex: str) -> typing.List[str]: +def get_installed_packages_list(regex: str) -> typing.List[typing.Tuple[str, str]]: started_on = dist.get_distro() if started_on.deb_based: return dpkg.get_installed_packages_list(regex) diff --git a/pleskdistup/common/src/rpm.py b/pleskdistup/common/src/rpm.py index 955d20d..bbf6457 100644 --- a/pleskdistup/common/src/rpm.py +++ b/pleskdistup/common/src/rpm.py @@ -160,9 +160,13 @@ def install_packages(pkgs: typing.List[str], repository: typing.Optional[str] = util.logged_check_call(command) -def get_installed_packages_list(regex: str) -> typing.List[str]: - res = subprocess.check_output(["/usr/bin/rpm", "-qa", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", regex], universal_newlines=True) - return res.splitlines() +def get_installed_packages_list(regex: str) -> typing.List[typing.Tuple[str, str]]: + pkgs_info = subprocess.check_output(["/usr/bin/rpm", "-qa", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", regex], universal_newlines=True) + result = [] + for line in pkgs_info.splitlines(): + name, version = line.split(" ", 1) + result.append((name, version)) + return result def remove_packages(pkgs: typing.List[str]) -> None: