From 9c7ff2172cf6186a7c6a5a2cf95d2e0a885bf39f Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Mon, 15 Apr 2024 19:43:49 +0300 Subject: [PATCH] Updated for kernel version --- ChangeLog.txt | 1 + configs/slpkg.toml | 6 ++++++ slpkg/configs.py | 1 + slpkg/dialog_configs.py | 8 +++++--- slpkg/upgrade.py | 8 +++++++- tests/test_configs.py | 1 + 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 4717bf70..d62b43cc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,7 @@ - Added: * Added to support custom repositories + * Added KERNEL_VERSION config to handle custom slackbuild version ### 5.0.5 - 12/04/2024 - Added: diff --git a/configs/slpkg.toml b/configs/slpkg.toml index 34612ca2..3acf5e62 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -52,6 +52,12 @@ ASCII_CHARACTERS = true # not work. Default is true. [true/false]. ASK_QUESTION = true +# This config removes the kernel version from some slackbuilds custom +# version build, like nvidia-kernel and virtualbox-kernel slackbuild packages. +# It helps to compare install and repository versions. +# Default is true. [true/false]. +KERNEL_VERSION = true + # Download sources in parallel. Default is false. [true/false] # Alternatively, you can use the option '--parallel'. PARALLEL_DOWNLOADS = false diff --git a/slpkg/configs.py b/slpkg/configs.py index 9aae49be..74d4fdce 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -81,6 +81,7 @@ class Configs: os_arch: str = config['os_arch'] download_only_path: Path = Path(config['download_only_path']) ask_question: bool = config['ask_question'] + kernel_version: str = config['kernel_version'] installpkg: str = config['installpkg'] reinstall: str = config['reinstall'] removepkg: str = config['removepkg'] diff --git a/slpkg/dialog_configs.py b/slpkg/dialog_configs.py index cf0f46f0..e61daaa5 100644 --- a/slpkg/dialog_configs.py +++ b/slpkg/dialog_configs.py @@ -38,7 +38,7 @@ class FormConfigs(Configs): title: str = ' Configuration File ' # Creating the elements for the dialog form. - for i, (key, value) in enumerate(self.configs['CONFIGS'].items(), start=1): + for i, (key, value) in enumerate(self.configs['configs'].items(), start=1): if value is True: value: str = 'true' elif value is False: @@ -76,6 +76,7 @@ class FormConfigs(Configs): 'SILENT_MODE', 'ASCII_CHARACTERS', 'ASK_QUESTION', + 'KERNEL_VERSION', 'PARALLEL_DOWNLOADS', 'PROGRESS_BAR', 'SPINNING_BAR', @@ -90,7 +91,7 @@ class FormConfigs(Configs): ] values: list = ['true', 'false'] - for key, value in zip(self.configs['CONFIGS'].keys(), tags): + for key, value in zip(self.configs['configs'].keys(), tags): if key in keys and value not in values: self.dialogbox.msgbox(f"\nError: Value for '{key}', it must be 'true' or 'false.'\n", @@ -115,7 +116,7 @@ class FormConfigs(Configs): with open(self.config_file, 'w') as patch_toml: for line in self.orig_configs: - for key, value in zip(self.configs['CONFIGS'].keys(), tags): + for key, value in zip(self.configs['configs'].keys(), tags): if line.lstrip().startswith(f'{key} ='): line = f' {key} = "{value}"\n' @@ -127,6 +128,7 @@ class FormConfigs(Configs): 'SILENT_MODE =', 'ASCII_CHARACTERS =', 'ASK_QUESTION =', + 'KERNEL_VERSION =', 'PARALLEL_DOWNLOADS =', 'MAXIMUM_PARALLEL = ', 'PROGRESS_BAR =', diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index dcc6d3c5..19ab83f5 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -2,9 +2,10 @@ # -*- coding: utf-8 -*- import shutil +import platform +from pathlib import Path from typing import Generator from packaging.version import parse, InvalidVersion -from pathlib import Path from slpkg.configs import Configs from slpkg.utilities import Utilities @@ -31,6 +32,7 @@ class Upgrade(Configs): self.installed_names: list = [] self.installed_packages: list = [] + self.kernel_ver: str = platform.uname()[2] self.columns, self.rows = shutil.get_terminal_size() def load_installed_packages(self, repository: str) -> None: @@ -89,7 +91,11 @@ class Upgrade(Configs): if self.data.get(inst_name): repo_version: str = self.data[inst_name]['version'] repo_build: str = self.data[inst_name]['build'] + inst_version: str = self.utils.split_package(installed)['version'] + if self.kernel_version and self.repository in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: + inst_version: str = inst_version.replace(f'_{self.kernel_ver}', '') + inst_build: str = self.utils.split_package(installed)['build'] try: if parse(repo_version) > parse(inst_version): diff --git a/tests/test_configs.py b/tests/test_configs.py index 2784ad20..1aac6a54 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -42,6 +42,7 @@ class TestConfigs(unittest.TestCase): self.assertEqual('-c mirror --parallel=100 --only-newer --delete', self.configs.lftp_mirror_options) self.assertEqual(True, self.configs.ascii_characters) self.assertEqual(True, self.configs.ask_question) + self.assertEqual(True, self.configs.kernel_version) self.assertEqual(False, self.configs.parallel_downloads) self.assertEqual(5, self.configs.maximum_parallel) self.assertEqual(True, self.configs.progress_bar)