Added rules for manage special packages

This commit is contained in:
Dimitris Zlatanidis 2023-05-23 20:33:37 +03:00
parent 1c17bb1206
commit 4840867cf1
6 changed files with 47 additions and 1 deletions

View file

@ -4,6 +4,8 @@ Updated:
Fixed:
- ValueError with search command
- Updates some packages to the same version #169
Added:
- Configuration file rules.toml
4.8.5 - 18/05/2023
Fixed:

10
configs/rules.toml Normal file
View file

@ -0,0 +1,10 @@
# This file contains some special rules that the
# slpkg can handle better.
# /etc/slpkg/rules.toml
# Date: 23/05/2023, Version: 4.8.6
[UPDATES]
# If the installed package version pattern has a different matching
# than the repository version for some special rules like nvidia-kernel,
# please add the package in this list below.
PACKAGES = ["nvidia-kernel", "virtualbox-kernel"]

View file

@ -11,6 +11,7 @@ config() {
config etc/slpkg/slpkg.toml.new
config etc/slpkg/repositories.toml.new
config etc/slpkg/blacklist.toml.new
config etc/slpkg/rules.toml.new
if [ -x /usr/bin/update-desktop-database ]; then
/usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1

View file

@ -101,6 +101,7 @@ mkdir -p $PKG/etc/$PRGNAM
install -D -m0644 configs/slpkg.toml $PKG/etc/slpkg/slpkg.toml.new
install -D -m0644 configs/repositories.toml $PKG/etc/slpkg/repositories.toml.new
install -D -m0644 configs/blacklist.toml $PKG/etc/slpkg/blacklist.toml.new
install -D -m0644 configs/rules.toml $PKG/etc/slpkg/rules.toml.new
mkdir -p $PKG/usr/man/man1 & mkdir -p $PKG/usr/man/fr/man1
cp man/slpkg.1 $PKG/usr/man/man1

29
slpkg/rules.py Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import tomli
from pathlib import Path
from slpkg.configs import Configs
from slpkg.toml_error_message import TomlErrors
class Rules(Configs):
""" Reads and returns the rules. """
def __init__(self):
super(Configs, self).__init__()
self.errors = TomlErrors()
self.rules_file_toml = Path(self.etc_path, 'rules.toml')
def packages(self) -> list:
""" Reads the config rules file. """
if self.rules_file_toml.is_file():
try:
with open(self.rules_file_toml, 'rb') as conf:
return tomli.load(conf)['UPDATES']['PACKAGES']
except (tomli.TOMLDecodeError, KeyError) as error:
self.errors.raise_toml_error_message(error, self.rules_file_toml)
return []

View file

@ -9,6 +9,7 @@ from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
from slpkg.logging_config import LoggingConfig
from slpkg.rules import Rules
class Upgrade(Configs):
@ -21,6 +22,7 @@ class Upgrade(Configs):
self.utils = Utilities()
self.repos = Repositories()
self.rules = Rules()
self.is_binary: bool = self.utils.is_binary_repo(repository)
@ -61,7 +63,8 @@ class Upgrade(Configs):
# 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.
inst_package_version = f"{inst_package_version[:len(repo_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}'