update log print colours
This commit is contained in:
1 parent
f9ee0a0694
commit
57520eaa04
1 file changed
+9
-4
@@ -9,6 +9,11 @@ from pathlib import Path
|
||||
import time
|
||||
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")
|
||||
|
||||
def log_message(message):
|
||||
@@ -123,7 +128,7 @@ def create_m4b(root_path: Path, book_dir: Path) -> None:
|
||||
text=True,
|
||||
)
|
||||
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(
|
||||
cmd_backup,
|
||||
stdout=log,
|
||||
@@ -131,12 +136,12 @@ def create_m4b(root_path: Path, book_dir: Path) -> None:
|
||||
text=True,
|
||||
)
|
||||
if result.returncode == 0:
|
||||
log_message("Success, delete media files")
|
||||
output_file_tmp.rename(output_file_final)
|
||||
for media in media_files:
|
||||
media.unlink()
|
||||
log_message(f"{GREEN}[SUCCESS]{RESET}, delete media files")
|
||||
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]:
|
||||
"""
|
||||
@@ -205,7 +210,7 @@ def main() -> None:
|
||||
try:
|
||||
create_m4b(target,book_dir)
|
||||
except Exception as exc:
|
||||
log_message(f"[ERROR] {book_dir}: {exc}")
|
||||
log_message(f"{RED}[ERROR]{RESET} {book_dir}: {exc}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user