Fix for upgrade

This commit is contained in:
Dimitris Zlatanidis 2024-03-15 20:41:47 +02:00
parent faad926433
commit 811f267104

View file

@ -3,6 +3,7 @@
from typing import Generator
from pkg_resources import parse_version
from pathlib import Path
from slpkg.rules import Rules
from slpkg.configs import Configs
@ -24,57 +25,18 @@ class Upgrade(Configs):
def packages(self) -> Generator:
""" Returns the upgradable packages. """
repo_tag: str = self.repos.repositories[self.repository]['repo_tag']
installed_package: Generator = self.log_packages.glob(f'*{repo_tag}')
# Returns the matched packages between two lists.
matched_packages: tuple = tuple(set(self.utils.installed_packages.keys()) & set(self.data.keys()))
for installed in installed_package:
name: str = self.utils.split_package(installed.name)['name']
if self.is_package_upgradeable(installed.name):
yield name
for package in matched_packages:
if self.is_package_upgradeable(package):
yield package
def is_package_upgradeable(self, name: str) -> bool:
""" Compares version of packages and returns the maximum. """
repo_package_version = repo_package_build = '0'
inst_package_version = inst_package_build = '0'
inst_package: str = self.utils.is_package_installed(name)
if inst_package and inst_package.endswith(self.repos.repositories[self.repository]['repo_tag']):
inst_package_version: str = self.utils.split_package(inst_package)['version']
inst_package_build: str = self.utils.split_package(inst_package)['build']
repo_package_version: str = self.data[name]['version']
if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name] and self.data.get(name):
repo_package: str = self.data[name]['package']
repo_package_build: str = self.utils.split_package(repo_package)['build']
else:
repo_location: str = self.data[name]['location']
repo_package_build: str = self.utils.read_slackbuild_build_tag(
name, repo_location, self.repository)
# Patches installed version to matching with repository package version.
# It fixes installed package version, packages like nvidia-kernel and virtualbox-kernel
# that contain the kernel version with package version.
if name in self.rules.packages():
inst_package_version = f"{inst_package_version[:len(repo_package_version)]}"
repository_package: str = f'{name}-{repo_package_version}'
installed_package: str = f'{name}-{inst_package_version}'
try:
if parse_version(repository_package) > parse_version(installed_package):
def is_package_upgradeable(self, installed: str) -> bool:
inst_name: str = self.utils.split_package(installed)['name']
if self.data.get(inst_name):
repo_package: str = self.data.get(inst_name).get('package')[:-4]
if parse_version(repo_package) > parse_version(installed):
return True
if (parse_version(repository_package) == parse_version(installed_package)
and parse_version(repo_package_build) > parse_version(inst_package_build)):
return True
except ValueError:
pass
if repository_package > installed_package:
return True
if repository_package == installed_package and repo_package_build > inst_package_build:
return True
return False