def _display_progress_bar(self, size_read):
self._totalread += size_read
if self._show_progress:
if self._totalsize:
percent = float(self._totalread) / float(self._totalsize)
# Output something like this: [==========> ] 49%
sys.stdout.write('\r[{0:<30}] {1:.0%}'.format(
'=' * int(decimal.Decimal(percent * 29).quantize(
decimal.Decimal('1'),
rounding=decimal.ROUND_HALF_UP)) + '>', percent
))
else:
sys.stdout.write(
'\r[%s] %d bytes' % (SPIN_CHARS[self._spin_index],
self._totalread))
self._spin_index += 1
if self._spin_index == len(SPIN_CHARS):
self._spin_index = 0
sys.stdout.flush()
评论列表
文章目录