diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index 0bbbaac7..7b47e4b7 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -1,9 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - -from distutils.version import LooseVersion - from slpkg.configs import Configs from slpkg.queries import SBoQueries from slpkg.utilities import Utilities @@ -38,7 +35,7 @@ class Upgrade: inst_ver = self.utils.split_installed_pkg(pkg)[1] repo_ver = SBoQueries(inst_pkg_name).version() - if LooseVersion(repo_ver) > LooseVersion(inst_ver): + if self.utils.is_repo_version_bigger(repo_ver, inst_ver): requires += Requires(inst_pkg_name).resolve() upgrade.append(inst_pkg_name) diff --git a/slpkg/utilities.py b/slpkg/utilities.py index eba30100..b2d33d5f 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -5,6 +5,7 @@ import time import shutil import tarfile from pathlib import Path +from distutils.version import LooseVersion from slpkg.configs import Configs from slpkg.blacklist import Blacklist @@ -87,3 +88,8 @@ class Utilities: print(f'\n{self.yellow}Finished Successfully:{self.endc}', time.strftime(f'[{self.cyan}%H:%M:%S{self.endc}]', time.gmtime(elapsed_time))) + + @staticmethod + def is_repo_version_bigger(repository_version, installed_version): + """ Compare two versions. """ + return LooseVersion(repository_version) > LooseVersion(installed_version) diff --git a/slpkg/views/views.py b/slpkg/views/views.py index a58dadb1..503cace0 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -3,7 +3,6 @@ import os from typing import Any -from distutils.version import LooseVersion from slpkg.configs import Configs from slpkg.views.ascii import Ascii @@ -41,14 +40,15 @@ class ViewMessage: def view_packages(self, package, version, mode): """ Printing the main packages. """ + is_installed = self.utils.is_installed(package) color = self.cyan - if mode == 'install' and self.utils.is_installed(package): + if mode == 'install' and is_installed: color = self.grey if mode == 'remove': color = self.red if mode == 'build': color = self.yellow - if mode == 'upgrade': + if mode == 'upgrade' and is_installed: color = self.violet self.ascii.draw_view_package(package, version, color) @@ -191,7 +191,7 @@ class ViewMessage: install += 1 elif installed and self.flag_reinstall in self.flags: upgrade += 1 - elif (installed and LooseVersion(repo_ver) > LooseVersion(inst_ver) and + elif (installed and self.utils.is_repo_version_bigger(repo_ver, inst_ver) and self.flag_reinstall not in self.flags): upgrade += 1 elif installed and option == 'remove':