Updated blacklist manage

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2020-02-16 17:09:46 +01:00
parent d0121363b1
commit 20a175f6e0
11 changed files with 37 additions and 39 deletions

View file

@ -47,11 +47,12 @@ from slpkg.binary.repo_init import RepoInit
from slpkg.binary.dependency import Dependencies from slpkg.binary.dependency import Dependencies
class BinaryInstall: class BinaryInstall(BlackList):
"""Install binaries packages with all dependencies from """Install binaries packages with all dependencies from
repository repository
""" """
def __init__(self, packages, repo, flag): def __init__(self, packages, repo, flag):
super().__init__()
self.packages = packages self.packages = packages
pkg_security(packages) pkg_security(packages)
self.repo = repo self.repo = repo
@ -80,7 +81,7 @@ class BinaryInstall:
self.repo_pkg_names = [] self.repo_pkg_names = []
for name in self.data[0]: for name in self.data[0]:
self.repo_pkg_names.append(split_package(name)[0]) self.repo_pkg_names.append(split_package(name)[0])
self.blacklist = BlackList().get_black() self.blacklist = list(self.get_black())
self.matching = False self.matching = False
def init_flags(self): def init_flags(self):

View file

@ -33,6 +33,6 @@ def search_pkg(name, repo):
""" """
PACKAGES_TXT = Utils().read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT") PACKAGES_TXT = Utils().read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT")
names = list(Utils().package_name(PACKAGES_TXT)) names = list(Utils().package_name(PACKAGES_TXT))
blacklist = BlackList().get_black() blacklist = list(BlackList().get_black())
if name in names and name not in blacklist: if name in names and name not in blacklist:
return name return name

View file

@ -45,20 +45,15 @@ class BlackList:
"""Return blacklist packages from /etc/slpkg/blacklist """Return blacklist packages from /etc/slpkg/blacklist
configuration file.""" configuration file."""
blacklist = list(self.black_filter()) blacklist = list(self.black_filter())
lenght = len(blacklist)
installed = os.listdir("/var/log/packages/") installed = os.listdir("/var/log/packages/")
for b in blacklist: for black in blacklist:
if b.endswith("*"): if black.endswith("*"):
for i in installed: for inst in installed:
if i.startswith(b[:-1]): if inst.startswith(black[:-1]):
blacklist.append(split_package(i)[0]) yield split_package(inst)[0]
else:
# Cleaning the first packages that contain * in the end yield black
# of the package name
blacklist = blacklist[lenght:]
return blacklist
def black_filter(self): def black_filter(self):
"""Return all the installed files that start """Return all the installed files that start
@ -69,7 +64,7 @@ class BlackList:
if not read.startswith("#"): if not read.startswith("#"):
yield read.replace("\n", "") yield read.replace("\n", "")
def listed(self): def black_listed(self):
"""Print blacklist packages """Print blacklist packages
""" """
print("Packages in the blacklist:\n") print("Packages in the blacklist:\n")
@ -77,7 +72,7 @@ class BlackList:
if black: if black:
print(f"{self.green}{black}{self.endc}") print(f"{self.green}{black}{self.endc}")
def add(self, pkgs): def black_add(self, pkgs):
"""Add blacklist packages if not exist """Add blacklist packages if not exist
""" """
blacklist = list(self.black_filter()) blacklist = list(self.black_filter())
@ -89,7 +84,7 @@ class BlackList:
print(f"{self.green}{pkg}{self.endc}") print(f"{self.green}{pkg}{self.endc}")
black_conf.write(pkg + "\n") black_conf.write(pkg + "\n")
def remove(self, pkgs): def black_remove(self, pkgs):
"""Remove packages from blacklist """Remove packages from blacklist
""" """
print("Remove packages from the blacklist:\n") print("Remove packages from the blacklist:\n")

View file

