diff --git a/slpkg/binary/install.py b/slpkg/binary/install.py index aad5cf1d..6d4d8303 100644 --- a/slpkg/binary/install.py +++ b/slpkg/binary/install.py @@ -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): diff --git a/slpkg/binary/search.py b/slpkg/binary/search.py index 4aa548d5..8fb3ef09 100644 --- a/slpkg/binary/search.py +++ b/slpkg/binary/search.py @@ -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 \ No newline at end of file diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index f097f4e6..685b59a6 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -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") diff --git a/slpkg/main.py b/slpkg/main.py index d5b206e5..5adab7c7 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -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("") diff --git a/slpkg/pkg/find.py b/slpkg/pkg/find.py index 8dffd840..f70979f6 100644 --- a/slpkg/pkg/find.py +++ b/slpkg/pkg/find.py @@ -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 diff --git a/slpkg/sbo/check.py b/slpkg/sbo/check.py index 3c8d5db6..abbda538 100644 --- a/slpkg/sbo/check.py +++ b/slpkg/sbo/check.py @@ -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] diff --git a/slpkg/sbo/dependency.py b/slpkg/sbo/dependency.py index c06a14e4..febf9347 100644 --- a/slpkg/sbo/dependency.py +++ b/slpkg/sbo/dependency.py @@ -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): diff --git a/slpkg/sbo/network.py b/slpkg/sbo/network.py index 75385c1f..97adcce7 100644 --- a/slpkg/sbo/network.py +++ b/slpkg/sbo/network.py @@ -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: diff --git a/slpkg/sbo/slackbuild.py b/slpkg/sbo/slackbuild.py index ad35af79..684be808 100644 --- a/slpkg/sbo/slackbuild.py +++ b/slpkg/sbo/slackbuild.py @@ -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 diff --git a/slpkg/slack/patches.py b/slpkg/slack/patches.py index aa09916c..bfeb841c 100644 --- a/slpkg/slack/patches.py +++ b/slpkg/slack/patches.py @@ -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 diff --git a/slpkg/tracking.py b/slpkg/tracking.py index ac469801..9af75eae 100644 --- a/slpkg/tracking.py +++ b/slpkg/tracking.py @@ -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)