From bd1390eb49245caf184004a42dc236bd92923b72 Mon Sep 17 00:00:00 2001 From: Tim-Philipp Müller Date: Fri, 23 Feb 2024 17:55:40 +0000 Subject: cerbero: add --clocktime argument to print absolute time as well Part-of: --- cerbero/main.py | 8 ++++++++ cerbero/utils/messages.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/cerbero/main.py b/cerbero/main.py index d72151d4..f96d7162 100644 --- a/cerbero/main.py +++ b/cerbero/main.py @@ -71,6 +71,8 @@ class Main(object): """Initialize logging""" if self.args.timestamps: m.START_TIME = time.monotonic() + if self.args.clocktime: + m.PRINT_CLOCK_TIME = True logging.getLogger().setLevel(logging.INFO) logging.getLogger().addHandler(logging.StreamHandler()) @@ -92,6 +94,12 @@ class Main(object): default=False, help=_('Print timestamps with every message printed'), ) + self.parser.add_argument( + '--clocktime', + action='store_true', + default=False, + help=_('Print absolute clock times with every message printed'), + ) self.parser.add_argument( '--list-variants', action='store_true', default=False, help=_('List available variants') ) diff --git a/cerbero/utils/messages.py b/cerbero/utils/messages.py index 45d863fc..5b825d22 100644 --- a/cerbero/utils/messages.py +++ b/cerbero/utils/messages.py @@ -36,6 +36,7 @@ STEP_TPL = '[(%s/%s @ %d%%) %s -> %s]' START_TIME = None SHELL_CLEAR_LINE = '\r\033[K' SHELL_MOVE_UP = '\033[F' +PRINT_CLOCK_TIME = False # Enable support fot VT-100 escapes in Windows 10 @@ -98,9 +99,16 @@ STDOUT = StdoutManager() def prepend_time(end=' '): + global PRINT_CLOCK_TIME global START_TIME s = '' + if PRINT_CLOCK_TIME: + s += str(datetime.datetime.now().strftime('%H:%M:%S')) + if START_TIME is None: + s += end if START_TIME is not None: + if PRINT_CLOCK_TIME: + s += ' | ' s += str(datetime.timedelta(microseconds=int((time.monotonic() - START_TIME) * 1e6))) s += end return s -- cgit v1.2.3