Remove rules.toml

This commit is contained in:
Dimitris Zlatanidis 2024-03-17 19:34:10 +02:00
parent 6f51681333
commit da48af38b5
7 changed files with 4 additions and 92 deletions

View file

@ -5,6 +5,7 @@
* Remove SQLAlchemy dependency * Remove SQLAlchemy dependency
* Remove help command, instead use manpage * Remove help command, instead use manpage
* Remove clean-logs and clean-data commands * Remove clean-logs and clean-data commands
* remove rules.toml config file
* Blacklist using regex pattern * Blacklist using regex pattern
- Bugfixes: - Bugfixes:

View file

@ -1,10 +0,0 @@
# This file contains some special rules that the
# slpkg can handle better.
# /etc/slpkg/rules.toml
# Updated: 30/11/2023, Version: 4.9.3
[UPGRADE]
# Please add in this list below, if the installed package version pattern
# has a different matching than the repository version for some special rules,
# like nvidia-kernel.
PACKAGES = ["nvidia-kernel", "virtualbox-kernel"]

View file

@ -8,7 +8,7 @@ config() {
fi fi
} }
FILES="slpkg repositories blacklist rules" FILES="slpkg repositories blacklist"
for file in $FILES; do for file in $FILES; do
config etc/slpkg/$file.toml.new config etc/slpkg/$file.toml.new
done done

View file

@ -95,7 +95,7 @@ find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | gr
# Install configuration files and creating lib directory # Install configuration files and creating lib directory
mkdir -p $PKG/etc/$PRGNAM mkdir -p $PKG/etc/$PRGNAM
FILES="slpkg repositories blacklist rules" FILES="slpkg repositories blacklist"
for file in $FILES; do for file in $FILES; do
install -D -m0644 configs/$file.toml $PKG/etc/slpkg/$file.toml.new install -D -m0644 configs/$file.toml $PKG/etc/slpkg/$file.toml.new
done done

View file

