mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-17 07:48:18 +01:00
Improved code quality
This commit is contained in:
parent
189b90f6e4
commit
15fd41b782
1 changed files with 29 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue