diff --git a/slpkg/checks.py b/slpkg/checks.py new file mode 100644 index 00000000..2e39302e --- /dev/null +++ b/slpkg/checks.py @@ -0,0 +1,51 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import os +from dataclasses import dataclass + +from slpkg.metadata import Metadata +from slpkg.queries import SBoQueries +from slpkg.blacklist import Blacklist + + +@dataclass +class Check: + log_packages: str = Metadata.log_packages + repo_tag: str = Metadata.repo_tag + + def exists(self, slackbuilds): + ''' Checking if the slackbuild exists in the repository. ''' + self.database() + for sbo in slackbuilds: + if not SBoQueries(sbo).slackbuild(): + raise SystemExit(f'\nPackage {sbo} does not exists.\n') + + def unsupported(self, slackbuilds): + ''' Checking for unsupported slackbuilds. ''' + for sbo in slackbuilds: + sources = SBoQueries(sbo).sources() + if 'UNSUPPORTED' in sources: + raise SystemExit(f'\nPackage {sbo} unsupported by arch.\n') + + def installed(self, slackbuilds): + ''' Checking for installed packages. ''' + for package in os.listdir(self.log_packages): + for sbo in slackbuilds: + if sbo + '-' in package and self.repo_tag in package: + return + raise SystemExit('\nNot found packages for remove.\n') + + def blacklist(self, slackbuilds): + ''' Checking for packages on the blacklist and removing them. ''' + black = Blacklist() + for package in black.get(): + if package in slackbuilds: + slackbuilds.remove(package) + return slackbuilds + + def database(self): + ''' Checking for empty table ''' + if not SBoQueries('').names(): + raise SystemExit('\nYou need to update the package lists first.\n' + 'Please run slpkg update.\n')