Updated for no case

This commit is contained in:
Dimitris Zlatanidis 2024-03-27 19:04:58 +02:00
parent 639ad89d24
commit 87791b2305
5 changed files with 20 additions and 48 deletions

View file

@ -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

View file

@ -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']

View file

@ -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):

View file

@ -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:

View file

@ -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)