Added option to upgrade

This commit is contained in:
Dimitris Zlatanidis 2023-01-23 23:42:00 +02:00
parent 01d40b2d86
commit 9888b9e81e
4 changed files with 17 additions and 13 deletions

View file

@ -156,10 +156,12 @@ Print the repository package version. (to be used with: -e, dependees, -t, track
.P .P
--file-pattern=PATTERN --file-pattern=PATTERN
.RS .RS
Search for specific installed files with a pattern, such as: slpkg -f 'python' --file-pattern='*', 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. and 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: Also when you want to install and view packages that you have installed from other repositories, try like
slpkg -i podman --file-pattern='*alien'. (to be used with: -i, install, -r, remove, -f, find) `slpkg -i podman --file-pattern='*alien'` or if you want to check and upgrade packages from other repositories
`slpkg upgrade --file-pattern='*alien'` or remove packages with `slpkg -r <packages> --file-pattern='*'`.
(to be used with: upgrade, -i, install, -r, remove, -f, find)
.RE .RE
.P .P
-h | --help -h | --help

View file

@ -110,7 +110,8 @@ class Argparse(Configs):
self.flag_jobs, self.flag_jobs,
self.flag_resolve_off, self.flag_resolve_off,
self.flag_reinstall, self.flag_reinstall,
self.flag_no_silent self.flag_no_silent,
self.flag_file_pattern
], ],
'check-updates': [], 'check-updates': [],
'configs': [], 'configs': [],
@ -216,7 +217,7 @@ class Argparse(Configs):
if pkg == package: if pkg == package:
repo_ver = SBoQueries(package).version() repo_ver = SBoQueries(package).version()
inst_pkg = self.utils.is_installed(package, pattern=f'*{self.sbo_repo_tag}') inst_pkg = self.utils.is_installed(package, self.file_pattern)
inst_ver = self.utils.split_installed_pkg(inst_pkg)[1] inst_ver = self.utils.split_installed_pkg(inst_pkg)[1]
choices += [(package, f'{inst_ver} -> {repo_ver}', True)] choices += [(package, f'{inst_ver} -> {repo_ver}', True)]
@ -271,7 +272,7 @@ class Argparse(Configs):
if len(self.args) == 1: if len(self.args) == 1:
self.check.database() self.check.database()
upgrade = Upgrade() upgrade = Upgrade(self.file_pattern)
packages = list(upgrade.packages()) packages = list(upgrade.packages())
packages = self.choose_packages(packages, command) packages = self.choose_packages(packages, command)

View file

@ -11,9 +11,10 @@ from slpkg.configs import Configs
class Upgrade(Configs, Utilities): class Upgrade(Configs, Utilities):
""" Upgrade the installed packages. """ """ Upgrade the installed packages. """
def __init__(self): def __init__(self, file_pattern):
super(Configs, self).__init__() super(Configs, self).__init__()
super(Utilities, self).__init__() super(Utilities, self).__init__()
self.file_pattern = file_pattern
def packages(self): def packages(self):
""" Compares version of packages and returns the maximum. """ """ Compares version of packages and returns the maximum. """
@ -21,14 +22,14 @@ class Upgrade(Configs, Utilities):
black = Blacklist().get() black = Blacklist().get()
upgrade, requires = [], [] upgrade, requires = [], []
installed = self.all_installed(f'*{self.sbo_repo_tag}') installed = self.all_installed(self.file_pattern)
for pkg in installed: for pkg in installed:
inst_pkg_name = self.split_installed_pkg(pkg)[0] inst_pkg_name = self.split_installed_pkg(pkg)[0]
if inst_pkg_name not in black and inst_pkg_name in repo_packages: if inst_pkg_name not in black and inst_pkg_name in repo_packages:
if self.is_repo_version_bigger(inst_pkg_name): if self.is_repo_version_bigger(inst_pkg_name, self.file_pattern):
requires += Requires(inst_pkg_name).resolve() requires += Requires(inst_pkg_name).resolve()
upgrade.append(inst_pkg_name) upgrade.append(inst_pkg_name)

View file

@ -88,10 +88,10 @@ class Utilities:
time.strftime(f'[{self.cyan}%H:%M:%S{self.endc}]', time.strftime(f'[{self.cyan}%H:%M:%S{self.endc}]',
time.gmtime(elapsed_time))) time.gmtime(elapsed_time)))
def is_repo_version_bigger(self, package: str) -> bool: def is_repo_version_bigger(self, package: str, file_pattern: str) -> bool:
""" Compare two versions. """ """ Compare two versions. """
pattern = f'*{self.configs.sbo_repo_tag}' # pattern = f'*{self.configs.sbo_repo_tag}'
installed = self.is_installed(package, pattern) installed = self.is_installed(package, file_pattern)
if installed: if installed:
installed_version = self.split_installed_pkg(installed)[1] installed_version = self.split_installed_pkg(installed)[1]
repository_version = SBoQueries(package).version() repository_version = SBoQueries(package).version()