Added blacklist

This commit is contained in:
Dimitris Zlatanidis 2022-06-18 17:04:23 +03:00
parent b79cfdb78e
commit 374cf76284
4 changed files with 44 additions and 5 deletions

3
config/blacklist.json Normal file
View file

@ -0,0 +1,3 @@
{
"blacklist": []
}

19
slpkg/blacklist.py Normal file
View file

@ -0,0 +1,19 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import json
from dataclasses import dataclass
from metadata import Metadata
@dataclass
class Blacklist:
etc_path: str = Metadata.etc_path
def get(self):
file = f'{self.etc_path}/blacklist.json'
if os.path.isfile(file):
with open(file, 'r') as black:
return json.load(black)['blacklist']

View file

@ -13,6 +13,7 @@ from slpkg.slackbuild import Slackbuilds
from slpkg.remove_packages import RemovePackages
from slpkg.update_repository import UpdateRepository
from slpkg.clean_logs import CleanLogsDependencies
from slpkg.blacklist import Blacklist
@dataclass
@ -23,6 +24,9 @@ class Check:
def exists(self, slackbuilds):
''' Checking if the slackbuild exists in the repository. '''
self.database()
if not slackbuilds:
raise SystemExit(f'\nPackage does not exists.\n')
for sbo in slackbuilds:
if not SBoQueries(sbo).slackbuild():
raise SystemExit(f'\nPackage {sbo} does not exists.\n')
@ -42,6 +46,14 @@ class Check:
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():
@ -103,7 +115,8 @@ class Argparse:
if len(self.args) >= 2:
# Build slackbuilds
if self.args[0] == 'build':
packages = set(self.args[1:])
packages = list(set(self.args[1:]))
packages = check.blacklist(packages)
check.exists(packages)
check.unsupported(packages)
@ -114,7 +127,8 @@ class Argparse:
# Install packages
if self.args[0] == 'install':
packages = set(self.args[1:])
packages = list(set(self.args[1:]))
packages = check.blacklist(packages)
check.exists(packages)
check.unsupported(packages)
@ -125,7 +139,8 @@ class Argparse:
# Remove packages
if self.args[0] == 'remove':
packages = set(self.args[1:])
packages = list(set(self.args[1:]))
packages = check.blacklist(packages)
check.installed(packages)

View file

@ -24,6 +24,7 @@ class Metadata:
tmp_slpkg: str = f'{tmp_path}/{prog_name}'
build_path: str = f'/tmp/{prog_name}/build'
lib_path: str = f'/var/lib/{prog_name}'
etc_path: str = f'/etc/{prog_name}'
db_path: str = f'/var/lib/{prog_name}/database'
sbo_repo_path: str = f'/var/lib/{prog_name}/repository'
log_packages: str = '/var/log/packages'
@ -45,7 +46,7 @@ class Metadata:
wget_options = '-c -N'
''' Overwrite with user configuration. '''
with open(f'/etc/{prog_name}/{prog_name}.json', 'r') as conf:
with open(f'/{etc_path}/{prog_name}.json', 'r') as conf:
config = json.load(conf)
# OS architecture by default
@ -55,6 +56,7 @@ class Metadata:
tmp_slpkg: str = config['tmp_slpkg']
build_path: str = config['build_path']
lib_path: str = config['lib_path']
etc_path: str = config['etc_path']
db_path: str = config['db_path']
sbo_repo_path: str = config['sbo_repo_path']
log_packages: str = config['log_packages']
@ -96,4 +98,4 @@ class Metadata:
'ENDC': '\x1b[0m'
}
return color
return color