Fixed for empty db

This commit is contained in:
Dimitris Zlatanidis 2023-03-22 18:49:40 +02:00
parent f3f32ac293
commit e1be676dff

View file

@ -9,33 +9,38 @@ from slpkg.blacklist import Blacklist
from slpkg.utilities import Utilities from slpkg.utilities import Utilities
from slpkg.repositories import Repositories from slpkg.repositories import Repositories
from slpkg.models.models import session as Session
from slpkg.models.models import SBoTable, PonceTable, BinariesTable
class Check(Configs): class Check(Configs):
""" Some checks before proceed. """ """ Some checks before proceed. """
def __init__(self): def __init__(self, flags: list):
super(Configs, self).__init__() super(Configs, self).__init__()
self.flags: list = flags
self.black = Blacklist() self.black = Blacklist()
self.utils = Utilities() self.utils = Utilities()
self.repos = Repositories() self.repos = Repositories()
self.repo_path = self.repos.sbo_repo_path self.session = Session
if self.repos.ponce_repo: self.flag_binary: list = ['-B', '--binary']
self.repo_path = self.repos.ponce_repo_path
def exists_in_the_database(self, slackbuilds: list) -> None: if self.utils.is_option(self.flag_binary, self.flags):
self.repo_table = BinariesTable
else:
self.repo_table = SBoTable
if self.repos.ponce_repo:
self.repo_table = PonceTable
def exists_in_the_database(self, packages: list) -> None:
""" Checking if the slackbuild exists in the database. """ """ Checking if the slackbuild exists in the database. """
not_packages: list = [] not_packages: list = []
for sbo in slackbuilds: for pkg in packages:
if not SBoQueries(sbo).slackbuild(): if not self.session.query(self.repo_table).filter(self.repo_table.name == pkg).first():
not_packages.append(sbo) not_packages.append(pkg)
else:
location = SBoQueries(sbo).location()
if not Path(self.repo_path, location, sbo).is_dir():
not_packages.append(sbo)
if not_packages: if not_packages:
self.utils.raise_error_message(f"Packages '{', '.join(not_packages)}' does not exists") self.utils.raise_error_message(f"Packages '{', '.join(not_packages)}' does not exists")
@ -72,8 +77,8 @@ class Check(Configs):
self.utils.raise_error_message(f"The packages '{', '.join(blacklist)}' is blacklisted") self.utils.raise_error_message(f"The packages '{', '.join(blacklist)}' is blacklisted")
def is_empty_database(self) -> None: def is_empty_database(self) -> None:
""" Checking for empty table """ """ Checking for empty table and database file. """
db = Path(self.db_path, self.database_name) db = Path(self.db_path, self.database_name)
if not SBoQueries('').sbos() or not db.is_file(): if not self.session.query(self.repo_table).first() or not db.is_file():
self.utils.raise_error_message("You need to update the package lists first.\n" self.utils.raise_error_message("You need to update the package lists first.\n"
" Please run 'slpkg update'") " Please run 'slpkg update'")