mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-17 07:48:18 +01:00
Fixed pylint errors
This commit is contained in:
parent
8ac952bc2c
commit
4712b2e96c
1 changed files with 57 additions and 17 deletions
|
@ -10,7 +10,11 @@ from typing import Any
|
|||
from pathlib import Path
|
||||
|
||||
|
||||
class NewConfigs:
|
||||
class NewConfigs: # pylint: disable=[R0902]
|
||||
|
||||
"""
|
||||
Tool that manage the config files.
|
||||
"""
|
||||
|
||||
def __init__(self, options: list):
|
||||
self.options: list = options
|
||||
|
@ -35,6 +39,8 @@ class NewConfigs:
|
|||
self.choice = None
|
||||
|
||||
def set_no_colors(self) -> None:
|
||||
""" Switch off colors.
|
||||
"""
|
||||
if '--no-colors' in self.options:
|
||||
self.bold: str = ''
|
||||
self.red: str = ''
|
||||
|
@ -45,7 +51,8 @@ class NewConfigs:
|
|||
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()):
|
||||
|
@ -75,7 +82,8 @@ class NewConfigs:
|
|||
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()
|
||||
|
@ -94,10 +102,13 @@ class NewConfigs:
|
|||
|
||||
@staticmethod
|
||||
def keep() -> None:
|
||||
""" 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()
|
||||
|
||||
|
@ -110,7 +121,8 @@ class NewConfigs:
|
|||
print() # new line
|
||||
|
||||
def overwrite_config_file(self) -> None:
|
||||
""" Copy tne 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")
|
||||
|
@ -119,7 +131,8 @@ class NewConfigs:
|
|||
print(f"mv {self.slpkg_config_new} -> {self.green}{self.slpkg_config}{self.endc}")
|
||||
|
||||
def overwrite_repositories_file(self) -> None:
|
||||
""" Copy tne 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")
|
||||
|
@ -128,7 +141,8 @@ class NewConfigs:
|
|||
print(f"mv {self.repositories_config_new} -> {self.green}{self.repositories_config}{self.endc}")
|
||||
|
||||
def overwrite_blacklist_file(self) -> None:
|
||||
""" Copy tne 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")
|
||||
|
@ -137,7 +151,8 @@ class NewConfigs:
|
|||
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()
|
||||
|
@ -145,25 +160,29 @@ class NewConfigs:
|
|||
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")
|
||||
|
@ -178,6 +197,8 @@ class NewConfigs:
|
|||
self.prompt_blacklist_config()
|
||||
|
||||
def prompt_slpkg_config(self) -> None:
|
||||
""" 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}/'
|
||||
|
@ -199,6 +220,8 @@ class NewConfigs:
|
|||
self.vimdiff(self.slpkg_config_new, self.slpkg_config)
|
||||
|
||||
def prompt_repositories_config(self) -> None:
|
||||
""" 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}/'
|
||||
|
@ -220,6 +243,8 @@ class NewConfigs:
|
|||
self.vimdiff(self.repositories_config_new, self.repositories_config)
|
||||
|
||||
def prompt_blacklist_config(self) -> None:
|
||||
""" 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}/'
|
||||
|
@ -242,9 +267,10 @@ class NewConfigs:
|
|||
|
||||
@staticmethod
|
||||
def diff_files(file2: Any, file1: Any) -> None:
|
||||
""" Diff the .new and the current file. """
|
||||
with open(file1, 'r') as f1:
|
||||
with open(file2, 'r') as f2:
|
||||
""" 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(
|
||||
f1.readlines(),
|
||||
f2.readlines(),
|
||||
|
@ -256,12 +282,26 @@ class NewConfigs:
|
|||
|
||||
@staticmethod
|
||||
def vimdiff(file1: Any, file2: Any) -> None:
|
||||
""" Show vimdiff command.
|
||||
|
||||
Args:
|
||||
file1 (Any): First file.
|
||||
file2 (Any): Second file.
|
||||
|
||||
Raises:
|
||||
SystemExit: Raise exit code.
|
||||
"""
|
||||
output = subprocess.call(f'vimdiff {file1} {file2}', shell=True)
|
||||
if output != 0:
|
||||
raise SystemExit(output)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
""" Manage arguments.
|
||||
|
||||
Raises:
|
||||
SystemExit: Description
|
||||
"""
|
||||
args: list = sys.argv
|
||||
args.pop(0)
|
||||
|
||||
|
@ -289,5 +329,5 @@ def main() -> None:
|
|||
try:
|
||||
config = NewConfigs(args)
|
||||
config.check()
|
||||
except KeyboardInterrupt:
|
||||
raise SystemExit(1)
|
||||
except KeyboardInterrupt as e:
|
||||
raise SystemExit(1) from e
|
||||
|
|
Loading…
Reference in a new issue