@ -17,11 +17,9 @@ class NewConfigs:
self.slpkg_config: Path = Path(self.etc_path, 'slpkg.toml') self.slpkg_config: Path = Path(self.etc_path, 'slpkg.toml')
self.repositories_config: Path = Path(self.etc_path, 'repositories.toml') self.repositories_config: Path = Path(self.etc_path, 'repositories.toml')
self.blacklist_config: Path = Path(self.etc_path, 'blacklist.toml') self.blacklist_config: Path = Path(self.etc_path, 'blacklist.toml')
self.rules_config: Path = Path(self.etc_path, 'rules.toml')
self.slpkg_config_new: Path = Path(self.etc_path, 'slpkg.toml.new') self.slpkg_config_new: Path = Path(self.etc_path, 'slpkg.toml.new')
self.repositories_config_new: Path = Path(self.etc_path, 'repositories.toml.new') self.repositories_config_new: Path = Path(self.etc_path, 'repositories.toml.new')
self.blacklist_config_new: Path = Path(self.etc_path, 'blacklist.toml.new') self.blacklist_config_new: Path = Path(self.etc_path, 'blacklist.toml.new')
self.rules_config_new: Path = Path(self.etc_path, 'rules.toml.new')
self.bold: str = '\033[1m' self.bold: str = '\033[1m'
self.red: str = '\x1b[91m' self.red: str = '\x1b[91m'
@ -59,7 +57,7 @@ class NewConfigs:
""" Checks for .new files. """ """ Checks for .new files. """
print('\nChecking for NEW configuration files...') print('\nChecking for NEW configuration files...')
if (self.slpkg_config_new.is_file() or self.blacklist_config_new.is_file() if (self.slpkg_config_new.is_file() or self.blacklist_config_new.is_file()
or self.repositories_config_new.is_file() or self.rules_config_new.is_file()): or self.repositories_config_new.is_file()):
print('\nThere are NEW files:\n') print('\nThere are NEW files:\n')
if self.slpkg_config_new.is_file(): if self.slpkg_config_new.is_file():
@ -71,9 +69,6 @@ class NewConfigs:
if self.blacklist_config_new.is_file(): if self.blacklist_config_new.is_file():
print(f"{self.bgreen:>12}{self.blacklist_config_new}{self.endc}") print(f"{self.bgreen:>12}{self.blacklist_config_new}{self.endc}")
if self.rules_config_new.is_file():
print(f"{self.bgreen:>12}{self.rules_config_new}{self.endc}")
print(f'\nWhat would you like to do ({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/' print(f'\nWhat would you like to do ({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
f'{self.byellow}R{self.endc}/{self.byellow}P{self.endc})?\n') f'{self.byellow}R{self.endc}/{self.byellow}P{self.endc})?\n')
@ -121,8 +116,6 @@ class NewConfigs:
if self.blacklist_config_new.is_file(): if self.blacklist_config_new.is_file():
self.overwrite_blacklist_file() self.overwrite_blacklist_file()
if self.rules_config_new.is_file():
self.overwrite_rules_file()
print() # new line print() # new line
def overwrite_config_file(self) -> None: def overwrite_config_file(self) -> None:
@ -152,22 +145,12 @@ class NewConfigs:
shutil.move(self.blacklist_config_new, self.blacklist_config) shutil.move(self.blacklist_config_new, self.blacklist_config)
print(f"mv {self.blacklist_config_new} -> {self.green}{self.blacklist_config}{self.endc}") print(f"mv {self.blacklist_config_new} -> {self.green}{self.blacklist_config}{self.endc}")
def overwrite_rules_file(self) -> None:
""" Copy tne rules.toml.new file and rename the old to .orig. """
if self.rules_config.is_file():
shutil.copy(self.rules_config, f"{self.rules_config}.orig")
print(f"\ncp {self.green}{self.rules_config}{self.endc} -> {self.rules_config}.orig")
shutil.move(self.rules_config_new, self.rules_config)
print(f"mv {self.rules_config_new} -> {self.green}{self.rules_config}{self.endc}")
def remove(self) -> None: def remove(self) -> None:
""" Removes the .new files. """ """ Removes the .new files. """
print() # new line print() # new line
self.remove_config_new_file() self.remove_config_new_file()
self.remove_repositories_new_file() self.remove_repositories_new_file()
self.remove_blacklist_new_file() self.remove_blacklist_new_file()
self.remove_rules_new_file()
print() # new line print() # new line
def remove_config_new_file(self) -> None: def remove_config_new_file(self) -> None:
@ -188,12 +171,6 @@ class NewConfigs:
self.blacklist_config_new.unlink() self.blacklist_config_new.unlink()
print(f"rm {self.red}{self.blacklist_config_new}{self.endc}") print(f"rm {self.red}{self.blacklist_config_new}{self.endc}")
def remove_rules_new_file(self) -> None:
""" Remove rules.toml.new file. """
if self.rules_config_new.is_file():
self.rules_config_new.unlink()
print(f"rm {self.red}{self.rules_config_new}{self.endc}")
def prompt(self) -> None: def prompt(self) -> None:
""" Prompt K, O, R selection for every single file. """ """ Prompt K, O, R selection for every single file. """
print(f"\n{'':>2}({self.byellow}K{self.endc})eep, ({self.byellow}O{self.endc})verwrite, " print(f"\n{'':>2}({self.byellow}K{self.endc})eep, ({self.byellow}O{self.endc})verwrite, "
@ -209,9 +186,6 @@ class NewConfigs:
if self.blacklist_config_new.is_file(): if self.blacklist_config_new.is_file():
self.prompt_blacklist_config() self.prompt_blacklist_config()
if self.rules_config_new.is_file():
self.prompt_rules_config()
def prompt_slpkg_config(self) -> None: def prompt_slpkg_config(self) -> None:
make: str = input(f'{self.bgreen}{self.slpkg_config_new}{self.endc} - ' make: str = input(f'{self.bgreen}{self.slpkg_config_new}{self.endc} - '
f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/' f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
@ -272,26 +246,6 @@ class NewConfigs:
if make.lower() == 'v': if make.lower() == 'v':
self.vimdiff(self.blacklist_config_new, self.blacklist_config) self.vimdiff(self.blacklist_config_new, self.blacklist_config)
def prompt_rules_config(self) -> None:
make: str = input(f'{self.bgreen}{self.rules_config_new}{self.endc} - '
f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
f'{self.byellow}R{self.endc}/{self.byellow}D{self.endc}/'
f'{self.byellow}V{self.endc}): ')
if make.lower() == 'k':
pass
if make.lower() == 'o':
self.overwrite_rules_file()
print() # new line
if make.lower() == 'r':
print() # new line
self.remove_rules_new_file()
print() # new line
if make.lower() == 'd':
self.diff_files(self.rules_config_new, self.rules_config)
if make.lower() == 'v':
self.vimdiff(self.rules_config_new, self.rules_config)
@staticmethod @staticmethod
def diff_files(file2: Any, file1: Any) -> None: def diff_files(file2: Any, file1: Any) -> None:
""" Diff the .new and the current file. """ """ Diff the .new and the current file. """

View file

@ -1,30 +0,0 @@
#!/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) -> tuple:
""" Reads the config rules file. """
packages: tuple = tuple()
if self.rules_file_toml.is_file():
try:
with open(self.rules_file_toml, 'rb') as conf:
packages: tuple = tuple(tomli.load(conf)['UPGRADE']['PACKAGES'])
except (tomli.TOMLDecodeError, KeyError) as error:
self.errors.raise_toml_error_message(error, self.rules_file_toml)
return packages

View file

@ -3,9 +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.configs import Configs from slpkg.configs import Configs
from slpkg.utilities import Utilities from slpkg.utilities import Utilities
from slpkg.repositories import Repositories from slpkg.repositories import Repositories
@ -21,7 +19,6 @@ class Upgrade(Configs):
self.utils = Utilities() self.utils = Utilities()
self.repos = Repositories() self.repos = Repositories()
self.rules = Rules()
def packages(self) -> Generator: def packages(self) -> Generator:
""" Returns the upgradable packages. """ """ Returns the upgradable packages. """