Updated for json data

This commit is contained in:
Dimitris Zlatanidis 2024-03-14 18:53:25 +02:00
parent dd57d5c241
commit 15033e84d7

View file

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import sys
import json
import logging
from pathlib import Path
@ -18,7 +19,6 @@ from slpkg.views.cli_menu import Usage
from slpkg.views.version import Version
from slpkg.choose_packages import Choose
from slpkg.views.asciibox import AsciiBox
from slpkg.sbos.queries import SBoQueries
from slpkg.views.help_commands import Help
from slpkg.repositories import Repositories
from slpkg.binaries.install import Packages
@ -26,7 +26,6 @@ from slpkg.dialog_configs import FormConfigs
from slpkg.check_updates import CheckUpdates
from slpkg.download_only import DownloadOnly
from slpkg.sbos.slackbuild import Slackbuilds
from slpkg.binaries.queries import BinQueries
from slpkg.logging_config import LoggingConfig
from slpkg.find_installed import FindInstalled
from slpkg.views.view_package import ViewPackage
@ -317,10 +316,10 @@ class Menu(Configs):
def load_database(self):
if self.repository != '*' and not self.data:
print('\rDatabase loading... ', end='')
if self.is_binary:
self.data: dict = BinQueries(self.repository).repository_data()
else:
self.data: dict = SBoQueries(self.repository).repository_data()
json_data: Path = Path(f'{self.repos.repositories_path}/{self.repository}', self.repos.data_json)
if json_data.is_file():
self.data: dict = json.loads(json_data.read_text())
print(f'{self.yellow}{self.ascii.done}{self.endc}')
def check_for_repositories(self) -> None:
@ -464,7 +463,6 @@ class Menu(Configs):
if len(self.args) == 1:
self.load_database()
self.check.is_database_empty()
upgrade = Upgrade(self.repository, self.data)
packages: list = list(upgrade.packages())
@ -507,7 +505,6 @@ class Menu(Configs):
if len(self.args) >= 2:
self.load_database()
self.check.is_database_empty()
packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive:
@ -517,7 +514,6 @@ class Menu(Configs):
packages: list = self.choose.packages(self.data, packages, command)
self.check.package_exists_in_the_database(packages, self.data)
self.check.is_package_unsupported(packages, self.data)
if self.repository in list(self.repos.repositories.keys())[:2]:
build = Slackbuilds(
@ -535,7 +531,7 @@ class Menu(Configs):
if len(self.args) >= 2:
self.load_database()
self.check.is_database_empty()
# self.check.is_database_empty()
packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive:
@ -550,7 +546,6 @@ class Menu(Configs):
install = Packages(self.repository, self.data, packages, self.flags, mode=command)
install.execute()
else:
self.check.is_package_unsupported(packages, self.data)
install = Slackbuilds(self.repository, self.data, packages, self.flags, mode=command)
install.execute()
raise SystemExit(0)
@ -561,7 +556,6 @@ class Menu(Configs):
if len(self.args) >= 2:
self.load_database()
self.check.is_database_empty()
packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive:
@ -596,7 +590,6 @@ class Menu(Configs):
command: str = Menu.find.__name__
if len(self.args) >= 2:
self.check.is_database_empty()
packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive:
@ -617,7 +610,6 @@ class Menu(Configs):
if len(self.args) >= 2:
self.load_database()
self.check.is_database_empty()
packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive:
@ -641,7 +633,6 @@ class Menu(Configs):
command: str = Menu.search.__name__
if len(self.args) >= 2:
self.check.is_database_empty()
packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_searches, self.flags):
@ -658,7 +649,6 @@ class Menu(Configs):
if len(self.args) >= 2:
self.load_database()
self.check.is_database_empty()
packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive:
@ -679,7 +669,6 @@ class Menu(Configs):
if len(self.args) >= 2:
self.load_database()
self.check.is_database_empty()
packages: list = self.is_file_list_packages()
if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive:
@ -819,14 +808,14 @@ def main() -> None:
'-t': menu.tracking
}
try:
arguments[args[0]]()
except (KeyError, IndexError):
logger = logging.getLogger(LoggingConfig.date_time)
logger.exception(main.__name__)
usage.help_short(1)
except KeyboardInterrupt:
raise SystemExit(1)
# try:
arguments[args[0]]()
# except (KeyError, IndexError):
# logger = logging.getLogger(LoggingConfig.date_time)
# logger.exception(main.__name__)
# usage.help_short(1)
# except KeyboardInterrupt:
# raise SystemExit(1)
if __name__ == '__main__':