slpkg/slpkg/checks.py

80 lines
2.6 KiB
Python
Raw Normal View History

2022-06-18 16:57:26 +02:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
2022-12-30 16:40:11 +01:00
from pathlib import Path
2022-06-18 16:57:26 +02:00
2022-06-18 20:35:23 +02:00
from slpkg.configs import Configs
2022-06-18 16:57:26 +02:00
from slpkg.queries import SBoQueries
from slpkg.blacklist import Blacklist
from slpkg.utilities import Utilities
2022-06-18 16:57:26 +02:00
2023-01-16 23:47:01 +01:00
class Check(Configs, Utilities):
""" Some checks before proceed. """
def __init__(self):
2023-01-16 23:47:01 +01:00
super(Configs, self).__init__()
super(Utilities, self).__init__()
2022-06-18 16:57:26 +02:00
@staticmethod
2023-03-02 21:06:25 +01:00
def exists(slackbuilds: list) -> None:
""" Checking if the slackbuild exists in the repository. """
2023-03-01 18:40:43 +01:00
not_packages: list = []
2022-06-18 18:19:27 +02:00
2022-06-18 16:57:26 +02:00
for sbo in slackbuilds:
if not SBoQueries(sbo).slackbuild():
2022-12-31 22:10:52 +01:00
not_packages.append(sbo)
2022-06-18 18:19:27 +02:00
2022-12-31 22:10:52 +01:00
if not_packages:
raise SystemExit(f'\nPackages \'{", ".join(not_packages)}\' '
2022-06-18 18:19:27 +02:00
'does not exists.\n')
2022-06-18 16:57:26 +02:00
@staticmethod
2023-03-02 21:06:25 +01:00
def unsupported(slackbuilds: list) -> None:
""" Checking for unsupported slackbuilds. """
2022-06-18 16:57:26 +02:00
for sbo in slackbuilds:
sources = SBoQueries(sbo).sources()
2022-06-20 19:43:56 +02:00
2022-06-18 16:57:26 +02:00
if 'UNSUPPORTED' in sources:
raise SystemExit(f"\nPackage '{sbo}' unsupported by arch.\n")
2022-06-18 16:57:26 +02:00
2023-01-23 22:14:24 +01:00
def installed(self, slackbuilds: list, file_pattern: str) -> list:
""" Checking for installed packages. """
found, not_found = [], []
2022-06-20 19:43:56 +02:00
for sbo in slackbuilds:
2023-03-03 07:05:20 +01:00
package: str = self.is_package_installed(sbo, file_pattern)
if package:
2023-03-01 18:40:43 +01:00
pkg: str = self.split_installed_pkg(package)[0]
found.append(pkg)
else:
not_found.append(sbo)
if not_found:
raise SystemExit(f'\nNot found \'{", ".join(not_found)}\' '
'installed packages.\n')
2022-06-20 19:43:56 +02:00
return found
2022-06-18 16:57:26 +02:00
2023-03-02 21:06:25 +01:00
def blacklist(self, slackbuilds: list) -> None:
""" Checking if the packages are blacklisted. """
2023-03-01 18:40:43 +01:00
packages: list = []
2022-06-18 16:57:26 +02:00
black = Blacklist()
2022-06-20 19:43:56 +02:00
2023-02-28 23:23:28 +01:00
for package in black.packages():
2022-06-18 16:57:26 +02:00
if package in slackbuilds:
packages.append(package)
2022-06-20 19:43:56 +02:00
if packages:
raise SystemExit(
f'\nThe packages \'{", ".join(packages)}\' is blacklisted.\n'
f'Please edit the blacklist.toml file in '
2023-03-02 21:09:00 +01:00
f'{self.etc_path} folder.\n')
2022-06-18 16:57:26 +02:00
2023-03-02 21:06:25 +01:00
def database(self) -> None:
""" Checking for empty table """
2023-01-16 23:47:01 +01:00
db = Path(self.db_path, self.database_name)
2022-12-30 19:49:39 +01:00
if not SBoQueries('').sbos() or not db.is_file():
2022-06-18 16:57:26 +02:00
raise SystemExit('\nYou need to update the package lists first.\n'
'Please run slpkg update.\n')