diff --git a/slpkg/find_installed.py b/slpkg/find_installed.py index a6d756de..b5d1eb0b 100644 --- a/slpkg/find_installed.py +++ b/slpkg/find_installed.py @@ -1,9 +1,8 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- -import os - from slpkg.configs import Configs +from slpkg.utilities import Utilities class FindInstalled: @@ -13,17 +12,19 @@ class FindInstalled: self.configs = Configs colors = self.configs.colour self.color = colors() + self.utils = Utilities() def find(self, packages: list): """ Find the packages. """ matching = [] + installed = self.utils.all_installed() print(f'The list below shows the installed packages ' f'that contains \'{", ".join([p for p in packages])}\' files:\n') for pkg in packages: - for package in os.listdir(self.configs.log_packages): - if pkg in package and self.configs.sbo_repo_tag in package: + for package in installed: + if pkg in package: matching.append(package) self.matched(matching) diff --git a/slpkg/main.py b/slpkg/main.py index 2c82f227..cbc3d54d 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -96,7 +96,7 @@ class Argparse: repo_packages = SBoQueries('').sbos() # Grab all the installed packages - installed = os.listdir(self.configs.log_packages) + installed = self.utils.all_installed() if method in ['remove', 'find']: @@ -104,10 +104,9 @@ class Argparse: name = self.utils.split_installed_pkg(package)[0] version = self.utils.split_installed_pkg(package)[1] - if package.endswith(self.configs.sbo_repo_tag): - for pkg in packages: - if pkg in name: - choices += [(name, version, False)] + for pkg in packages: + if pkg in name: + choices += [(name, version, False)] else: for package in repo_packages: for pkg in packages: diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index a8e6a0f8..0bbbaac7 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- -import os from distutils.version import LooseVersion @@ -27,7 +26,9 @@ class Upgrade: black = Blacklist().get() upgrade, requires = [], [] - for pkg in os.listdir(self.configs.log_packages): + installed = self.utils.all_installed() + + for pkg in installed: inst_pkg_name = self.utils.split_installed_pkg(pkg)[0] if (pkg.endswith(self.configs.sbo_repo_tag) diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 08087649..eba30100 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -33,9 +33,16 @@ class Utilities: if pkg == name and pkg not in self.black.get(): return package - return '' + def all_installed(self): + """ Return all installed SBo packages from /val/log/packages folder. """ + pattern = f'*{self.configs.sbo_repo_tag}' + var_log_packages = Path(self.configs.log_packages) + installed = [file.name for file in var_log_packages.glob(pattern)] + + return installed + @staticmethod def untar_archive(path: str, archive: str, ext_path: str): """ Untar the file to the build folder. """ diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 99789479..37173cab 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -4,7 +4,6 @@ import os import shutil from typing import Any -from pathlib import Path from distutils.version import LooseVersion from slpkg.configs import Configs @@ -181,10 +180,7 @@ class ViewMessage: def _view_removed(self, name: str): """ View and creates list with packages for remove. """ - pattern = f'*{self.configs.sbo_repo_tag}' - - var_log_packages = Path(self.configs.log_packages) - installed = [file.name for file in var_log_packages.glob(pattern)] + installed = self.utils.all_installed() if self.utils.is_installed(name): for package in installed: