From d096fbb4f2251ee41c3260bacf807bbfc931c029 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 23 May 2023 21:34:30 +0300 Subject: [PATCH] Updated for rules --- README.md | 3 +++ man/slpkg.1 | 2 ++ slpkg/new_configs.py | 52 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 677126ab..ffce77c2 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,9 @@ For further information, please read the manpage: /etc/slpkg/blacklist.toml Blacklist of packages + +/etc/slpkg/rules.toml + Rules file in the /etc/slpkg/rules.toml file. ``` ### Repositories diff --git a/man/slpkg.1 b/man/slpkg.1 index 52e2dee1..d9c1adfd 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -274,6 +274,8 @@ Repositories file in the /etc/slpkg/repositories.toml file. .P Blacklist file in the /etc/slpkg/blacklist.toml file. .P +Rules file in the /etc/slpkg/rules.toml file. +.P \fIslpkg_new-configs\fR command it's managing the .new configuration files easily and fast. Move, copy or remove them. .RE .SH REPORT BUGS diff --git a/slpkg/new_configs.py b/slpkg/new_configs.py index dd1e51d0..15800143 100644 --- a/slpkg/new_configs.py +++ b/slpkg/new_configs.py @@ -17,9 +17,11 @@ class NewConfigs: self.slpkg_config: Path = Path(self.etc_path, 'slpkg.toml') self.repositories_config: Path = Path(self.etc_path, 'repositories.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.repositories_config_new: Path = Path(self.etc_path, 'repositories.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.red: str = '\x1b[91m' @@ -57,7 +59,7 @@ class NewConfigs: """ Checks for .new files. """ print('\nChecking for NEW configuration files...') if (self.slpkg_config_new.is_file() or self.blacklist_config_new.is_file() - or self.repositories_config_new.is_file()): + or self.repositories_config_new.is_file() or self.rules_config_new.is_file()): print('\nThere are NEW files:\n') if self.slpkg_config_new.is_file(): @@ -69,6 +71,9 @@ class NewConfigs: if self.blacklist_config_new.is_file(): 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}/' f'{self.byellow}R{self.endc}/{self.byellow}P{self.endc})?\n') @@ -80,8 +85,7 @@ class NewConfigs: self.menu() - elif (not self.slpkg_config_new.is_file() and not self.blacklist_config_new.is_file() - and not self.repositories_config_new.is_file()): + else: print(f"\n{'No .new files found.':>23}\n") def menu(self) -> None: @@ -116,6 +120,9 @@ class NewConfigs: if self.blacklist_config_new.is_file(): self.overwrite_blacklist_file() + + if self.rules_config_new.is_file(): + self.overwrite_rules_file() print() # new line def overwrite_config_file(self) -> None: @@ -145,12 +152,22 @@ class NewConfigs: shutil.move(self.blacklist_config_new, self.blacklist_config) 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: """ Removes the .new files. """ print() # new line self.remove_config_new_file() self.remove_repositories_new_file() self.remove_blacklist_new_file() + self.remove_rules_new_file() print() # new line def remove_config_new_file(self) -> None: @@ -171,6 +188,12 @@ class NewConfigs: self.blacklist_config_new.unlink() 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: """ 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, " @@ -186,6 +209,9 @@ class NewConfigs: if self.blacklist_config_new.is_file(): self.prompt_blacklist_config() + if self.rules_config_new.is_file(): + self.prompt_rules_config() + def prompt_slpkg_config(self): make: str = input(f'{self.bgreen}{self.slpkg_config_new}{self.endc} - ' f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/' @@ -246,6 +272,26 @@ class NewConfigs: if make.lower() == 'v': self.vimdiff(self.blacklist_config_new, self.blacklist_config) + def prompt_rules_config(self): + 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 def diff_files(file2: Any, file1: Any) -> None: """ Diff the .new and the current file. """