From f2ddb6fd46164f5905fd40ec784bd0dba1228157 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 30 Dec 2021 18:05:31 -0500 Subject: [PATCH] better looking summary --- modules/util.py | 12 ++++++------ plex_meta_manager.py | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/util.py b/modules/util.py index 219341dd..edc9e936 100644 --- a/modules/util.py +++ b/modules/util.py @@ -183,19 +183,19 @@ def regex_first_int(data, id_type, default=None): else: raise Failed(f"Regex Error: Failed to parse {id_type} from {data}") -def centered(text, sep=" "): +def centered(text, sep=" ", side_space=True, left=False): if len(text) > screen_width - 2: return text space = screen_width - len(text) - 2 - text = f" {text} " + text = f"{' ' if side_space else sep}{text}{' ' if side_space else sep}" if space % 2 == 1: text += sep space -= 1 side = int(space / 2) - 1 - final_text = f"{sep * side}{text}{sep * side}" + final_text = f"{text}{sep * side}{sep * side}" if left else f"{sep * side}{text}{sep * side}" return final_text -def separator(text=None, space=True, border=True, debug=False): +def separator(text=None, space=True, border=True, debug=False, side_space=True, left=False): sep = " " if space else separating_character for handler in logger.handlers: apply_formatter(handler, border=False) @@ -208,9 +208,9 @@ def separator(text=None, space=True, border=True, debug=False): text_list = text.split("\n") for t in text_list: if debug: - logger.debug(f"|{sep}{centered(t, sep=sep)}{sep}|") + logger.debug(f"|{sep}{centered(t, sep=sep, side_space=side_space, left=left)}{sep}|") else: - logger.info(f"|{sep}{centered(t, sep=sep)}{sep}|") + logger.info(f"|{sep}{centered(t, sep=sep, side_space=side_space, left=left)}{sep}|") if border and debug: logger.debug(border_text) elif border: diff --git a/plex_meta_manager.py b/plex_meta_manager.py index a3200881..20a717b5 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -354,12 +354,16 @@ def update_libraries(config): for title in playlist_status: if len(title) > longest: longest = len(title) + def print_status(section, status): logger.info("") util.separator(f"{section} Summary", space=False, border=False) logger.info("") + logger.info(f"{'Title':^{longest}} | + | = | - | {'Status':^13}") + breaker = f"{util.separating_character * longest}|{util.separating_character * 5}|{util.separating_character * 5}|{util.separating_character * 5}|" + util.separator(breaker, space=False, border=False, side_space=False, left=True) for name, data in status.items(): - logger.info(f"{name:<{longest}} | {data['status']:<13} | +{data['added']} ={data['unchanged']} -{data['removed']}") + logger.info(f"{name:<{longest}} | {data['added']:^3} | {data['unchanged']:^3} | {data['removed']:^3} | {data['status']}") if data["errors"]: for error in data["errors"]: util.print_multiline(error, info=True)