Skip to content

Commit

Permalink
Added some suggestions from Scot.
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Braun committed Jul 22, 2019
1 parent a8056cc commit 9714fb0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,26 @@ def __init__(self, name, log_dir, tmp_dir=None, html_file=None, indent=0,
def update_done_time(self):
"""
Allows the ``top_dict['done_time']`` to be updated before
:func:`finalize` is called. This is especially useful for child
:func:`finalize` is called. This is especially useful for child
:class:`Logger` objects who might finish their commands before the
parent finalizes everything.
"""
self.top_dict['done_time'] = datetime.datetime.now()

def duration(self):
"""
Returns the duration from the beginning of the :class:`Logger` object's
creation until now.
Returns:
str: Duration in the format ``%Hh %Mm %Ss``.
"""
self.update_done_time()
dur = self.top_dict['done_time'] - self.top_dict['init_time']
dur_str = self.strfdelta(dur, "{hrs}h {min}m {sec}s")

return dur_str

def add_child(self, child_name):
"""
Creates and returns a 'child' :class:`Logger` object. This will be one
Expand Down Expand Up @@ -425,11 +439,7 @@ def finalize(self):
# ------------
if isinstance(log, Logger):
# Get the duration of this Logger's commands
if log.top_dict['init_time'] == log.top_dict['done_time']:
log.top_dict['done_time'] = datetime.datetime.now()
duration = log.top_dict['done_time'] -\
log.top_dict['init_time']
duration = self.strfdelta(duration, "{hrs}h {min}m {sec}s")
duration = self.duration()

# First print the header text.
html_str = (
Expand Down

0 comments on commit 9714fb0

Please sign in to comment.