update log print colours

This commit is contained in:
Lucas Vivo committed 2026-10-07 12:01:20 +02:00
1 parent f9ee0a0694
commit 57520eaa04
1 file changed
+9 -4
@@ -9,6 +9,11 @@ from pathlib import Path
import time import time
from typing import Any from typing import Any
RED = "\033[91m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
BLUE = "\033[94m"
RESET = "\033[0m"
logfile=Path(f"media_{time.strftime("%Y%m%d_%H%M%S")}.log") logfile=Path(f"media_{time.strftime("%Y%m%d_%H%M%S")}.log")
def log_message(message): def log_message(message):
@@ -123,7 +128,7 @@ def create_m4b(root_path: Path, book_dir: Path) -> None:
text=True, text=True,
) )
if result.returncode == 234: if result.returncode == 234:
log_message(f"[ERROR] {result.returncode} retrying with aac encoder") log_message(f"{YELLOW}[WARNING]{RESET} {result.returncode} retrying with aac encoder")
result = subprocess.run( result = subprocess.run(
cmd_backup, cmd_backup,
stdout=log, stdout=log,
@@ -131,12 +136,12 @@ def create_m4b(root_path: Path, book_dir: Path) -> None:
text=True, text=True,
) )
if result.returncode == 0: if result.returncode == 0:
log_message("Success, delete media files")
output_file_tmp.rename(output_file_final) output_file_tmp.rename(output_file_final)
for media in media_files: for media in media_files:
media.unlink() media.unlink()
log_message(f"{GREEN}[SUCCESS]{RESET}, delete media files")
else: else:
log_message(f"FAILED: Code: {result.returncode}, Stderr: {result.stderr}") log_message(f"{RED}[ERROR]{RESET} Code: {result.returncode}, Stderr: {result.stderr}")
def find_book_dirs(root: Path) -> tuple[list[Any], int]: def find_book_dirs(root: Path) -> tuple[list[Any], int]:
""" """
@@ -205,7 +210,7 @@ def main() -> None:
try: try:
create_m4b(target,book_dir) create_m4b(target,book_dir)
except Exception as exc: except Exception as exc:
log_message(f"[ERROR] {book_dir}: {exc}") log_message(f"{RED}[ERROR]{RESET} {book_dir}: {exc}")
if __name__ == "__main__": if __name__ == "__main__":