Update docstrings

This commit is contained in:
Dimitris Zlatanidis 2024-05-20 22:55:30 +03:00
parent 432c2dc326
commit 5df895b309

View file

@ -10,10 +10,7 @@ from pathlib import Path
class NewConfigs: # pylint: disable=[R0902]
"""
Tool that manage the config files.
"""
"""Tool that manage the config files."""
def __init__(self, options: list):
self.options: list = options
@ -38,8 +35,7 @@ class NewConfigs: # pylint: disable=[R0902]
self.choice = None
def set_no_colors(self) -> None:
""" Switch off colors.
"""
"""Switch off colors."""
if '--no-colors' in self.options:
self.bold: str = ''
self.red: str = ''
@ -50,8 +46,7 @@ class NewConfigs: # pylint: disable=[R0902]
self.endc: str = ''
def check(self) -> None:
""" Checks for .new files.
"""
"""Checks for .new files."""
print('Checking for NEW configuration files...\n')
if (self.slpkg_config_new.is_file() or self.blacklist_config_new.is_file()
or self.repositories_config_new.is_file()):
@ -81,8 +76,7 @@ class NewConfigs: # pylint: disable=[R0902]
print(f"\n{'No .new files found.':>23}\n")
def menu(self) -> None:
""" Menu of choices.
"""
"""Menu of choices."""
choice: str = input('Choice: ')
choice: str = choice.lower()
@ -101,13 +95,11 @@ class NewConfigs: # pylint: disable=[R0902]
@staticmethod
def keep() -> None:
""" Prints a message.
"""
"""Prints a message."""
print("\nNo changes were made.\n")
def overwrite(self) -> None:
""" Copy tne .new files and rename the olds to .orig.
"""
"""Copy tne .new files and rename the olds to .orig."""
if self.slpkg_config_new.is_file():
self.overwrite_config_file()
@ -120,8 +112,7 @@ class NewConfigs: # pylint: disable=[R0902]
print() # new line
def overwrite_config_file(self) -> None:
""" Copy the slpkg.toml.new file and rename the old to .orig.
"""
"""Copy the slpkg.toml.new file and rename the old to .orig."""
if self.slpkg_config.is_file():
shutil.copy(self.slpkg_config, f"{self.slpkg_config}.orig")
print(f"\ncp {self.green}{self.slpkg_config}{self.endc} -> {self.slpkg_config}.orig")
@ -130,8 +121,7 @@ class NewConfigs: # pylint: disable=[R0902]
print(f"mv {self.slpkg_config_new} -> {self.green}{self.slpkg_config}{self.endc}")
def overwrite_repositories_file(self) -> None:
""" Copy the repositories.toml.new file and rename the old to .orig.
"""
"""Copy the repositories.toml.new file and rename the old to .orig."""
if self.slpkg_config.is_file():
shutil.copy(self.repositories_config, f"{self.repositories_config}.orig")
print(f"\ncp {self.green}{self.repositories_config}{self.endc} -> {self.repositories_config}.orig")
@ -140,8 +130,7 @@ class NewConfigs: # pylint: disable=[R0902]
print(f"mv {self.repositories_config_new} -> {self.green}{self.repositories_config}{self.endc}")
def overwrite_blacklist_file(self) -> None:
""" Copy the blacklist.toml.new file and rename the old to .orig.
"""
"""Copy the blacklist.toml.new file and rename the old to .orig."""
if self.blacklist_config.is_file():
shutil.copy(self.blacklist_config, f"{self.blacklist_config}.orig")
print(f"\ncp {self.green}{self.blacklist_config}{self.endc} -> {self.blacklist_config}.orig")
@ -150,8 +139,7 @@ class NewConfigs: # pylint: disable=[R0902]
print(f"mv {self.blacklist_config_new} -> {self.green}{self.blacklist_config}{self.endc}")
def remove(self) -> None:
""" Removes the .new files.
"""
"""Removes the .new files."""
print() # new line
self.remove_config_new_file()
self.remove_repositories_new_file()
@ -159,29 +147,25 @@ class NewConfigs: # pylint: disable=[R0902]
print() # new line
def remove_config_new_file(self) -> None:
""" Remove slpkg.toml.new file.
"""
"""Remove slpkg.toml.new file."""
if self.slpkg_config_new.is_file():
self.slpkg_config_new.unlink()
print(f"rm {self.red}{self.slpkg_config_new}{self.endc}")
def remove_repositories_new_file(self) -> None:
""" Remove repositories.toml.new file.
"""
"""Remove repositories.toml.new file."""
if self.repositories_config_new.is_file():
self.repositories_config_new.unlink()
print(f"rm {self.red}{self.repositories_config_new}{self.endc}")
def remove_blacklist_new_file(self) -> None:
""" Remove blacklist.toml.new file.
"""
"""Remove blacklist.toml.new file."""
if self.blacklist_config_new.is_file():
self.blacklist_config_new.unlink()
print(f"rm {self.red}{self.blacklist_config_new}{self.endc}")
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, "
f"({self.byellow}R{self.endc})emove, ({self.byellow}D{self.endc})iff, "
f"({self.byellow}V{self.endc})imdiff\n")
@ -196,8 +180,7 @@ class NewConfigs: # pylint: disable=[R0902]
self.prompt_blacklist_config()
def prompt_slpkg_config(self) -> None:
""" Prompt for slpkg.toml file.
"""
"""Prompt for slpkg.toml file."""
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}R{self.endc}/{self.byellow}D{self.endc}/'
@ -219,8 +202,7 @@ class NewConfigs: # pylint: disable=[R0902]
self.vimdiff(self.slpkg_config_new, self.slpkg_config)
def prompt_repositories_config(self) -> None:
""" Prompt for repositories.toml file.
"""
"""Prompt for repositories.toml file."""
make: str = input(f'{self.bgreen}{self.repositories_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}/'
@ -242,8 +224,7 @@ class NewConfigs: # pylint: disable=[R0902]
self.vimdiff(self.repositories_config_new, self.repositories_config)
def prompt_blacklist_config(self) -> None:
""" Prompt for blacklist.toml file.
"""
"""Prompt for blacklist.toml file."""
make: str = input(f'{self.bgreen}{self.blacklist_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}/'
@ -266,8 +247,7 @@ class NewConfigs: # pylint: disable=[R0902]
@staticmethod
def diff_files(file2: Path, file1: Path) -> None:
""" Diff the .new and the current file.
"""
"""Diff the .new and the current file."""
with open(file1, 'r', encoding='utf-8') as f1:
with open(file2, 'r', encoding='utf-8') as f2:
diff = difflib.context_diff(
@ -281,7 +261,7 @@ class NewConfigs: # pylint: disable=[R0902]
@staticmethod
def vimdiff(file1: Path, file2: Path) -> None:
""" Show vimdiff command.
"""Show vimdiff command.
Args:
file1 (Any): First file.
@ -296,7 +276,7 @@ class NewConfigs: # pylint: disable=[R0902]
def main() -> None:
""" Manage arguments.
"""Manage arguments.
Raises:
SystemExit: Description