def update(self, increment=1):
self.duration = datetime.timedelta(seconds=time.monotonic() - self.started_at)
self.current += increment
try:
percent = 100 * (self.current / float(self.total))
filled_length = int(round(self.columns * self.current / float(self.total)))
except ZeroDivisionError:
percent = 0
filled_length = 0
if self.quiet:
return
if self.log:
logger = logging.getLogger(__name__)
logger.info("{s.prelude} {percent:.1f}% = {s.current}/{s.total} {s.suffix} ({s.duration} elapsed)".format(s=self, percent=percent))
return
bar = '=' * filled_length + '-' * (self.columns - filled_length)
out = "\r{s.prelude} [{bar}] {percent:.1f}% {s.current}/{s.total} {s.suffix} ({duration} elapsed)".format(bar=bar, s=self, percent=percent, duration=humanize.naturaldelta(self.duration))
self.longest_line = max(self.longest_line, len(out))
sys.stdout.write(out)
sys.stdout.flush()
评论列表
文章目录