borgend/ui.py

changeset 97
96d5adbe0205
parent 89
51cc2e25af38
child 98
9052e427ea39
equal deleted inserted replaced
96:de8ac6c470d8 97:96d5adbe0205
76 return '{0:.2f}MB'.format(B/MB) 76 return '{0:.2f}MB'.format(B/MB)
77 elif GB <= B < TB: 77 elif GB <= B < TB:
78 return '{0:.2f}GB'.format(B/GB) 78 return '{0:.2f}GB'.format(B/GB)
79 elif TB <= B: 79 elif TB <= B:
80 return '{0:.2f}TB'.format(B/TB) 80 return '{0:.2f}TB'.format(B/TB)
81
82
83 def progress_percentage(done, total, d):
84 progress=''
85 try:
86 percentage = 100*float(done)/float(total)
87 progress=': %d%%' % int(round(percentage))
88 if 'operation_no' in d:
89 progress=':#%d%s' % (d['operation_no'], progress)
90 except:
91 pass
92 return progress
93
94 def progress_parts(done, total, d):
95 progress=''
96 try:
97 progress=': %d/%d' % (int(done), int(total))
98 if 'operation_no' in d:
99 progress=':#%d%s' % (d['operation_no'], progress)
100 except:
101 pass
102 return progress
103
81 104
82 def make_title(status): 105 def make_title(status):
83 def add_info(info, new): 106 def add_info(info, new):
84 if info: 107 if info:
85 return "%s; %s" % (info, new) 108 return "%s; %s" % (info, new)
123 146
124 this_info='' 147 this_info=''
125 if 'reason' in status.detail: 148 if 'reason' in status.detail:
126 this_info=status.detail['reason'] + ' ' 149 this_info=status.detail['reason'] + ' '
127 150
128 when_how_sched= "%s%s %s" % (this_info, status.operation, whenstr) 151 when_how_sched= "%s%s %s" % (this_info, status.type, whenstr)
129 152
130 info=add_info(info, when_how_sched) 153 info=add_info(info, when_how_sched)
131 154
132 elif status.state==backup.State.QUEUED: 155 elif status.state==backup.State.QUEUED:
133 info=add_info(info, "queued") 156 info=add_info(info, "queued %s" % status.type)
134 elif status.state==backup.State.ACTIVE: 157 elif status.state==backup.State.ACTIVE:
135 # Operation running 158 # Operation running
136 progress='' 159 progress=''
137 d=status.detail 160 d=status.detail
138 if 'progress_current' in d and 'progress_total' in d: 161 if 'progress_current' in d and 'progress_total' in d:
139 percentage = 100*float(d['progress_current'])/float(d['progress_total']) 162 progress=progress_percentage(d['progress_current'],
140 progress=': %d%%' % int(round(percentage)) 163 d['progress_total'], d)
141 if 'operation_no' in d: 164 elif ('progress_current_secondary' in d and
142 progress='/#%d%s' % (d['operation_no'], progress) 165 'progress_total_secondary' in d):
166 progress=progress_parts(d['progress_current_secondary'],
167 d['progress_total_secondary'], d)
143 elif 'original_size' in d and 'deduplicated_size' in d: 168 elif 'original_size' in d and 'deduplicated_size' in d:
144 progress=' %s→%s' % (humanbytes(d['original_size']), 169 progress=' %s→%s' % (humanbytes(d['original_size']),
145 humanbytes(d['deduplicated_size'])) 170 humanbytes(d['deduplicated_size']))
146 171
147 howrunning = "running %s%s" % (status.operation, progress) 172 howrunning = "running %s%s" % (status.type, progress)
148 173
149 info=add_info(info, howrunning) 174 info=add_info(info, howrunning)
150 else: 175 else:
151 pass 176 pass
152 177

mercurial