From 87791b2305bbbaa894b9b14a8f3b1433e691e04e Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 27 Mar 2024 19:04:58 +0200 Subject: [PATCH] Updated for no case --- configs/slpkg.toml | 9 ++------- slpkg/configs.py | 2 -- slpkg/main.py | 38 +++++++++----------------------------- slpkg/utilities.py | 18 +++++++++--------- tests/test_configs.py | 1 - 5 files changed, 20 insertions(+), 48 deletions(-) diff --git a/configs/slpkg.toml b/configs/slpkg.toml index 91d81fbb..9ede95f4 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -1,6 +1,6 @@ # This is the general configuration file of slpkg: # /etc/slpkg/slpkg.toml -# Updated: 20/03/2024, Version: 5.0.0 +# Updated: 27/03/2024, Version: 5.0.0 [CONFIGS] @@ -57,8 +57,7 @@ ASK_QUESTION = true PARALLEL_DOWNLOADS = false # If progress bar is true, it does not print the commands as they -# are executed. -# Default is false. [true/false] +# are executed. Default is false. [true/false] PROGRESS_BAR = false # There are 5 predefined spinners for the progress bar. @@ -75,10 +74,6 @@ SPINNER_COLOR = "green" # Default is bold_green. BORDER_COLOR = "bold_green" -# Enable or disable case-sensitive pattern matching. -# Default is true. [true/false] -CASE_SENSITIVE = true - # Keep process log files on /var/log/slpkg/ folder. # Default is true. [true/false] PROCESS_LOG = true diff --git a/slpkg/configs.py b/slpkg/configs.py index 635c930b..f60952e6 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -52,7 +52,6 @@ class Configs: progress_spinner: str = 'pixel' spinner_color: str = 'green' border_color: str = 'bold_green' - case_sensitive: bool = True process_log: bool = True urllib_retries: Any = False @@ -98,7 +97,6 @@ class Configs: progress_spinner: str = config['PROGRESS_SPINNER'] spinner_color: str = config['SPINNER_COLOR'] border_color: str = config['BORDER_COLOR'] - case_sensitive: bool = config['CASE_SENSITIVE'] process_log: bool = config['PROCESS_LOG'] urllib_retries: Any = config['URLLIB_RETRIES'] diff --git a/slpkg/main.py b/slpkg/main.py index d4ef7fc1..4cf4edec 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -77,11 +77,6 @@ class Menu(Configs): self.flag_search ) - self.flag_no_cases: tuple = ( - self.flag_no_case, - self.flag_short_no_case - ) - self.options: tuple = ( self.flag_yes, self.flag_short_yes, @@ -481,9 +476,7 @@ class Menu(Configs): if len(self.args) >= 2: self.data: dict = self.load_data.load(self.repository) packages: list = self.is_file_list_packages() - - if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive: - packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data) + packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data, self.flags) if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose.packages(self.data, packages, command) @@ -507,9 +500,7 @@ class Menu(Configs): if len(self.args) >= 2: self.data: dict = self.load_data.load(self.repository) packages: list = self.is_file_list_packages() - - if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive: - packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data) + packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data, self.flags) if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose.packages(self.data, packages, command) @@ -531,9 +522,7 @@ class Menu(Configs): if len(self.args) >= 2: self.data: dict = self.load_data.load(self.repository) packages: list = self.is_file_list_packages() - - if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive: - packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data) + packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data, self.flags) if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose.packages(self.data, packages, command) @@ -565,13 +554,10 @@ class Menu(Configs): if len(self.args) >= 2: packages: list = self.is_file_list_packages() - - if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive: - self.data: dict = self.load_data.load(self.repository) - packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data) + self.data: dict = self.load_data.load(self.repository) + packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data, self.flags) if self.utils.is_option(self.flag_searches, self.flags): - self.data: dict = self.load_data.load(self.repository) packages: list = self.choose.packages(self.data, packages, command) find = FindInstalled(self.flags, packages) @@ -585,9 +571,7 @@ class Menu(Configs): if len(self.args) >= 2: self.data: dict = self.load_data.load(self.repository) packages: list = self.is_file_list_packages() - - if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive: - packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data) + packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data, self.flags) if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose.packages(self.data, packages, command) @@ -624,9 +608,7 @@ class Menu(Configs): if len(self.args) >= 2: self.data: dict = self.load_data.load(self.repository) packages: list = self.is_file_list_packages() - - if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive: - packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data) + packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data, self.flags) if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose.packages(self.data, packages, command) @@ -644,9 +626,7 @@ class Menu(Configs): if len(self.args) >= 2: self.data: dict = self.load_data.load(self.repository) packages: list = self.is_file_list_packages() - - if self.utils.is_option(self.flag_no_cases, self.flags) or not self.case_sensitive: - packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data) + packages: list = self.utils.case_insensitive_pattern_matching(packages, self.data, self.flags) if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose.packages(self.data, packages, command) @@ -660,7 +640,7 @@ class Menu(Configs): class SubMenu: - """ Sub menu that separate from the main menu because of + """ Submenu that separate from the main menu because of have no options to manage here. """ def __init__(self, args: list): diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 43695622..d5f22b20 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -171,16 +171,16 @@ class Utilities(Configs): for file in os.listdir(folder): os.chown(Path(folder, file), 0, 0) - @staticmethod - def case_insensitive_pattern_matching(packages: list, data: dict) -> list: + def case_insensitive_pattern_matching(self, packages: list, data: dict, flags: list) -> list: """ Case-insensitive pattern matching packages. """ - repo_packages: tuple = tuple(data.keys()) - for package in packages: - for pkg in repo_packages: - if package.lower() == pkg.lower(): - packages.append(pkg) - packages.remove(package) - break + if self.is_option(('-m', '--no-case'), flags): + repo_packages: tuple = tuple(data.keys()) + for package in packages: + for pkg in repo_packages: + if package.lower() == pkg.lower(): + packages.append(pkg) + packages.remove(package) + break return packages def read_json_file(self, file: Path) -> dict: diff --git a/tests/test_configs.py b/tests/test_configs.py index db92ad99..23050bd6 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -46,7 +46,6 @@ class TestConfigs(unittest.TestCase): self.assertEqual('pixel', self.configs.progress_spinner) self.assertEqual('green', self.configs.spinner_color) self.assertEqual('bold_green', self.configs.border_color) - self.assertEqual(True, self.configs.case_sensitive) self.assertEqual(True, self.configs.process_log) self.assertEqual(False, self.configs.urllib_retries)