Source code for src.utilities
import yaml
from pathlib import Path
from typing import Optional
from colorama import Fore, Style
[docs]
def load_config(config_file_path:str|Path='config/config.yaml'):
"""Load the configuration from the YAML file."""
config_file_path = Path(config_file_path)
if not config_file_path.exists():
raise FileNotFoundError(f"Configuration file not found: {config_file_path}")
else:
print_update(level=1,message=f"Loading configuration from '{config_file_path}'")
with open(config_file_path, 'r') as file:
config = yaml.safe_load(file)
return config
[docs]
def print_update(level: int=None,
message: str="--",
alert:Optional[bool]=False):
if level is not None:
if level == 1:
color = Fore.YELLOW
prefix="└"
elif level == 2:
color = Fore.CYAN
prefix=" └"
elif level == 3:
color = Fore.LIGHTCYAN_EX + Style.DIM
prefix=" └"
elif level > 3:
color = Fore.LIGHTBLACK_EX + Style.DIM
prefix=" └─"
elif alert:
level=2
color = Fore.RED
prefix=" └ X "
else:
color = Fore.LIGHTMAGENTA_EX + Style.DIM
prefix=" ─"
print(f"{color}{prefix}> {message}{Style.RESET_ALL}")
[docs]
def print_module_title(text, Length_Char_inLine=60):
print(f"{Fore.LIGHTCYAN_EX}{Length_Char_inLine * '_'}{Style.RESET_ALL}\n"
f"{Fore.LIGHTGREEN_EX}{5 * ' '}{text}{Style.RESET_ALL}\n"
f"{Fore.LIGHTCYAN_EX}{Length_Char_inLine * '_'}{Style.RESET_ALL}")
[docs]
def print_banner(message: str):
line = "*" * len(message)
print(f"{Fore.GREEN}{Style.BRIGHT}{line}{Style.RESET_ALL}")
print(f"{Fore.GREEN}{Style.BRIGHT}{message}{Style.RESET_ALL}")
print(f"{Fore.GREEN}{Style.BRIGHT}{line}{Style.RESET_ALL}")
[docs]
def print_info(info:str):
print(f"{Fore.LIGHTBLACK_EX}{Style.BRIGHT}ℹ️ {info}{Style.RESET_ALL}")