Skip to content

Commit

Permalink
Prints number of minutes to only 1 decimal place
Browse files Browse the repository at this point in the history
Prints the backup/restore/image mount durations as the number of minutes to
only 1 decimal place, rather than the much larger default print precision of
floating point numbers in Python.
  • Loading branch information
shasheene committed Dec 11, 2020
1 parent 104f453 commit 5ba24a0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def update_backup_progress_bar(self, fraction):

def completed_backup(self, succeeded, message):
backup_timeend = datetime.now()
duration_minutes = (backup_timeend - self.backup_timestart).total_seconds() / 60.0
duration_minutes = Utility.get_human_readable_minutes_seconds((backup_timeend - self.backup_timestart).total_seconds())
duration_message = _("Operation took {num_minutes} minutes.").format(num_minutes=duration_minutes)
self.main_statusbar.remove_all(self.main_statusbar.get_context_id("backup"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------
import collections
import math
import os
import queue
import shutil
Expand Down Expand Up @@ -616,12 +615,9 @@ def _do_mount_command(self, please_wait_popup, callback, image, partition_key, d
return

backup_timeend = datetime.now()
duration_minutes, duration_seconds = divmod((backup_timeend - backup_timestart).total_seconds(), 60)
frac, whole = math.modf(duration_minutes / 60)
# 1 decimal place (55.3 minutes)
human_readable_minutes_seconds = "{:.1f}".format(duration_minutes + frac)
duration_minutes = Utility.get_human_readable_minutes_seconds((backup_timeend - backup_timestart).total_seconds())
duration_message = _("Mounting partition took {num_minutes} minutes.").format(
num_minutes=human_readable_minutes_seconds)
num_minutes=duration_minutes)
GLib.idle_add(callback, True, duration_message)
GLib.idle_add(please_wait_popup.destroy)
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ def update_progress_bar(self, fraction):
# Expected to run on GTK event thread
def completed_restore(self, succeeded, message):
restore_timeend = datetime.now()
duration_minutes = (restore_timeend - self.restore_timestart).total_seconds() / 60.0
duration_minutes = Utility.get_human_readable_minutes_seconds((restore_timeend - self.restore_timestart).total_seconds())

self.main_statusbar.remove_all(self.main_statusbar.get_context_id("restore"))
self.restore_in_progress = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------
import gettext
import math
import os
import pwd
import re
Expand Down Expand Up @@ -418,6 +419,13 @@ def print_cli_friendly(message, cmd_list_list):
print(flat_command_string)
return flat_command_string

@staticmethod
def get_human_readable_minutes_seconds(seconds):
duration_minutes, duration_seconds = divmod(seconds, 60)
frac, whole = math.modf(duration_minutes / 60)
# 1 decimal place (55.3 minutes)
return "{:.1f}".format(duration_minutes + frac)

@staticmethod
def run(short_description, cmd_list, use_c_locale, output_filepath=None, logger=None):
if use_c_locale:
Expand Down

0 comments on commit 5ba24a0

Please sign in to comment.