Commits

Anonymous committed b6918cd

add progressbar library

  • Participants
  • Parent commits f9f7ab9

Comments (0)

Files changed (1)

scripts/progressbar.py

+# Text progress bar library, like curl or scp.
+
+import sys
+
+class ProgressBar:
+    def __init__(self, label, limit):
+        self.label = label
+        self.limit = limit
+        self.cur = 0
+
+    def update(self, value):
+        self.cur = value
+        pct = int(100.0 * self.cur / self.limit)
+        barlen = int(50.0 * self.cur / self.limit) - 1
+        bar = '='*barlen + '>'
+        sys.stdout.write('\r%-12s %3d%% %-50s|'%(self.label, pct, bar))
+        sys.stdout.flush()
+
+    def finish(self):
+        self.update(self.limit)
+        sys.stdout.write('\n')
+
+if __name__ == '__main__':
+    from time import sleep
+    pb = ProgressBar('test', 12)
+    for i in range(12):
+        pb.update(i)
+        sleep(0.5)
+    pb.finish()