text: from __future__ import print_function
  import sys
  import re
  
  class ProgressBar(object):
      DEFAULT = 'Progress: %(bar)s %(percent)3d%%'
      FULL = '%(bar)s %(current)d/%(total)d (%(percent)3d%%)'
  
      def __init__(self, total, width=40, fmt=FULL, symbol='=',
                   output=sys.stderr):
          assert len(symbol) == 1
  
          self.total = total
          self.width = width
          self.symbol = symbol
          self.output = output
          self.fmt = re.sub(r'(?P<name>%\(.+?\))d',
              r'\g<name>%dd' % len(str(total)), fmt)
  
          self.current = 0
  
      def __call__(self):
          percent = self.current / float(self.total)
          size = int(self.width * percent)
          bar = '[' + self.symbol * size + ' ' * (self.width - size) + ']'
  
          args = {
              'total': self.total,
              'bar': bar,
              'current': self.current,
              'percent': percent * 100
          }
          print('\r' + self.fmt % args, file=self.output, end='')
          
      def update(self):
          self.current += 1
          self()
          
          if(self.current == self.total):
              self.current = self.total
              print('\n')