Updated for upgrade

This commit is contained in:
Dimitris Zlatanidis 2023-04-05 20:04:13 +03:00
parent 07d4953f8e
commit 2b344eeb41

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
from typing import Generator
from packaging.version import parse
from packaging.version import parse, InvalidVersion
from slpkg.configs import Configs
from slpkg.utilities import Utilities
@ -22,7 +22,7 @@ class Upgrade(Configs):
self.flag_bin_repository: list = ['-B', '--bin-repo=']
self.repo_for_binaries: bool = self.utils.is_option(self.flag_bin_repository, self.flags)
self.all_installed: list = self.utils.installed_packages
self.all_installed: list = self.utils.installed_package_names
def packages(self) -> Generator[str, None, None]:
""" Returns the upgradable packages. """
@ -31,13 +31,13 @@ class Upgrade(Configs):
else:
repo_packages: list = list(SBoQueries('').sbos())
for pkg in self.all_installed:
inst_package: str = self.utils.split_binary_pkg(pkg)[0]
# Compares two lists and get only the installed packages from the repository.
packages: list = list(set(self.all_installed) & set(repo_packages))
if inst_package in repo_packages:
for pkg in packages:
if self.is_package_upgradeable(inst_package):
yield inst_package
if self.is_package_upgradeable(pkg):
yield pkg
def is_package_upgradeable(self, name: str) -> bool:
""" Compares version of packages and returns the maximum. """
@ -58,13 +58,13 @@ class Upgrade(Configs):
repo_version: str = SBoQueries(name).version()
repo_build: str = self.utils.read_sbo_build_tag(name)
# print(f'{name} {repo_version}{repo_build} {inst_version}{inst_build}',
# parse(f'{repo_version}{repo_build}') > parse(f'{inst_version}{inst_build}'))
try:
if parse(repo_version) > parse(inst_version):
return True
if parse(repo_version) > parse(inst_version):
return True
if parse(repo_version) == parse(inst_version) and parse(repo_build) > parse(inst_build):
return True
if parse(repo_version) == parse(inst_version) and parse(repo_build) > parse(inst_build):
return True
except InvalidVersion:
pass
return False