86
86
self.ui_factory.progress_finished(self)
88
88
def make_sub_task(self):
89
return ProgressTask(parent_task=self, self.ui_factory)
89
return ProgressTask(self, self.ui_factory)
91
91
def _overall_completion_fraction(self, child_fraction=0.0):
92
92
"""Return fractional completion of this task and its parents
147
147
One instance of this is created and held by the UI, and fed updates when a
148
148
task wants to be painted.
150
Transports feed data to this through the ui_factory object.
151
153
def __init__(self, term_file):
156
158
self._width = osutils.terminal_width()
157
159
self._last_transport_msg = ''
158
160
self._spin_pos = 0
159
self._last_update = 0
161
# time we last repainted the screen
162
self._last_repaint = 0
163
# time we last got information about transport activity
160
164
self._transport_update_time = 0
161
165
self._task_fraction = None
162
166
self._last_task = None
167
self._total_byte_count = 0
168
self._bytes_since_update = 0
164
170
def _show_line(self, s):
165
171
n = self._width - 1
201
207
def _repaint(self):
203
if now < self._last_update + 0.1:
205
if now > self._transport_update_time + 5:
206
# no recent activity; expire it
207
self._last_transport_msg = ''
208
self._last_update = now
209
208
bar_string = self._render_bar()
210
209
if self._last_task:
211
210
task_msg = self._format_task(self._last_task)
224
223
def show_progress(self, task):
225
224
self._last_task = task
226
if now < self._last_repaint + 0.1:
228
if now > self._transport_update_time + 5:
229
# no recent activity; expire it
230
self._last_transport_msg = ''
231
self._last_repaint = now
228
def show_transport_activity(self, msg):
229
self._last_transport_msg = msg
230
self._transport_update_time = time.time()
234
def show_transport_activity(self, byte_count):
235
"""Called by transports as they do IO.
237
This may update a progress bar, spinner, or similar display.
238
By default it does nothing.
240
# XXX: Probably there should be a transport activity model, and that
241
# too should be seen by the progress view, rather than being poked in
243
self._total_byte_count += byte_count
244
self._bytes_since_update += byte_count
246
if self._transport_update_time is None:
247
self._transport_update_time = now
248
elif now >= (self._transport_update_time + 0.2):
249
# guard against clock stepping backwards, and don't update too
251
rate = self._bytes_since_update / (now - self._transport_update_time)
252
msg = ("%6dkB @ %4dkB/s" %
253
(self._total_byte_count>>10, int(rate)>>10,))
254
self._transport_update_time = now
255
self._last_repaint = now
256
self._bytes_since_update = 0
257
self._last_transport_msg = msg
234
261
class ProgressBarStack(object):