~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Martin Pool
  • Date: 2009-03-12 06:44:49 UTC
  • mto: This revision was merged to the branch mainline in revision 4144.
  • Revision ID: mbp@sourcefrog.net-20090312064449-mrw7183pcdgospc2
Fix bug in showing task progress and add a test

Show diffs side-by-side

added added

removed removed

Lines of Context:
130
130
        self._last_repaint = 0
131
131
        # time we last got information about transport activity
132
132
        self._transport_update_time = 0
133
 
        self._task_fraction = None
134
133
        self._last_task = None
135
134
        self._total_byte_count = 0
136
135
        self._bytes_since_update = 0
154
153
            # to have what looks like an incomplete progress bar.
155
154
            spin_str =  r'/-\|'[self._spin_pos % 4]
156
155
            self._spin_pos += 1
157
 
            f = self._task_fraction or 0
158
156
            cols = 20
159
157
            # number of markers highlighted in bar
160
 
            markers = int(round(float(cols) * f)) - 1
 
158
            completion_fraction = self._last_task._overall_completion_fraction()
 
159
            markers = int(round(float(cols) * completion_fraction)) - 1
161
160
            bar_str = '[' + ('#' * markers + spin_str).ljust(cols) + '] '
162
161
            return bar_str
163
162
        elif self._last_task.show_spinner:
177
176
            s = ' %d' % (task.current_cnt)
178
177
        else:
179
178
            s = ''
180
 
        self._task_fraction = task._overall_completion_fraction()
181
179
        # compose all the parent messages
182
180
        t = task
183
181
        m = task.msg
204
202
        self._have_output = True
205
203
 
206
204
    def show_progress(self, task):
 
205
        """Called by the task object when it has changed.
 
206
        
 
207
        :param task: The top task object; its parents are also included 
 
208
            by following links.
 
209
        """
207
210
        self._last_task = task
 
211
        # XXX: Possibly should force update if something important has changed
 
212
        # (like a new task) even if the last update was recent?
208
213
        now = time.time()
209
214
        if now < self._last_repaint + 0.1:
210
215
            return
211
 
        if now > self._transport_update_time + 5:
 
216
        if now > self._transport_update_time + 10:
212
217
            # no recent activity; expire it
213
218
            self._last_transport_msg = ''
214
219
        self._last_repaint = now