Skip to content

Commit

Permalink
show time left in progress bar and refresh progress bar every second (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
lguohan authored May 9, 2017
1 parent 452df11 commit e188b5e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions sonic_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@
ABOOT_BOOT_CONFIG = '/boot-config'

def reporthook(count, block_size, total_size):
global start_time
global start_time, last_time
cur_time = int(time.time())
if count == 0:
start_time = time.time()
start_time = cur_time
last_time = cur_time
return

duration = time.time() - start_time
if cur_time == last_time:
return

last_time = cur_time

duration = cur_time - start_time
progress_size = int(count * block_size)
speed = int(progress_size / (1024 * duration))
percent = int(count * block_size * 100 / total_size)
sys.stdout.write("\r...%d%%, %d MB, %d KB/s, %d seconds passed" %
(percent, progress_size / (1024 * 1024), speed, duration))
time_left = (total_size - progress_size) / speed / 1024
sys.stdout.write("\r...%d%%, %d MB, %d KB/s, %d seconds left... " %
(percent, progress_size / (1024 * 1024), speed, time_left))
sys.stdout.flush()

def get_image_type():
Expand Down

0 comments on commit e188b5e

Please sign in to comment.