| 20 ERRORS: 'B?' |
20 ERRORS: 'B?' |
| 21 } |
21 } |
| 22 |
22 |
| 23 def combine_state(state1, state2): |
23 def combine_state(state1, state2): |
| 24 return max(state1, state2) |
24 return max(state1, state2) |
| |
25 |
| |
26 # Based on code snatched from |
| |
27 # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778 |
| |
28 def humanbytes(B): |
| |
29 'Return the given bytes as a human friendly KB, MB, GB, or TB string' |
| |
30 B = float(B) |
| |
31 KB = float(1024) |
| |
32 MB = float(KB ** 2) # 1,048,576 |
| |
33 GB = float(KB ** 3) # 1,073,741,824 |
| |
34 TB = float(KB ** 4) # 1,099,511,627,776 |
| |
35 |
| |
36 if B < KB: |
| |
37 return '{0} {1}B'.format(B) |
| |
38 elif KB <= B < MB: |
| |
39 return '{0:.2f}KB'.format(B/KB) |
| |
40 elif MB <= B < GB: |
| |
41 return '{0:.2f}MB'.format(B/MB) |
| |
42 elif GB <= B < TB: |
| |
43 return '{0:.2f}GB'.format(B/GB) |
| |
44 elif TB <= B: |
| |
45 return '{0:.2f}TB'.format(B/TB) |
| 25 |
46 |
| 26 def make_title(status): |
47 def make_title(status): |
| 27 state=INACTIVE |
48 state=INACTIVE |
| 28 |
49 |
| 29 if status['type']=='scheduled': |
50 if status['type']=='scheduled': |
| 51 title="%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr) |
72 title="%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr) |
| 52 elif status['type']=='current': |
73 elif status['type']=='current': |
| 53 # Operation running |
74 # Operation running |
| 54 progress='' |
75 progress='' |
| 55 if 'progress_current' in status and 'progress_total' in status: |
76 if 'progress_current' in status and 'progress_total' in status: |
| 56 progress='%d%%' % (status.progress_current/status.progress_total) |
77 progress=' %d%%' % (status.progress_current/status.progress_total) |
| |
78 elif 'original_size' in status and 'deduplicated_size' in status: |
| |
79 progress=' %s O %s D' % (humanbytes(status.original_size), |
| |
80 humanbytes(status.deduplicated_size)) |
| 57 title="%s (running: %s%s)" % (status['name'], status['operation'], progress) |
81 title="%s (running: %s%s)" % (status['name'], status['operation'], progress) |
| 58 state=ACTIVE |
82 state=ACTIVE |
| 59 else: # status['type']=='nothing': |
83 else: # status['type']=='nothing': |
| 60 # Should be unscheduled, nothing running |
84 # Should be unscheduled, nothing running |
| 61 title=status['name'] |
85 title=status['name'] |