ui.py

changeset 19
f9ce2442f14f
parent 18
6d8ac70c5fb9
child 20
fdfbe5d7b677
--- a/ui.py	Sat Jan 20 23:07:53 2018 +0000
+++ b/ui.py	Sat Jan 20 23:19:16 2018 +0000
@@ -23,6 +23,27 @@
 def combine_state(state1, state2):
     return max(state1, state2)
 
+# Based on code snatched from
+# https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778
+def humanbytes(B):
+   'Return the given bytes as a human friendly KB, MB, GB, or TB string'
+   B = float(B)
+   KB = float(1024)
+   MB = float(KB ** 2) # 1,048,576
+   GB = float(KB ** 3) # 1,073,741,824
+   TB = float(KB ** 4) # 1,099,511,627,776
+
+   if B < KB:
+      return '{0} {1}B'.format(B)
+   elif KB <= B < MB:
+      return '{0:.2f}KB'.format(B/KB)
+   elif MB <= B < GB:
+      return '{0:.2f}MB'.format(B/MB)
+   elif GB <= B < TB:
+      return '{0:.2f}GB'.format(B/GB)
+   elif TB <= B:
+      return '{0:.2f}TB'.format(B/TB)
+
 def make_title(status):
     state=INACTIVE
 
@@ -53,7 +74,10 @@
         # Operation running
         progress=''
         if 'progress_current' in status and 'progress_total' in status:
-            progress='%d%%' % (status.progress_current/status.progress_total)
+            progress=' %d%%' % (status.progress_current/status.progress_total)
+        elif 'original_size' in status and 'deduplicated_size' in status:
+            progress=' %s O %s D' % (humanbytes(status.original_size),
+                                     humanbytes(status.deduplicated_size))
         title="%s (running: %s%s)" % (status['name'], status['operation'], progress)
         state=ACTIVE
     else: # status['type']=='nothing':

mercurial