From 15fd41b782102787b4e1e7951869ee16e0fc1df0 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sat, 27 Apr 2024 19:21:31 +0300 Subject: [PATCH] Improved code quality --- slpkg/find_installed.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/slpkg/find_installed.py b/slpkg/find_installed.py index d54e84ba..b3816e36 100644 --- a/slpkg/find_installed.py +++ b/slpkg/find_installed.py @@ -6,7 +6,10 @@ from slpkg.utilities import Utilities class FindInstalled(Configs): - """ Find installed packages. """ + + """ + Find installed packages. + """ def __init__(self, flags: list, packages: list): super(Configs, self).__init__() @@ -19,36 +22,50 @@ class FindInstalled(Configs): ('-m', '--no-case'), flags) def find(self) -> None: + """ Find packages installed packages. + """ self.view_title() for package in self.packages: for name in self.utils.all_installed().values(): if package in name or package == '*' or self.is_not_case_sensitive(package, name): self.matching.append(name) - self.matched() + self.view_matched_packages() @staticmethod def view_title() -> None: + """ Prints the title. + """ print('The list below shows the installed packages:\n') - def matched(self) -> None: + def view_matched_packages(self) -> None: + """ Prints the matching packages. + """ if self.matching: - self.view_matched_packages() + for package in self.matching: + name: str = self.utils.split_package(package)['name'] + pkg_size: int = self.utils.count_file_size(name) + size: str = self.utils.convert_file_sizes(pkg_size) + print(f'{self.cyan}{package}{self.endc} ({size})') + self.view_summary() else: print('\nDoes not match any package.\n') - def view_matched_packages(self) -> None: - for package in self.matching: - name: str = self.utils.split_package(package)['name'] - pkg_size: int = self.utils.count_file_size(name) - size: str = self.utils.convert_file_sizes(pkg_size) - print(f'{self.cyan}{package}{self.endc} ({size})') - self.view_summary() - def view_summary(self) -> None: + """ Prints the summary. + """ print(f'\n{self.grey}Total found {len(self.matching)} packages.{self.endc}') def is_not_case_sensitive(self, package: str, name: str) -> bool: + """ Checks for case sensitive. + + Args: + package (str): Package file. + name (str): Name of package. + + Returns: + bool: True or False. + """ if self.option_for_no_case: return package.lower() in name.lower() return False