From 6a4dd77576c55dce14d7486a6c7ac6760d6b5575 Mon Sep 17 00:00:00 2001 From: Valentin Date: Sun, 18 Jun 2023 14:21:19 +0300 Subject: [PATCH] Added a new type category: Timer, and 3 entries for it --- docs/DATA.md | 5 + mighty_logger/powerful_logger.py | 186 ++++++++++++++++++++++++++++++- mighty_logger/src/log_enums.py | 3 + mighty_logger/text/icon_set.py | 15 +++ test/test_console.py | 5 + test/test_html.py | 10 +- 6 files changed, 218 insertions(+), 6 deletions(-) diff --git a/docs/DATA.md b/docs/DATA.md index 4a2c0e2..cf3a662 100644 --- a/docs/DATA.md +++ b/docs/DATA.md @@ -40,6 +40,10 @@ The library stores various important data for use that you may need to know whil - milestone (v0.6.0) - success - fail +- Timer (^) + - start_timer (v0.6.1) + - timer_mark (v0.6.1) + - stop_timer (v0.6.1) ###### Settings: - Global: @@ -121,6 +125,7 @@ The library stores various important data for use that you may need to know whil - @ - type: Message - ! - type: Error - & - type: Process +- ^ - type: Timer - $ - free - ^ - free --> diff --git a/mighty_logger/powerful_logger.py b/mighty_logger/powerful_logger.py index 66e06c7..254f4da 100644 --- a/mighty_logger/powerful_logger.py +++ b/mighty_logger/powerful_logger.py @@ -81,6 +81,7 @@ def __init__( self._progress_start: datetime | None = None self._progress_time: str = " " self._progress_interrupt = False + self._start_timer_value: datetime | None = None self.global_background = global_background self._color_scheme_init() if self._environment == LogEnvironments.CONSOLE: @@ -262,6 +263,27 @@ def _color_scheme_init(self) -> None: self._ColorScheme['TYPE_FAIL'] = [AnsiColor('FIREBRICK', "foreground"), AnsiColor('YELLOW', "foreground")] self._ColorScheme['FAIL_MESSAGE'] = [AnsiColor('DARKRED', "foreground"), AnsiColor('DARKYELLOW', "foreground")] self._ColorScheme['FAIL_BACKGROUND'] = ["", AnsiColor('DARKRED', "background")] + # START_TIMER colors + self._ColorScheme['START_TIMER_TIME'] = [AnsiColor('ORCHID', "foreground"), AnsiColor('LAVENDERBLUSH', "foreground")] + self._ColorScheme['START_TIMER_STATUS'] = [AnsiColor('ORANGE', "foreground"), AnsiColor('CHARTREUSE', "foreground")] + self._ColorScheme['START_TIMER_STATUS_MESSAGE'] = [AnsiColor('DARKORANGE', "foreground"), AnsiColor('LAWNGREEN', "foreground")] + self._ColorScheme['TYPE_START_TIMER'] = [AnsiColor('SEAGREEN', "foreground"), AnsiColor('PALEGREEN', "foreground")] + self._ColorScheme['START_TIMER_MESSAGE'] = [AnsiColor('FORESTGREEN', "foreground"), AnsiColor('LIGHTGREEN', "foreground")] + self._ColorScheme['START_TIMER_BACKGROUND'] = ["", AnsiColor('FORESTGREEN', "background")] + # TIMER_MARK colors + self._ColorScheme['TIMER_MARK_TIME'] = [AnsiColor('ORCHID', "foreground"), AnsiColor('DARKMAGENTA', "foreground")] + self._ColorScheme['TIMER_MARK_STATUS'] = [AnsiColor('ORANGE', "foreground"), AnsiColor('DARKRED', "foreground")] + self._ColorScheme['TIMER_MARK_STATUS_MESSAGE'] = [AnsiColor('DARKORANGE', "foreground"), AnsiColor('MAROON', "foreground")] + self._ColorScheme['TYPE_TIMER_MARK'] = [AnsiColor('KHAKI', "foreground"), AnsiColor('SIENNA', "foreground")] + self._ColorScheme['TIMER_MARK_MESSAGE'] = [AnsiColor('DARKKHAKI', "foreground"), AnsiColor('SADDLEBROWN', "foreground")] + self._ColorScheme['TIMER_MARK_BACKGROUND'] = ["", AnsiColor('DARKKHAKI', "background")] + # STOP_TIMER colors + self._ColorScheme['STOP_TIMER_TIME'] = [AnsiColor('ORCHID', "foreground"), AnsiColor('PURPLE', "foreground")] + self._ColorScheme['STOP_TIMER_STATUS'] = [AnsiColor('ORANGE', "foreground"), AnsiColor('DARKRED', "foreground")] + self._ColorScheme['STOP_TIMER_STATUS_MESSAGE'] = [AnsiColor('DARKORANGE', "foreground"), AnsiColor('MAROON', "foreground")] + self._ColorScheme['TYPE_STOP_TIMER'] = [AnsiColor('LIGHTSKYBLUE', "foreground"), AnsiColor('NAVY', "foreground")] + self._ColorScheme['STOP_TIMER_MESSAGE'] = [AnsiColor('SKYBLUE', "foreground"), AnsiColor('MIDNIGHTBLUE', "foreground")] + self._ColorScheme['STOP_TIMER_BACKGROUND'] = ["", AnsiColor('SKYBLUE', "background")] case LogEnvironments.HTML: self._ColorScheme['INITIAL_COLOR'] = [HexColor('GOLD'), HexColor('INDIGO')] self._ColorScheme['INITIAL_BACKGROUND'] = ["", HexColor('GOLD')] @@ -412,6 +434,27 @@ def _color_scheme_init(self) -> None: self._ColorScheme['TYPE_FAIL'] = [HexColor('FIREBRICK'), HexColor('YELLOW')] self._ColorScheme['FAIL_MESSAGE'] = [HexColor('DARKRED'), HexColor('DARKYELLOW')] self._ColorScheme['FAIL_BACKGROUND'] = ["", HexColor('DARKRED')] + # START_TIMER colors + self._ColorScheme['START_TIMER_TIME'] = [HexColor('ORCHID'), HexColor('LAVENDERBLUSH')] + self._ColorScheme['START_TIMER_STATUS'] = [HexColor('ORANGE'), HexColor('CHARTREUSE')] + self._ColorScheme['START_TIMER_STATUS_MESSAGE'] = [HexColor('DARKORANGE'), HexColor('LAWNGREEN')] + self._ColorScheme['TYPE_START_TIMER'] = [HexColor('SEAGREEN'), HexColor('PALEGREEN')] + self._ColorScheme['START_TIMER_MESSAGE'] = [HexColor('FORESTGREEN'), HexColor('LIGHTGREEN')] + self._ColorScheme['START_TIMER_BACKGROUND'] = ["", HexColor('FORESTGREEN')] + # TIMER_MARK colors + self._ColorScheme['TIMER_MARK_TIME'] = [HexColor('ORCHID'), HexColor('DARKMAGENTA')] + self._ColorScheme['TIMER_MARK_STATUS'] = [HexColor('ORANGE'), HexColor('DARKRED')] + self._ColorScheme['TIMER_MARK_STATUS_MESSAGE'] = [HexColor('DARKORANGE'), HexColor('MAROON')] + self._ColorScheme['TYPE_TIMER_MARK'] = [HexColor('KHAKI'), HexColor('SIENNA')] + self._ColorScheme['TIMER_MARK_MESSAGE'] = [HexColor('DARKKHAKI'), HexColor('SADDLEBROWN')] + self._ColorScheme['TIMER_MARK_BACKGROUND'] = ["", HexColor('DARKKHAKI')] + # STOP_TIMER colors + self._ColorScheme['STOP_TIMER_TIME'] = [HexColor('ORCHID'), HexColor('PURPLE')] + self._ColorScheme['STOP_TIMER_STATUS'] = [HexColor('ORANGE'), HexColor('DARKRED')] + self._ColorScheme['STOP_TIMER_STATUS_MESSAGE'] = [HexColor('DARKORANGE'), HexColor('MAROON')] + self._ColorScheme['TYPE_STOP_TIMER'] = [HexColor('LIGHTSKYBLUE'), HexColor('NAVY')] + self._ColorScheme['STOP_TIMER_MESSAGE'] = [HexColor('SKYBLUE'), HexColor('MIDNIGHTBLUE')] + self._ColorScheme['STOP_TIMER_BACKGROUND'] = ["", HexColor('SKYBLUE')] def _initial_log(self) -> None: """ @@ -484,6 +527,12 @@ def buffer(self) -> TextBufferType: #todo v0.7.1 сделать конвертер из Console в HTML и наоборот + # ######################################################################################## # + # # + # Entering to Logger # + # # + # ######################################################################################## # + def empty( self, *, @@ -1004,6 +1053,12 @@ def unresolved( if self._environment == LogEnvironments.CONSOLE: self._buffer.update_console() + # ######################################################################################## # + # # + # Entering to Processes # + # # + # ######################################################################################## # + def start_indefinite_process( self, *, @@ -1032,7 +1087,7 @@ def start_indefinite_process( self._progress_start = datetime.now() progress_stop = datetime.now() - self._progress_time = str(progress_stop - self._progress_start).split(".")[0] + " " + self._progress_time = "&" + str(progress_stop - self._progress_start).split(".")[0] func = getattr(self, "_initiation", None) args = {} if status_message != StatusMessageType("..."): @@ -1121,7 +1176,7 @@ def start_definite_process( self._progress_start = datetime.now() progress_stop = datetime.now() - self._progress_time = str(progress_stop - self._progress_start).split(".")[0] + " " + self._progress_time = "&" + str(progress_stop - self._progress_start).split(".")[0] func = getattr(self, "_initiation", None) args = {} if status_message != StatusMessageType("..."): @@ -1229,7 +1284,7 @@ def note_process( last = self._buffer.pop() progress_stop = datetime.now() - self._progress_time = str(progress_stop - self._progress_start).split(".")[0] + " " + self._progress_time = "&" + str(progress_stop - self._progress_start).split(".")[0] func = getattr(self, entry_type, None) args = {} if status_message != StatusMessageType("..."): @@ -1270,7 +1325,7 @@ def stop_process( self._buffer.remove() progress_stop = datetime.now() - self._progress_time = str(progress_stop - self._progress_start).split(".")[0] + " " + self._progress_time = "&" + str(progress_stop - self._progress_start).split(".")[0] func = getattr(self, "_success", None) if self._progress_rise == 100 else getattr(self, "_fail", None) args = {} if status_message != StatusMessageType("..."): @@ -1455,3 +1510,126 @@ def _fail( ) if self._environment == LogEnvironments.CONSOLE: self._buffer.update_console() + + # ######################################################################################## # + # # + # Entering to Timer # + # # + # ######################################################################################## # + + def start_timer( + self, + *, + status_message: StatusMessageType = StatusMessageType("..."), + message_text: str = "...", + local_background: bool = True, + local_settings: dict = None + ) -> None: + """ + ... + + :param status_message: Log entry status message + :param message_text: Log entry message + :param local_background: Display entry with background? + :param local_settings: Dictionary of local entering settings + """ + self._start_timer_value = datetime.now() + stop_timer_value = datetime.now() + self._progress_time = "^" + str(stop_timer_value - self._start_timer_value).split(".")[0] + + if local_settings is None: + local_settings = {} + if not 'italic' in local_settings: + local_settings["italic"] = True + self._buffer << self._assemble_entry( + [ + self._ColorScheme['START_TIMER_TIME'][local_background], + self._ColorScheme['START_TIMER_STATUS'][local_background], + self._ColorScheme['START_TIMER_STATUS_MESSAGE'][local_background], + self._ColorScheme['TYPE_START_TIMER'][local_background], + self._ColorScheme['START_TIMER_MESSAGE'][local_background], + self._ColorScheme['START_TIMER_BACKGROUND'][local_background], + ], self._progress_time, self._icon_set.start_timer, status_message.current_status_message, "^START TIMER", message_text, self._environment, local_settings + ) + if self._environment == LogEnvironments.CONSOLE: + self._buffer.update_console() + + self._progress_time = " " + + def timer_mark( + self, + *, + status_message: StatusMessageType = StatusMessageType("..."), + message_text: str = "...", + local_background: bool = True, + local_settings: dict = None + ) -> None: + """ + ... + + :param status_message: Log entry status message + :param message_text: Log entry message + :param local_background: Display entry with background? + :param local_settings: Dictionary of local entering settings + """ + stop_timer_value = datetime.now() + self._progress_time = "^" + str(stop_timer_value - self._start_timer_value).split(".")[0] + + if local_settings is None: + local_settings = {} + if not 'italic' in local_settings: + local_settings["italic"] = True + self._buffer << self._assemble_entry( + [ + self._ColorScheme['TIMER_MARK_TIME'][local_background], + self._ColorScheme['TIMER_MARK_STATUS'][local_background], + self._ColorScheme['TIMER_MARK_STATUS_MESSAGE'][local_background], + self._ColorScheme['TYPE_TIMER_MARK'][local_background], + self._ColorScheme['TIMER_MARK_MESSAGE'][local_background], + self._ColorScheme['TIMER_MARK_BACKGROUND'][local_background], + ], self._progress_time, self._icon_set.timer_mark, status_message.current_status_message, "^TIMER MARK", message_text, self._environment, local_settings + ) + if self._environment == LogEnvironments.CONSOLE: + self._buffer.update_console() + + self._progress_time = " " + + def stop_timer( + self, + *, + status_message: StatusMessageType = StatusMessageType("..."), + message_text: str = "...", + local_background: bool = True, + local_settings: dict = None + ) -> None: + """ + ... + + :param status_message: Log entry status message + :param message_text: Log entry message + :param local_background: Display entry with background? + :param local_settings: Dictionary of local entering settings + """ + stop_timer_value = datetime.now() + self._progress_time = "^" + str(stop_timer_value - self._start_timer_value).split(".")[0] + + + if local_settings is None: + local_settings = {} + if not 'italic' in local_settings: + local_settings["italic"] = True + self._buffer << self._assemble_entry( + [ + self._ColorScheme['STOP_TIMER_TIME'][local_background], + self._ColorScheme['STOP_TIMER_STATUS'][local_background], + self._ColorScheme['STOP_TIMER_STATUS_MESSAGE'][local_background], + self._ColorScheme['TYPE_STOP_TIMER'][local_background], + self._ColorScheme['STOP_TIMER_MESSAGE'][local_background], + self._ColorScheme['STOP_TIMER_BACKGROUND'][local_background], + ], self._progress_time, self._icon_set.stop_timer, status_message.current_status_message, "^STOP TIMER", message_text, self._environment, local_settings + ) + if self._environment == LogEnvironments.CONSOLE: + self._buffer.update_console() + + self._start_timer_value = None + self._progress_time = " " diff --git a/mighty_logger/src/log_enums.py b/mighty_logger/src/log_enums.py index 6f6b1a0..9dc2f6a 100644 --- a/mighty_logger/src/log_enums.py +++ b/mighty_logger/src/log_enums.py @@ -46,3 +46,6 @@ class TypesEntries: UNRESOLVED = 'unresolved' ACHIEVEMENT = '_achievement' MILESTONE = '_milestone' + START_TIMER = 'start_timer' + TIMER_MARK = 'timer_mark' + STOP_TIMER = 'stop_timer' diff --git a/mighty_logger/text/icon_set.py b/mighty_logger/text/icon_set.py index 8c62e7a..4fb6f19 100644 --- a/mighty_logger/text/icon_set.py +++ b/mighty_logger/text/icon_set.py @@ -41,6 +41,9 @@ class IconSetType: milestone = '' success = '' fail = '' + start_timer = '' + timer_mark = '' + stop_timer = '' class EmptyIconSet(IconSetType): ... @@ -70,6 +73,9 @@ class IconSet1(IconSetType): milestone = '🔖' success = '✔️' fail = '❌' + start_timer = '⏰' + timer_mark = '⌚' + stop_timer = '⏲️' class IconSet2(IconSetType): """ @@ -96,6 +102,9 @@ class IconSet2(IconSetType): milestone = '🔖' success = '🎉' fail = '🚫' + start_timer = '🕑' + timer_mark = '🕕' + stop_timer = '🕙' class IconSet3(IconSetType): """ @@ -122,6 +131,9 @@ class IconSet3(IconSetType): milestone = '🎯' success = '👍' fail = '👎' + start_timer = '🟩' + timer_mark = '🟨' + stop_timer = '🟪' class IconSet4(IconSetType): """ @@ -148,3 +160,6 @@ class IconSet4(IconSetType): milestone = '🗺️' success = '✅' fail = '❎' + start_timer = '⏳' + timer_mark = '⏱️' + stop_timer = '⌛' diff --git a/test/test_console.py b/test/test_console.py index 8fe832b..e32e2d0 100644 --- a/test/test_console.py +++ b/test/test_console.py @@ -8,6 +8,7 @@ logger = Logger(program_name="Installer", console_width=115, status_message_global_entry=False) logger.message(message_text="Program installation started") + logger.start_timer(message_text="Timer started") sleep(1) logger.start_indefinite_process(animation=IndefiniteAnimations.Star, message_text="File upload") @@ -18,6 +19,7 @@ logger.stop_process(message_text="Files unzipped") logger.warning(message_text="Newer version found") + logger.timer_mark(message_text="Timer mark", local_background=False) sleep(1) logger.start_definite_process(progress_bar=DefiniteAnimations.Dots, message_text="Installing files") @@ -44,6 +46,7 @@ logger.note_process(entry_type=TypesEntries.MILESTONE, message_text="Files prepared") sleep(3.7) logger.progress_rise(76) + logger.note_process(entry_type=TypesEntries.TIMER_MARK, message_text="Timer mark") sleep(1.5) logger.progress_rise(77) sleep(1.4) @@ -77,4 +80,6 @@ sleep(1.3) logger.stop_process(message_text="Program installed") + logger.stop_timer(message_text="Timer completed") + logger.buffer().save("log.txt") diff --git a/test/test_html.py b/test/test_html.py index 1d556ed..6b94408 100644 --- a/test/test_html.py +++ b/test/test_html.py @@ -2,14 +2,16 @@ from mighty_logger import Logger from mighty_logger.src import LogEnvironments, TypesEntries +from mighty_logger.text import IndefiniteAnimations, DefiniteAnimations if __name__ == "__main__": logger = Logger(program_name="Test", log_environment=LogEnvironments.HTML, status_message_global_entry=False) logger.message(message_text="Program installation started") + logger.start_timer(message_text="Timer started") sleep(1) - logger.start_indefinite_process(message_text="File upload") + logger.start_indefinite_process(animation=IndefiniteAnimations.Star, message_text="File upload") sleep(2) logger.note_process(entry_type=TypesEntries.ACHIEVEMENT, message_text="Files downloaded") sleep(3) @@ -17,9 +19,10 @@ logger.stop_process(message_text="Files unzipped") logger.warning(message_text="Newer version found") + logger.timer_mark(message_text="Timer mark", local_background=False) sleep(1) - logger.start_definite_process(message_text="Installing files") + logger.start_definite_process(progress_bar=DefiniteAnimations.Dots, message_text="Installing files") sleep(0.6) logger.progress_rise(3) sleep(0.4) @@ -43,6 +46,7 @@ logger.note_process(entry_type=TypesEntries.MILESTONE, message_text="Files prepared") sleep(3.7) logger.progress_rise(76) + logger.note_process(entry_type=TypesEntries.TIMER_MARK, message_text="Timer mark") sleep(1.5) logger.progress_rise(77) sleep(1.4) @@ -76,4 +80,6 @@ sleep(1.3) logger.stop_process(message_text="Program installed") + logger.stop_timer(message_text="Timer completed") + logger.buffer().save("log.html")