mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-27 09:58:10 +01:00
Fix for upgrade
This commit is contained in:
parent
faad926433
commit
811f267104
1 changed files with 12 additions and 50 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
from pkg_resources import parse_version
|
from pkg_resources import parse_version
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from slpkg.rules import Rules
|
from slpkg.rules import Rules
|
||||||
from slpkg.configs import Configs
|
from slpkg.configs import Configs
|
||||||
|
@ -24,57 +25,18 @@ class Upgrade(Configs):
|
||||||
|
|
||||||
def packages(self) -> Generator:
|
def packages(self) -> Generator:
|
||||||
""" Returns the upgradable packages. """
|
""" 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.
|
for installed in installed_package:
|
||||||
matched_packages: tuple = tuple(set(self.utils.installed_packages.keys()) & set(self.data.keys()))
|
name: str = self.utils.split_package(installed.name)['name']
|
||||||
|
if self.is_package_upgradeable(installed.name):
|
||||||
|
yield name
|
||||||
|
|
||||||
for package in matched_packages:
|
def is_package_upgradeable(self, installed: str) -> bool:
|
||||||
if self.is_package_upgradeable(package):
|
inst_name: str = self.utils.split_package(installed)['name']
|
||||||
yield package
|
if self.data.get(inst_name):
|
||||||
|
repo_package: str = self.data.get(inst_name).get('package')[:-4]
|
||||||
def is_package_upgradeable(self, name: str) -> bool:
|
if parse_version(repo_package) > parse_version(installed):
|
||||||
""" 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):
|
|
||||||
return True
|
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
|
return False
|
||||||
|
|
Loading…
Reference in a new issue