Updated for json

This commit is contained in:
Dimitris Zlatanidis 2024-03-15 21:15:13 +02:00
parent fc363692a4
commit e347f1913f

View file

@ -1,6 +1,8 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from pathlib import Path
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.views.asciibox import AsciiBox
@ -32,30 +34,22 @@ class SearchPackage(Configs):
if self.repository == '*':
self.search_to_all_repositories()
else:
self.search_to_the_repository()
json_file: Path = Path(f'{self.repos.repositories_path}/{self.repository}', self.repos.json_file)
self.repo_data: dict = self.utils.read_json_file(json_file)
self.search_for_the_packages(self.repository)
print(f'{self.yellow}{self.ascii.done}{self.endc}')
print(f'The list below shows the repo '
f'packages that contains \'{", ".join([p for p in self.packages])}\':\n')
self.summary_of_searching()
def search_to_all_repositories(self) -> None:
for repo, item in self.repos.repositories.items():
if item['enable']: # Check if the repository is enabled
if self.utils.is_binary_repo(repo):
self.repo_data: dict = BinQueries(repo).repository_data()
else:
self.repo_data: dict = SBoQueries(repo).repository_data()
json_file: Path = Path(f'{self.repos.repositories_path}/{repo}', self.repos.json_file)
self.repo_data: dict = self.utils.read_json_file(json_file)
self.search_for_the_packages(repo)
def search_to_the_repository(self) -> None:
if self.is_binary:
self.repo_data: dict = BinQueries(self.repository).repository_data()
else:
self.repo_data: dict = SBoQueries(self.repository).repository_data()
self.search_for_the_packages(self.repository)
def search_for_the_packages(self, repo: str) -> None:
for package in self.packages:
for name, data_pkg in self.repo_data.items():