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
class BinaryInstall:
class BinaryInstall(BlackList):
"""Install binaries packages with all dependencies from
repository
"""
def __init__(self, packages, repo, flag):
super().__init__()
self.packages = packages
pkg_security(packages)
self.repo = repo
@ -80,7 +81,7 @@ class BinaryInstall:
self.repo_pkg_names = []
for name in self.data[0]:
self.repo_pkg_names.append(split_package(name)[0])
self.blacklist = BlackList().get_black()
self.blacklist = list(self.get_black())
self.matching = False
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")
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:
return name

View file

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

View file

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

View file

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

View file

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

View file

@ -30,14 +30,15 @@ from slpkg.__metadata__ import MetaData as _meta_
from slpkg.sbo.greps import SBoGrep
class Requires:
class Requires(BlackList):
"""Resolving SBo dependencies
"""
def __init__(self, flag):
super().__init__()
self.flag = flag
self.meta = _meta_
self.SLACKBUILDS_TXT = SBoGrep(name="").names()
self.blacklist = BlackList().get_black()
self.blacklist = list(self.get_black())
self.dep_results = []
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
class SBoNetwork:
class SBoNetwork(BlackList):
"""View SBo site in terminal and also read, build or
install packages
"""
def __init__(self, name, flag):
super().__init__()
self.name = name
self.flag = flag
self.meta = _meta_
@ -76,7 +77,6 @@ class SBoNetwork:
self.with_checklist()
grep = SBoGrep(self.name)
self.sbo_files = grep.files()
self.blacklist = BlackList().get_black()
self.sbo_url = sbo_search_pkg(self.name)
if self.sbo_url:
self.sbo_desc = grep.description()[len(self.name) + 2:-1]
@ -92,7 +92,7 @@ class SBoNetwork:
"""View SlackBuild package, read or install them
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.view_sbo()
while True:

View file

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

View file

@ -50,10 +50,11 @@ from slpkg.slack.mirrors import mirrors
from slpkg.slack.slack_version import slack_ver
class Patches:
class Patches(BlackList):
"""Upgrade distribution from official Slackware mirrors
"""
def __init__(self, skip, flag):
super().__init__()
self.skip = skip
self.flag = flag
self.meta = _meta_
@ -133,8 +134,7 @@ class Patches:
"""Store and return packages for upgrading
"""
data = repo_data(self.PACKAGES_TXT, "slack", self.flag)
b = BlackList()
black = b.get_black()
black = list(self.get_black())
for name, loc, comp, uncomp in zip(data[0], data[1], data[2], data[3]):
repo_pkg_name = split_package(name)[0]
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
class TrackingDeps:
class TrackingDeps(BlackList):
"""View tree of dependencies and also
highlight packages with color green
if already installed and color red
if not installed.
"""
def __init__(self, name, repo, flag):
super().__init__()
self.name = name
self.repo = repo
self.flag = flag
@ -135,7 +136,7 @@ class TrackingDeps:
self.bin_case_insensitive()
self.find_pkg = search_pkg(self.name, self.repo)
if self.find_pkg:
self.black = BlackList().get_black()
self.black = list(self.get_black())
self.dependencies_list = Dependencies(
self.repo, self.black).binary(self.name, self.flag)