def format_message(self, current, total):
"""Creates message to be written on console"""
if total:
ratio = float(current) / total
filled_bricks = int((ratio + 0.05) * self.progress_num_bricks)
num_digits = int(math.log10(total))
else:
ratio = 1.0
filled_bricks = self.progress_num_bricks
num_digits = 1
last_step = total == current
if last_step:
eta = datetime.timedelta(0)
elif ratio and self.start_datetime:
total_seconds_ = total_seconds(
datetime.datetime.now() - self.start_datetime
)
eta = datetime.timedelta(
seconds=total_seconds_ / ratio - total_seconds_
)
else:
eta = '?'
screw = " " if last_step else next(self.screw_cycle)
return self.line_template.format(
bricks=self.progress_brick * filled_bricks,
num_bricks=self.progress_num_bricks,
ratio=ratio,
current=current,
total=total,
num_digits=num_digits,
eta=eta,
screw=screw
)
评论列表
文章目录