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
|
2022-12-09 18:45:36 +01:00
|
|
|
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):
|
2022-12-07 16:36:00 +01:00
|
|
|
""" Some checks before proceed. """
|
2022-12-02 21:06:18 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-12-07 16:36:00 +01:00
|
|
|
@staticmethod
|
2023-03-02 21:06:25 +01:00
|
|
|
def exists(slackbuilds: list) -> None:
|
2022-12-07 16:36:00 +01:00
|
|
|
""" 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
|
|
|
|
2022-12-07 16:36:00 +01:00
|
|
|
@staticmethod
|
2023-03-02 21:06:25 +01:00
|
|
|
def unsupported(slackbuilds: list) -> None:
|
2022-12-07 16:36:00 +01:00
|
|
|
""" 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:
|
2022-11-27 18:33:12 +01:00
|
|
|
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:
|
2022-12-07 16:36:00 +01:00
|
|
|
""" Checking for installed packages. """
|
2022-11-27 20:28:51 +01:00
|
|
|
found, not_found = [], []
|
2022-06-20 19:43:56 +02:00
|
|
|
|
2022-11-27 18:33:12 +01:00
|
|
|
for sbo in slackbuilds:
|
2023-03-03 07:05:20 +01:00
|
|
|
package: str = self.is_package_installed(sbo, file_pattern)
|
2022-12-17 12:50:19 +01:00
|
|
|
if package:
|
2023-03-01 18:40:43 +01:00
|
|
|
pkg: str = self.split_installed_pkg(package)[0]
|
2022-12-17 12:50:19 +01:00
|
|
|
found.append(pkg)
|
|
|
|
else:
|
2022-11-27 20:28:51 +01:00
|
|
|
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
|
|
|
|
2022-11-27 18:33:12 +01: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:
|
2022-12-07 16:36:00 +01:00
|
|
|
""" 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:
|
2022-11-23 16:05:30 +01:00
|
|
|
packages.append(package)
|
2022-06-20 19:43:56 +02:00
|
|
|
|
2022-11-23 16:05:30 +01:00
|
|
|
if packages:
|
|
|
|
raise SystemExit(
|
2022-11-23 18:33:13 +01:00
|
|
|
f'\nThe packages \'{", ".join(packages)}\' is blacklisted.\n'
|
2022-12-06 15:31:58 +01:00
|
|
|
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:
|
2022-12-07 16:36:00 +01:00
|
|
|
""" 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')
|