Commit 3209e2b3 authored by rgaudin's avatar rgaudin
Browse files

Prevent logger progress from raising a ZeroDivisionError (no dowloads for instance)

parent 79422896
......@@ -158,7 +158,7 @@ def write_image_on_card(image_fd, device_fd, logger):
# only update logger every 4 steps (100MiB)
if step % 4 == 0:
logger.progress(step / steps)
logger.progress(step, steps)
logger.std(
"Copied {copied} of {total} ({pc:.2f}%)"
.format(copied=human_readable_size(step * buffer_size),
......
......@@ -160,7 +160,7 @@ def run_installation(name, timezone, language, wifi_pwd, admin_account, kalite,
.format(p=dl_content['name'],
s=human_readable_size(rf.downloaded_size)))
retrieved += dl_content['archive_size']
logger.progress(retrieved / archives_total_size)
logger.progress(retrieved, archives_total_size)
# check edupi resources compliance
if edupi_resources:
......@@ -257,7 +257,7 @@ def run_installation(name, timezone, language, wifi_pwd, admin_account, kalite,
# size of expanded files for this category (for progress)
processed += sum([c['expanded_size']
for c in content_dl_cb(**cb_kwargs)])
logger.progress(processed / expanded_total_size)
logger.progress(processed, expanded_total_size)
except Exception as exp:
try:
unmount_data_partition(mount_point, device, logger)
......
......@@ -86,9 +86,18 @@ class ProgressHelper(object):
self.stage_started_on = datetime.datetime.now()
self.update()
def progress(self, percentage=None):
def progress(self, numerator, denominator=1):
''' record progress for the current stage '''
assert percentage is None or (percentage >= 0 and percentage <= 1)
if numerator is not None:
try:
percentage = numerator / denominator
assert percentage >= 0 and percentage <= 1
except AssertionError:
percentage = None
except ZeroDivisionError:
percentage = 1
else:
percentage = None
self.stage_progress = percentage
self.update()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment