Updated for help

This commit is contained in:
Dimitris Zlatanidis 2023-03-14 19:57:08 +02:00
parent 19c7eefe7d
commit df9596abd2

View file

@ -1,6 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys
import shutil import shutil
import difflib import difflib
from pathlib import Path from pathlib import Path
@ -8,13 +9,27 @@ from pathlib import Path
class NewConfig: class NewConfig:
def __init__(self): def __init__(self, options: list):
self.options: list = options
self.etc_path: str = '/etc/slpkg' self.etc_path: str = '/etc/slpkg'
self.slpkg_config = Path(self.etc_path, 'slpkg.toml') self.slpkg_config = Path(self.etc_path, 'slpkg.toml')
self.blacklist_config = Path(self.etc_path, 'blacklist.toml') self.blacklist_config = Path(self.etc_path, 'blacklist.toml')
self.slpkg_config_new = Path(self.etc_path, 'slpkg.toml.new') self.slpkg_config_new = Path(self.etc_path, 'slpkg.toml.new')
self.blacklist_config_new = Path(self.etc_path, 'blacklist.toml.new') self.blacklist_config_new = Path(self.etc_path, 'blacklist.toml.new')
if '--no-colors' in self.options:
color = {
'bold': '',
'red': '',
'green': '',
'yellow': '',
'cyan': '',
'blue': '',
'grey': '',
'violet': '',
'endc': ''
}
else:
color = { color = {
'bold': '\033[1m', 'bold': '\033[1m',
'red': '\x1b[91m', 'red': '\x1b[91m',
@ -28,6 +43,7 @@ class NewConfig:
} }
self.bold: str = color['bold'] self.bold: str = color['bold']
self.red: str = color['red']
self.green: str = color['green'] self.green: str = color['green']
self.yellow: str = color['yellow'] self.yellow: str = color['yellow']
self.bgreen: str = f'{color["bold"]}{color["green"]}' self.bgreen: str = f'{color["bold"]}{color["green"]}'
@ -121,13 +137,13 @@ class NewConfig:
""" Remove slpkg.toml.new file. """ """ Remove slpkg.toml.new file. """
if self.slpkg_config_new.is_file(): if self.slpkg_config_new.is_file():
self.slpkg_config_new.unlink() self.slpkg_config_new.unlink()
print(f"rm {self.slpkg_config_new}") print(f"rm {self.red}{self.slpkg_config_new}{self.endc}")
def remove_blacklist_file(self): def remove_blacklist_file(self):
""" Remove blacklist.toml.new file. """ """ Remove blacklist.toml.new file. """
if self.blacklist_config_new.is_file(): if self.blacklist_config_new.is_file():
self.blacklist_config_new.unlink() self.blacklist_config_new.unlink()
print(f"rm {self.blacklist_config_new}") print(f"rm {self.red}{self.blacklist_config_new}{self.endc}")
def prompt(self): def prompt(self):
""" Prompt K, O, R selection for every single file. """ """ Prompt K, O, R selection for every single file. """
@ -183,5 +199,13 @@ class NewConfig:
if __name__ == '__main__': if __name__ == '__main__':
config = NewConfig() args = sys.argv
args.pop(0)
if '--help' in args or '-h' in args:
print('slpkg_new-configs [OPTIONS]\n'
'\n--no-colors Disable the output colors.\n'
'-h, --help Show this message and exit.\n')
sys.exit()
config = NewConfig(args)
config.check() config.check()