Added tag installed

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2024-06-09 21:43:47 +03:00
parent cb8d54b581
commit 31d6c0d52f
2 changed files with 20 additions and 4 deletions

View file

@ -1,5 +1,11 @@
## slpkg - ChangeLog
### 5.1.1 - 09/06/2024
- Added:
* Added an 'installed' tag for installed packages in the search command
### 5.1.0 - 06/06/2024
- Added:

View file

@ -5,6 +5,7 @@
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
from slpkg.views.view_process import ViewProcess
class SearchPackage(Configs): # pylint: disable=[R0902]
@ -18,6 +19,7 @@ class SearchPackage(Configs): # pylint: disable=[R0902]
self.utils = Utilities()
self.repos = Repositories()
self.view_process = ViewProcess()
self.matching: int = 0
self.data_dict: dict = {}
@ -31,13 +33,15 @@ class SearchPackage(Configs): # pylint: disable=[R0902]
def search(self) -> None:
"""Choose between all and one repository."""
self.view_process.message('Please wait for the results')
if self.repository == '*':
self.search_to_all_repositories()
else:
self.repo_data: dict = self.data
self.search_for_the_packages(self.repository)
print('The list below shows the repository packages:\n')
self.view_process.done()
print()
self.summary_of_searching()
def search_to_all_repositories(self) -> None:
@ -58,11 +62,15 @@ class SearchPackage(Configs): # pylint: disable=[R0902]
if package in name or package == '*' or self.is_not_case_sensitive(package, name):
self.matching += 1
installed: str = f'{self.endc}'
if self.utils.is_package_installed(name):
installed: str = f' {self.endc}(installed)'
self.data_dict[self.matching] = {
'repository': repo,
'name': name,
'version': data_pkg['version']
'version': data_pkg['version'],
'installed': installed
}
def summary_of_searching(self) -> None:
@ -73,7 +81,7 @@ class SearchPackage(Configs): # pylint: disable=[R0902]
repo_length: int = 1
try:
name_length: int = max(len(name['name']) for name in self.data_dict.values())
name_length: int = max(len(name['name']) + len(name['installed']) for name in self.data_dict.values())
except ValueError:
name_length: int = 1
@ -81,12 +89,14 @@ class SearchPackage(Configs): # pylint: disable=[R0902]
version: str = ''
repository: str = ''
for item in self.data_dict.values():
package_name: str = f"{item['name']}{item['installed']}"
if self.option_for_pkg_version:
version: str = item['version']
if self.repository == '*':
repository: str = f"{item['repository']:<{repo_length}} : "
print(f"{repository}{self.cyan}{item['name']:<{name_length}}{self.endc} "
print(f"{repository}{self.cyan}{package_name:<{name_length}}{self.endc} "
f"{self.yellow}{version}{self.endc}")
print(f'\n{self.grey}Total found {self.matching} packages.{self.endc}')