From 1cc108433ad8ef79590aa205db5bb5c4bd1089b0 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Fri, 2 Aug 2024 15:54:21 +0300 Subject: [PATCH] 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: