Added option to remove

This commit is contained in:
Dimitris Zlatanidis 2023-01-23 23:14:24 +02:00
parent 8f7d857082
commit 6e9ab19646
5 changed files with 30 additions and 27 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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()

View file

@ -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