@ -49,7 +49,6 @@ from slpkg.status_deps import DependenciesStatus
from slpkg.init import ( from slpkg.init import (
Update, Update,
Upgrade, Upgrade,
Initialization,
check_exists_repositories check_exists_repositories
) )
from slpkg.__metadata__ import MetaData as _meta_ from slpkg.__metadata__ import MetaData as _meta_
@ -67,9 +66,10 @@ from slpkg.binary.check import pkg_upgrade
from slpkg.binary.install import BinaryInstall from slpkg.binary.install import BinaryInstall
class ArgParse: class ArgParse(BlackList):
def __init__(self, args): def __init__(self, args):
super().__init__()
self.args = args self.args = args
self.meta = _meta_ self.meta = _meta_
self.msg = Msg() self.msg = Msg()
@ -463,7 +463,6 @@ class ArgParse:
def pkg_blacklist(self): def pkg_blacklist(self):
"""Manage blacklist packages """Manage blacklist packages
""" """
blacklist = BlackList()
options = [ options = [
"-b", "-b",
"--blacklist" "--blacklist"
@ -475,19 +474,19 @@ class ArgParse:
command = ["list"] command = ["list"]
if (len(self.args) == 2 and self.args[0] in options and if (len(self.args) == 2 and self.args[0] in options and
self.args[1] == command[0]): self.args[1] == command[0]):
blacklist.listed() self.black_listed()
elif (len(self.args) > 2 and self.args[0] in options and elif (len(self.args) > 2 and self.args[0] in options and
flag[0] in self.args): flag[0] in self.args):
self.args.remove(flag[0]) self.args.remove(flag[0])
blacklist.add(self.args[1:]) self.black_add(self.args[1:])
elif (len(self.args) == 2 and self.args[0] in options and elif (len(self.args) == 2 and self.args[0] in options and
flag[1] in self.args): flag[1] in self.args):
self.args.remove(flag[1]) self.args.remove(flag[1])
blacklist.remove(blacklist.get_black()) self.black_remove(list(self.get_black()))
elif (len(self.args) > 2 and self.args[0] in options and elif (len(self.args) > 2 and self.args[0] in options and
flag[1] in self.args): flag[1] in self.args):
self.args.remove(flag[1]) self.args.remove(flag[1])
blacklist.remove(self.args[1:]) self.black_remove(self.args[1:])
else: else:
usage("") usage("")

View file

@ -32,7 +32,7 @@ def searching(find_pkg, directory):
""" """
if os.path.isdir(directory): if os.path.isdir(directory):
installed = os.listdir(directory) installed = os.listdir(directory)
blacklist = BlackList().get_black() blacklist = list(BlackList().get_black())
if os.path.exists(directory): if os.path.exists(directory):
for pkg in installed: for pkg in installed:
if (not pkg.startswith(".") and pkg.startswith(find_pkg) and if (not pkg.startswith(".") and pkg.startswith(find_pkg) and

View file

@ -41,7 +41,7 @@ def sbo_upgrade(skip, flag):
msg.checking() msg.checking()
upgrade_names = [] upgrade_names = []
data = SBoGrep(name="").names() data = SBoGrep(name="").names()
blacklist = BlackList().get_black() blacklist = list(BlackList().get_black())
for pkg in sbo_list(): for pkg in sbo_list():
name = split_package(pkg)[0] name = split_package(pkg)[0]
ver = split_package(pkg)[1] ver = split_package(pkg)[1]

View file

@ -30,14 +30,15 @@ from slpkg.__metadata__ import MetaData as _meta_
from slpkg.sbo.greps import SBoGrep from slpkg.sbo.greps import SBoGrep
class Requires: class Requires(BlackList):
"""Resolving SBo dependencies """Resolving SBo dependencies
""" """
def __init__(self, flag): def __init__(self, flag):
super().__init__()
self.flag = flag self.flag = flag
self.meta = _meta_ self.meta = _meta_
self.SLACKBUILDS_TXT = SBoGrep(name="").names() self.SLACKBUILDS_TXT = SBoGrep(name="").names()
self.blacklist = BlackList().get_black() self.blacklist = list(self.get_black())
self.dep_results = [] self.dep_results = []
def sbo(self, name): def sbo(self, name):

View file

@ -48,11 +48,12 @@ from slpkg.sbo.slack_find import slack_package
from slpkg.slack.slack_version import slack_ver from slpkg.slack.slack_version import slack_ver
class SBoNetwork: class SBoNetwork(BlackList):
"""View SBo site in terminal and also read, build or """View SBo site in terminal and also read, build or
install packages install packages
""" """
def __init__(self, name, flag): def __init__(self, name, flag):
super().__init__()
self.name = name self.name = name
self.flag = flag self.flag = flag
self.meta = _meta_ self.meta = _meta_
@ -76,7 +77,6 @@ class SBoNetwork:
self.with_checklist() self.with_checklist()
grep = SBoGrep(self.name) grep = SBoGrep(self.name)
self.sbo_files = grep.files() self.sbo_files = grep.files()
self.blacklist = BlackList().get_black()
self.sbo_url = sbo_search_pkg(self.name) self.sbo_url = sbo_search_pkg(self.name)
if self.sbo_url: if self.sbo_url:
self.sbo_desc = grep.description()[len(self.name) + 2:-1] self.sbo_desc = grep.description()[len(self.name) + 2:-1]
@ -92,7 +92,7 @@ class SBoNetwork:
"""View SlackBuild package, read or install them """View SlackBuild package, read or install them
from slackbuilds.org from slackbuilds.org
""" """
if self.sbo_url and self.name not in self.blacklist: if self.sbo_url and self.name not in self.get_black():
self.prgnam = f"{self.name}-{self.sbo_version}" self.prgnam = f"{self.name}-{self.sbo_version}"
self.view_sbo() self.view_sbo()
while True: while True:

View file

@ -48,10 +48,11 @@ from slpkg.sbo.search import sbo_search_pkg
from slpkg.sbo.slack_find import slack_package from slpkg.sbo.slack_find import slack_package
class SBoInstall: class SBoInstall(BlackList):
"""Build and install SBo packages with all dependencies """Build and install SBo packages with all dependencies
""" """
def __init__(self, slackbuilds, flag): def __init__(self, slackbuilds, flag):
super().__init__()
self.slackbuilds = slackbuilds self.slackbuilds = slackbuilds
pkg_security(self.slackbuilds) pkg_security(self.slackbuilds)
self.flag = flag self.flag = flag
@ -81,7 +82,7 @@ class SBoInstall:
self.count_uni = 0 self.count_uni = 0
self.msg.reading() self.msg.reading()
self.data = SBoGrep(name="").names() self.data = SBoGrep(name="").names()
self.blacklist = BlackList().get_black() self.blacklist = list(self.get_black())
def init_flags(self): def init_flags(self):
"""Flags initialization """Flags initialization

View file

@ -50,10 +50,11 @@ from slpkg.slack.mirrors import mirrors
from slpkg.slack.slack_version import slack_ver from slpkg.slack.slack_version import slack_ver
class Patches: class Patches(BlackList):
"""Upgrade distribution from official Slackware mirrors """Upgrade distribution from official Slackware mirrors
""" """
def __init__(self, skip, flag): def __init__(self, skip, flag):
super().__init__()
self.skip = skip self.skip = skip
self.flag = flag self.flag = flag
self.meta = _meta_ self.meta = _meta_
@ -133,8 +134,7 @@ class Patches:
"""Store and return packages for upgrading """Store and return packages for upgrading
""" """
data = repo_data(self.PACKAGES_TXT, "slack", self.flag) data = repo_data(self.PACKAGES_TXT, "slack", self.flag)
b = BlackList() black = list(self.get_black())
black = b.get_black()
for name, loc, comp, uncomp in zip(data[0], data[1], data[2], data[3]): for name, loc, comp, uncomp in zip(data[0], data[1], data[2], data[3]):
repo_pkg_name = split_package(name)[0] repo_pkg_name = split_package(name)[0]
if (not os.path.isfile(self.meta.pkg_path + name[:-4]) and if (not os.path.isfile(self.meta.pkg_path + name[:-4]) and

View file

@ -38,13 +38,14 @@ from slpkg.binary.search import search_pkg
from slpkg.binary.dependency import Dependencies from slpkg.binary.dependency import Dependencies
class TrackingDeps: class TrackingDeps(BlackList):
"""View tree of dependencies and also """View tree of dependencies and also
highlight packages with color green highlight packages with color green
if already installed and color red if already installed and color red
if not installed. if not installed.
""" """
def __init__(self, name, repo, flag): def __init__(self, name, repo, flag):
super().__init__()
self.name = name self.name = name
self.repo = repo self.repo = repo
self.flag = flag self.flag = flag
@ -135,7 +136,7 @@ class TrackingDeps:
self.bin_case_insensitive() self.bin_case_insensitive()
self.find_pkg = search_pkg(self.name, self.repo) self.find_pkg = search_pkg(self.name, self.repo)
if self.find_pkg: if self.find_pkg:
self.black = BlackList().get_black() self.black = list(self.get_black())
self.dependencies_list = Dependencies( self.dependencies_list = Dependencies(
self.repo, self.black).binary(self.name, self.flag) self.repo, self.black).binary(self.name, self.flag)