fck/fck/checker.py

33 lines
883 B
Python

from typing import Generator, List, Tuple, Optional
from .file import FILE
import re
def checkmark(value: Optional[bool] = None) -> str:
"""
Takes optional bool and returns colored string.
"""
return {
True: '\033[92m✓\033[0m',
False: '\033[91m❌\033[0m',
None: '\033[33m?\033[0m'
}[value]
def check(f: FILE, largefile: bool = False) -> bool:
"""
Check given file and return checked file.
"""
f.csum.reset()
try:
with open(f.fpath, 'rb') as file:
if not largefile:
f.csum.gensum(file.read())
else:
for line in file:
f.csum.gensum(line)
except FileNotFoundError:
print(f"[WARN]: No such file or directory: {f.fpath}")
print(f"{checkmark(f.verify())} \t {f.csum} \t {f.esum} \t {f.fname}")
return f.verify()