diff --git a/slpkg/utilities.py b/slpkg/utilities.py index cf6f2901..63289ab2 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -3,6 +3,7 @@ import os import re +import glob import time import shutil import fnmatch @@ -29,22 +30,27 @@ class Utilities(Configs): self.stdout = None self.prog_version = Version() - self.installed_packages: dict = dict(self.all_installed()) + # self.installed_packages: dict = dict(self.all_installed()) def is_package_installed(self, name: str) -> str: """ Returns the installed package binary. """ - try: - return self.installed_packages[name] - except KeyError: - return '' + installed_package: Generator = Path(self.log_packages).glob(f'{name}*') + for installed in installed_package: + inst_name: str = self.split_package(installed.name)['name'] + if inst_name == name: + return installed + return '' - def all_installed(self) -> tuple: + def all_installed(self) -> dict: """ Return all installed packages from /val/log/packages folder. """ + installed_packages: dict = {} for file in self.log_packages.glob(self.file_pattern): name: str = self.split_package(file.name)['name'] if not name.startswith('.') and not self.blacklist_pattern(name): - yield name, file.name + installed_packages[name] = file.name + + return installed_packages @staticmethod def remove_file_if_exists(path: Path, file: str) -> None: