Source code for s3workers.progress

import sys
import threading

# TODO: http://click.pocoo.org/5/utils/#showing-progress-bars


[docs]class SimpleProgress(object): def __init__(self): self._lock = threading.RLock()
[docs] def report(self, msg, *args): with self._lock: sys.stdout.write("\r" + (msg % args)) sys.stdout.flush()
[docs] def write(self, msg, *args): with self._lock: sys.stdout.write("\r" + (msg % args) + "\n") sys.stdout.flush()
[docs] def finish(self): sys.stdout.write("\n") sys.stdout.flush()
[docs]class S3KeyProgress(SimpleProgress): def __init__(self): super(self.__class__, self).__init__() self._counter = 0 self._selected = 0
[docs] def report(self, final=False): with self._lock: if not final: self._counter += 1 super(self.__class__, self).report('Selected %d of %d keys', self._selected, self._counter)
[docs] def write(self, msg, *args): with self._lock: self._selected += 1 super(self.__class__, self).write(msg, *args)
[docs] def finish(self): self.report(True) super(self.__class__, self).finish()