Added error ascii box

This commit is contained in:
Dimitris Zlatanidis 2023-01-12 22:09:20 +02:00
parent 792da416bb
commit 5eb871e21b
2 changed files with 38 additions and 3 deletions

View file

@ -1,3 +1,7 @@
4.4.8 - 12/01/2023
Added:
- Error ascii box for checksum
4.4.7 - 07/01/2023 4.4.7 - 07/01/2023
Added: Added:
- Finished report to download only - Finished report to download only

View file

@ -1,10 +1,13 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import shutil
import hashlib import hashlib
from pathlib import Path from pathlib import Path
from typing import Union from typing import Union
from slpkg.configs import Configs
from slpkg.views.ascii import Ascii
from slpkg.views.views import ViewMessage from slpkg.views.views import ViewMessage
@ -13,6 +16,26 @@ class Md5sum:
def __init__(self, flags: list): def __init__(self, flags: list):
self.flags = flags self.flags = flags
self.ascii = Ascii()
self.configs = Configs
self.colors = self.configs.colour
self.color = self.colors()
self.bold = self.color['bold']
self.red = self.color['red']
self.yellow = self.color['yellow']
self.violet = self.color['violet']
self.cyan = self.color['cyan']
self.endc = self.color['endc']
self.bred = f'{self.bold}{self.red}'
self.hl = self.ascii.horizontal_line
self.ulc = self.ascii.upper_left_corner
self.urc = self.ascii.upper_right_corner
self.vl = self.ascii.vertical_line
self.var = self.ascii.vertical_and_right
self.val = self.ascii.vertical_and_left
self.llc = self.ascii.lower_left_corner
self.lrc = self.ascii.lower_right_corner
self.columns, self.rows = shutil.get_terminal_size()
def check(self, path: Union[str, Path], source: str, checksum: str, name: str): def check(self, path: Union[str, Path], source: str, checksum: str, name: str):
""" Checksum the source. """ """ Checksum the source. """
@ -22,10 +45,18 @@ class Md5sum:
file_check = hashlib.md5(md5).hexdigest() file_check = hashlib.md5(md5).hexdigest()
checksum = "".join(checksum)
if file_check != checksum: if file_check != checksum:
print('\nExpected:', ''.join(checksum)) print('\n' + self.bred + self.ulc + self.hl * (self.columns - 2) + self.urc)
print('Found:', file_check) print(f"{self.bred}{self.vl}{self.red} Error:{self.endc} MD5SUM check for "
print(f'\nMD5SUM check for {name} FAILED.') f"{self.cyan}'{name}'{self.red} FAILED!" + ' ' * (self.columns - (len(name)) - 37) + self.vl)
print(self.bred + self.var + self.hl * (self.columns - 2) + self.val)
print(f'{self.bred}{self.vl}{self.yellow} Expected:{self.endc} {checksum}{self.bred}'
+ ' ' * (self.columns - (len(checksum)) - 13) + self.vl)
print(f'{self.bred}{self.vl}{self.violet} Found:{self.endc} {file_check}{self.bred}'
+ ' ' * (self.columns - (len(file_check)) - 10) + self.vl)
print(self.bred + self.llc + self.hl * (self.columns - 2) + self.lrc + self.endc)
view = ViewMessage(self.flags) view = ViewMessage(self.flags)
view.question() view.question()