/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Martin Pool
  • Date: 2008-12-16 04:26:43 UTC
  • mto: (3882.7.11 progress)
  • mto: This revision was merged to the branch mainline in revision 3940.
  • Revision ID: mbp@sourcefrog.net-20081216042643-lelt3haqjmedugq6
Move display of transport throughput into TextProgressView

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        self.ui_factory.progress_finished(self)
87
87
 
88
88
    def make_sub_task(self):
89
 
        return ProgressTask(parent_task=self, self.ui_factory)
 
89
        return ProgressTask(self, self.ui_factory)
90
90
 
91
91
    def _overall_completion_fraction(self, child_fraction=0.0):
92
92
        """Return fractional completion of this task and its parents
146
146
 
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.
 
149
 
 
150
    Transports feed data to this through the ui_factory object.
149
151
    """
150
152
 
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
163
169
 
164
170
    def _show_line(self, s):
165
171
        n = self._width - 1
199
205
        return m + s
200
206
 
201
207
    def _repaint(self):
202
 
        now = time.time()
203
 
        if now < self._last_update + 0.1:
204
 
            return
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)
223
222
 
224
223
    def show_progress(self, task):
225
224
        self._last_task = task
 
225
        now = time.time()
 
226
        if now < self._last_repaint + 0.1:
 
227
            return
 
228
        if now > self._transport_update_time + 5:
 
229
            # no recent activity; expire it
 
230
            self._last_transport_msg = ''
 
231
        self._last_repaint = now
226
232
        self._repaint()
227
233
 
228
 
    def show_transport_activity(self, msg):
229
 
        self._last_transport_msg = msg
230
 
        self._transport_update_time = time.time()
231
 
        self._repaint()
 
234
    def show_transport_activity(self, byte_count):
 
235
        """Called by transports as they do IO.
 
236
        
 
237
        This may update a progress bar, spinner, or similar display.
 
238
        By default it does nothing.
 
239
        """
 
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
 
242
        # here.
 
243
        self._total_byte_count += byte_count
 
244
        self._bytes_since_update += byte_count
 
245
        now = time.time()
 
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
 
250
            # often
 
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
 
258
            self._repaint()
232
259
 
233
260
 
234
261
class ProgressBarStack(object):