Skip to content

Commit

Permalink
Switch get_installed_packages_list to return tuple, not specifically …
Browse files Browse the repository at this point in the history
…formatter string
  • Loading branch information
Mikhail Sandakov committed Aug 2, 2024
1 parent 0af2886 commit 1cc1084
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pleskdistup/actions/common_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions pleskdistup/common/src/dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pleskdistup/common/src/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions pleskdistup/common/src/rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1cc1084

Please sign in to comment.