From e347f1913f65dbc17daf0bcca94d9e4b7027af7c Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 15 Mar 2024 21:15:13 +0200 Subject: [PATCH] Updated for json --- slpkg/search.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/slpkg/search.py b/slpkg/search.py index 51128883..f765cbc8 100644 --- a/slpkg/search.py +++ b/slpkg/search.py @@ -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():