Added to check for upgrade packages

This commit is contained in:
Dimitris Zlatanidis 2024-03-18 19:23:22 +02:00
parent d7fd8fe250
commit 4f7159028e
4 changed files with 97 additions and 21 deletions

View file

@ -9,6 +9,9 @@
* Blacklist using regex pattern
* Move command check-updates to option --check
- Added:
* Check for upgrade packages using the option --check
- Bugfixes:
* Double view message when update repositories

View file

@ -279,7 +279,6 @@ class Menu(Configs):
self.commands['-v'] = self.commands['--version']
self.commands['-u'] = self.commands['update']
self.commands['-U'] = self.commands['upgrade']
self.commands['-c'] = self.commands['check-updates']
self.commands['-I'] = self.commands['repo-info']
self.commands['-g'] = self.commands['configs']
self.commands['-T'] = self.commands['clean-tmp']
@ -305,7 +304,8 @@ class Menu(Configs):
def check_for_repositories(self) -> None:
""" Checks a combination for binaries use repositories only and if repository exists. """
except_options: tuple = (
'-s', 'search'
'-s', 'search',
'-U', 'upgrade'
)
if self.repository == '*' and not self.utils.is_option(except_options, self.args):
self.usage.help_minimal(f"{self.prog_name}: invalid repository '{self.repository}'")
@ -450,24 +450,32 @@ class Menu(Configs):
self.data: dict = self.utils.load_data(self.repository)
upgrade = Upgrade(self.repository, self.data)
packages: list = list(upgrade.packages())
packages: list = self.choose.packages(self.data, packages, command)
if not packages:
print('\nEverything is up-to-date!\n')
raise SystemExit(0)
if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]:
install = Packages(
self.repository, self.data, packages, self.flags, mode=command
)
if self.utils.is_option((self.flag_check, self.flag_short_check), self.flags):
upgrade.check_packages()
else:
install = Slackbuilds(
self.repository, self.data, packages, self.flags, mode=command
)
if self.repository == '*':
self.repository = self.repos.default_repository
self.data: dict = self.utils.load_data(self.repository)
install.execute()
packages: list = list(upgrade.packages())
packages: list = self.choose.packages(self.data, packages, command)
if not packages:
print('\nEverything is up-to-date!\n')
raise SystemExit(0)
if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]:
install = Packages(
self.repository, self.data, packages, self.flags, mode=command
)
else:
install = Slackbuilds(
self.repository, self.data, packages, self.flags, mode=command
)
install.execute()
raise SystemExit(0)
self.usage.help_short(1)
@ -755,8 +763,6 @@ def main() -> None:
# try:
arguments[args[0]]()
# except (KeyError, IndexError):
# logger = logging.getLogger(LoggingConfig.date_time)
# logger.exception(main.__name__)
# usage.help_short(1)
# except KeyboardInterrupt:
# raise SystemExit(1)

View file

@ -12,7 +12,6 @@ from multiprocessing import cpu_count
from slpkg.checksum import Md5sum
from slpkg.configs import Configs
from slpkg.upgrade import Upgrade
from slpkg.views.views import View
from slpkg.utilities import Utilities
from slpkg.dialog_box import DialogBox
@ -40,7 +39,6 @@ class Slackbuilds(Configs):
self.utils = Utilities()
self.dialogbox = DialogBox()
self.multi_proc = MultiProcess(flags)
self.upgrade = Upgrade(repository, data)
self.view = View(flags, repository, data)
self.check_md5 = Md5sum(flags)
self.download = Downloader(flags)

View file

@ -19,6 +19,8 @@ class Upgrade(Configs):
self.utils = Utilities()
self.repos = Repositories()
self.count_packages: int = 0
self.count_repos: list = []
def packages(self) -> Generator:
""" Returns the upgradable packages. """
@ -37,3 +39,70 @@ class Upgrade(Configs):
if parse_version(repo_package) > parse_version(installed):
return True
return False
def check_packages(self) -> None:
title: str = f"{'packages':<19} {'Version':<15} {'Build':<6} {'Repository':<15} {'Build':<5} {'Repo':>14}"
print(len(title) * '=')
print(f'{self.bgreen}{title}{self.endc}')
print(len(title) * '=')
if self.repository == '*':
for repo in self.data.keys():
repo_tag: str = self.repos.repositories[repo]['repo_tag']
installed_package: Generator = self.log_packages.glob(f'*{repo_tag}')
for installed in installed_package:
name: str = self.utils.split_package(installed.name)['name']
if self.data[repo].get(name):
repo_package: str = self.data[repo].get(name).get('package')[:-4]
if parse_version(repo_package) > parse_version(installed.name):
self.count_packages += 1
self.count_repos.append(repo)
repo_version: str = self.data[repo].get(name).get('version')
repo_build: str = self.data[repo].get(name).get('build')
inst_version: str = self.utils.split_package(installed.name)['version']
inst_build: str = self.utils.split_package(installed.name)['build']
if len(name) > 18:
name: str = f'{name[:15]}...'
if len(inst_version) > 15:
inst_version: str = f'{inst_version[:11]}...'
if len(repo_version) > 15:
repo_version: str = f'{repo_version[:11]}...'
print(f"{name:<19} {inst_version:<15} {inst_build:<6} {repo_version:<15} "
f"{repo_build:<5} {repo:>14}")
else:
repo_tag: str = self.repos.repositories[self.repository]['repo_tag']
installed_package: Generator = self.log_packages.glob(f'*{repo_tag}')
self.count_repos.append(self.repository)
for installed in installed_package:
name: str = self.utils.split_package(installed.name)['name']
if self.data.get(name):
repo_package: str = self.data.get(name).get('package')[:-4]
if parse_version(repo_package) > parse_version(installed.name):
self.count_packages += 1
repo_version: str = self.data.get(name).get('version')
repo_build: str = self.data.get(name).get('build')
inst_version: str = self.utils.split_package(installed.name)['version']
inst_build: str = self.utils.split_package(installed.name)['build']
if len(name) > 18:
name: str = f'{name[:15]}...'
if len(inst_version) > 15:
inst_version: str = f'{inst_version[:11]}...'
if len(repo_version) > 15:
repo_version: str = f'{repo_version[:11]}...'
print(f"{name:<19} {inst_version:<15} {inst_build:<6} {repo_version:<15} "
f"{repo_build:<5} {self.repository:>14}")
count_repos: int = len(set(self.count_repos))
repos_message: str = 'repository'
if count_repos > 1:
repos_message: str = 'repositories'
print(len(title) * '=')
print(f'{self.grey}Total packages for upgrade {self.count_packages} in {count_repos} '
f'{repos_message}.{self.endc}\n')