mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-27 09:58:10 +01:00
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
try:
|
|
import tomli
|
|
except ModuleNotFoundError:
|
|
import tomllib as tomli
|
|
|
|
from pathlib import Path
|
|
|
|
from slpkg.configs import Configs
|
|
from slpkg.toml_errors import TomlErrors
|
|
|
|
|
|
class Blacklist(Configs): # pylint: disable=[R0903]
|
|
|
|
"""
|
|
Reads and returns the blacklist.
|
|
"""
|
|
|
|
def __init__(self):
|
|
super(Configs, self).__init__()
|
|
|
|
self.toml_errors = TomlErrors()
|
|
self.blacklist_file_toml: Path = Path(self.etc_path, 'blacklist.toml')
|
|
|
|
def packages(self) -> tuple:
|
|
""" Reads the blacklist file. """
|
|
packages: tuple = tuple()
|
|
if self.blacklist_file_toml.is_file():
|
|
try:
|
|
with open(self.blacklist_file_toml, 'rb') as black_file:
|
|
black: dict = {k.lower(): v for k, v in tomli.load(black_file).items()}
|
|
packages: tuple = black['packages']
|
|
except (tomli.TOMLDecodeError, KeyError) as error:
|
|
print()
|
|
self.toml_errors.raise_toml_error_message(error, self.blacklist_file_toml)
|
|
|
|
return packages
|