Fixed for pylint errors

This commit is contained in:
Dimitris Zlatanidis 2024-04-26 22:03:05 +03:00
parent 6b78a1c01d
commit c107f69e89

View file

@ -15,7 +15,7 @@ from slpkg.dialog_box import DialogBox
from slpkg.multi_process import MultiProcess
class RemovePackages(Configs):
class RemovePackages(Configs): # pylint: disable=[R0902]
""" Removes installed packages with dependencies if they installed with
slpkg install command.
"""
@ -37,7 +37,12 @@ class RemovePackages(Configs):
self.option_for_yes: bool = self.utils.is_option(
('-y', '--yes'), flags)
def remove(self, upgrade=False) -> None:
def remove(self, upgrade: bool = False) -> None:
""" Remove packages
Args:
upgrade (bool, optional): Is packages comes from upgrade method.
"""
self.deps_log: dict = self.utils.read_json_file(self.deps_log_file)
if upgrade:
@ -50,7 +55,7 @@ class RemovePackages(Configs):
self.add_installed_dependencies_to_remove()
self.view.remove_packages(self.packages, self.dependencies)
self.found_dependent()
self.find_dependent()
answer: str = 'y'
if upgrade:
@ -65,6 +70,8 @@ class RemovePackages(Configs):
self.utils.finished_time(elapsed_time)
def add_packages_for_remove(self) -> None:
""" Add packages for remove.
"""
for package in self.packages:
installed: str = self.utils.is_package_installed(package)
if installed:
@ -76,7 +83,9 @@ class RemovePackages(Configs):
if self.utils.is_package_installed(dep) and dep not in self.packages:
self.dependencies.append(dep)
def found_dependent(self) -> None:
def find_dependent(self) -> None:
""" Find packages that depend on other packages.
"""
for package in self.packages_for_remove:
name: str = self.utils.split_package(package)['name']
version: str = self.utils.split_package(package)['version']
@ -91,15 +100,21 @@ class RemovePackages(Configs):
print(f"{'':>2}{pkg} {self.grey}{ver}{self.endc}")
def remove_doubles_dependencies(self) -> None:
""" Removes doubles packages.
"""
self.dependencies: list = list(set(self.dependencies))
def add_installed_dependencies_to_remove(self) -> None:
""" Adds dependencies for remove.
"""
for dep in self.dependencies:
installed: str = self.utils.is_package_installed(dep)
if installed:
self.packages_for_remove.append(installed)
def remove_packages(self) -> None:
""" Remove packages.
"""
# Remove old slpkg.log file.
if self.slpkg_log_file.is_file():
self.slpkg_log_file.unlink()
@ -114,9 +129,18 @@ class RemovePackages(Configs):
if name in self.deps_log.keys():
self.deps_log.pop(name)
self.deps_log_file.write_text(json.dumps(self.deps_log, indent=4))
self.deps_log_file.write_text(json.dumps(self.deps_log, indent=4), encoding='utf-8')
def choose_packages_for_remove(self, packages: list, upgrade=False) -> list:
def choose_packages_for_remove(self, packages: list, upgrade: bool = False) -> list:
""" Choose packages via dialog utility.
Args:
packages (list): Description
upgrade (bool, optional): Description
Returns:
list: List of package names.
"""
if packages and self.dialog:
height: int = 10
width: int = 70
@ -134,12 +158,17 @@ class RemovePackages(Configs):
text: str = f'There are {len(choices)} dependencies:'
if upgrade:
text: str = f'There are {len(choices)} packages:'
code, packages = self.dialogbox.checklist(text, title, height, width, list_height, choices)
code, packages = self.dialogbox.checklist(text, title, height, width, list_height, choices) # pylint: disable=[W0612]
os.system('clear')
return packages
return packages
def remove_question(self) -> str | None:
""" Question about remove packages.
Returns:
str | None: Answer.
"""
if not self.option_for_yes and self.ask_question:
answer: str = input('\nDo you want to remove these packages? [y/N] ')
return answer