Moved compare to utilities

This commit is contained in:
Dimitris Zlatanidis 2023-01-13 23:37:33 +02:00
parent 9185b1c1a7
commit 262c4e5d2e
3 changed files with 11 additions and 8 deletions

View file

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

View file

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

View file

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