From 6e9ab1964635ef63e024c41211fdd91a07c50251 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Mon, 23 Jan 2023 23:14:24 +0200 Subject: [PATCH] Added option to remove --- man/slpkg.1 | 2 +- slpkg/checks.py | 5 ++--- slpkg/main.py | 31 ++++++++++++++++--------------- slpkg/remove_packages.py | 5 +++-- slpkg/views/views.py | 14 ++++++++------ 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/man/slpkg.1 b/man/slpkg.1 index 521ee29e..dc4811b6 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -159,7 +159,7 @@ Print the repository package version. (to be used with: -e, dependees, -t, track Search for specific installed files with a pattern, such as: slpkg -f 'python' --file-pattern='*', prints all installed packages that include the name 'python', not only the SBo packages. Also when you want to see packages that you have installed from other repositories, like: -slpkg -i podman --file-pattern='*alien'. (to be used with: -i, install, -f, find) +slpkg -i podman --file-pattern='*alien'. (to be used with: -i, install, -r, remove, -f, find) .RE .P -h | --help diff --git a/slpkg/checks.py b/slpkg/checks.py index 2c1a3885..06530c40 100644 --- a/slpkg/checks.py +++ b/slpkg/checks.py @@ -38,13 +38,12 @@ class Check(Configs, Utilities): if 'UNSUPPORTED' in sources: raise SystemExit(f"\nPackage '{sbo}' unsupported by arch.\n") - def installed(self, slackbuilds: list) -> list: + def installed(self, slackbuilds: list, file_pattern: str) -> list: """ Checking for installed packages. """ found, not_found = [], [] for sbo in slackbuilds: - pattern = f'*{self.sbo_repo_tag}' - package = self.is_installed(sbo, pattern) + package = self.is_installed(sbo, file_pattern) if package: pkg = self.split_installed_pkg(package)[0] found.append(pkg) diff --git a/slpkg/main.py b/slpkg/main.py index 46b6964a..3a3f4c63 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -32,7 +32,7 @@ class Argparse(Configs): self.args = args self.flags = [] self.directory = None - self.file_pattern = None + self.file_pattern = f'*{self.sbo_repo_tag}' self.dialogbox = DialogBox() self.utils = Utilities() self.usage = Usage() @@ -54,7 +54,7 @@ class Argparse(Configs): self.flag_no_silent = '--no-silent' self.flag_directory = '--directory=' self.flag_pkg_version = '--pkg-version' - self.flag_pattern = '--file-pattern=' + self.flag_file_pattern = '--file-pattern=' self.is_dialog_enabled() @@ -68,7 +68,7 @@ class Argparse(Configs): self.flag_no_silent, self.flag_directory, self.flag_pkg_version, - self.flag_pattern] + self.flag_file_pattern] self.remove_flags() @@ -79,9 +79,9 @@ class Argparse(Configs): self.directory = arg.split('=')[1] self.args[self.args.index(arg)] = self.flag_directory - if arg.startswith(self.flag_pattern): + if arg.startswith(self.flag_file_pattern): self.file_pattern = arg.split('=')[1] - self.args[self.args.index(arg)] = self.flag_pattern + self.args[self.args.index(arg)] = self.flag_file_pattern for opt in self.options: if opt in self.args: @@ -131,7 +131,7 @@ class Argparse(Configs): self.flag_skip_installed, self.flag_search, self.flag_no_silent, - self.flag_pattern + self.flag_file_pattern ], 'download': [ self.flag_yes, @@ -143,9 +143,13 @@ class Argparse(Configs): self.flag_yes, self.flag_resolve_off, self.flag_search, - self.flag_no_silent + self.flag_no_silent, + self.flag_file_pattern + ], + 'find': [ + self.flag_search, + self.flag_file_pattern ], - 'find': [self.flag_search, self.flag_pattern], 'view': [ self.flag_search, self.flag_pkg_version], @@ -276,7 +280,7 @@ class Argparse(Configs): print('\nEverything is up-to-date.\n') raise SystemExit() - install = Slackbuilds(packages, self.flags, mode=command) + install = Slackbuilds(packages, self.flags, self.file_pattern, mode=command) install.execute() raise SystemExit() self.usage.help(1) @@ -329,7 +333,7 @@ class Argparse(Configs): self.check.exists(packages) self.check.unsupported(packages) - build = Slackbuilds(packages, self.flags, mode=command) + build = Slackbuilds(packages, self.flags, self.file_pattern, mode=command) build.execute() raise SystemExit() self.usage.help(1) @@ -347,9 +351,6 @@ class Argparse(Configs): self.check.exists(packages) self.check.unsupported(packages) - if not self.file_pattern: - self.file_pattern = f'*{self.sbo_repo_tag}' - install = Slackbuilds(packages, self.flags, self.file_pattern, mode=command) install.execute() raise SystemExit() @@ -381,9 +382,9 @@ class Argparse(Configs): packages = self.choose_packages(packages, command) self.check.database() - packages = self.check.installed(packages) + packages = self.check.installed(packages, self.file_pattern) - remove = RemovePackages(packages, self.flags) + remove = RemovePackages(packages, self.flags, self.file_pattern) remove.remove() raise SystemExit() self.usage.help(1) diff --git a/slpkg/remove_packages.py b/slpkg/remove_packages.py index c6300cf4..0497d4df 100644 --- a/slpkg/remove_packages.py +++ b/slpkg/remove_packages.py @@ -16,9 +16,10 @@ from slpkg.models.models import session as Session class RemovePackages(Configs): """ Removes installed packages. """ - def __init__(self, packages: list, flags: list): + def __init__(self, packages: list, flags: list, file_pattern: str): self.packages = packages self.flags = flags + self.file_pattern = file_pattern self.session = Session self.color = self.colour() self.bold = self.color['bold'] @@ -43,7 +44,7 @@ class RemovePackages(Configs): view = ViewMessage(self.flags) self.installed_packages, self.dependencies = view.remove_packages( - self.packages) + self.packages, self.file_pattern) view.question() diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 60710cd6..4ed156a6 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -23,6 +23,7 @@ class ViewMessage(Configs): self.flag_resolve_off = '--resolve-off' self.flag_reinstall = '--reinstall' self.flag_yes = '--yes' + self.file_pattern = pattern = f'*{self.sbo_repo_tag}' self.session = Session self.utils = Utilities() self.black = Blacklist() @@ -107,8 +108,11 @@ class ViewMessage(Configs): self.summary(slackbuilds, dependencies=[], option='download') - def remove_packages(self, packages: list) -> Any: + def remove_packages(self, packages: list, file_pattern: str) -> Any: """ View remove packages. """ + if file_pattern: + self.file_pattern = file_pattern + slackbuilds, dependencies = [], [] for pkg in packages: slackbuilds.append(pkg) @@ -144,10 +148,9 @@ class ViewMessage(Configs): def _view_removed(self, name: str): """ View and creates list with packages for remove. """ - pattern = f'*{self.sbo_repo_tag}' - installed = self.utils.all_installed(pattern) + installed = self.utils.all_installed(self.file_pattern) - if self.utils.is_installed(name, pattern): + if self.utils.is_installed(name, self.file_pattern): for package in installed: pkg = self.utils.split_installed_pkg(package)[0] if pkg == name: @@ -183,8 +186,7 @@ class ViewMessage(Configs): install = upgrade = remove = 0 for sbo in slackbuilds: - pattern = f'*{self.sbo_repo_tag}' - installed = self.utils.is_installed(sbo, pattern) + installed = self.utils.is_installed(sbo, self.file_pattern) if not installed: install += 1