/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: John Arbash Meinel
  • Date: 2006-09-20 14:51:03 UTC
  • mfrom: (0.8.23 version_info)
  • mto: This revision was merged to the branch mainline in revision 2028.
  • Revision ID: john@arbash-meinel.com-20060920145103-02725c6d6c886040
[merge] version-info plugin, and cleanup for layout in bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005 Aaron Bentley <aaron.bentley@utoronto.ca>
2
 
# Copyright (C) 2005, 2006 Canonical Ltd
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
2
# Copyright (C) 2005, 2006 Canonical <canonical.com>
 
3
#
 
4
#    This program is free software; you can redistribute it and/or modify
 
5
#    it under the terms of the GNU General Public License as published by
 
6
#    the Free Software Foundation; either version 2 of the License, or
 
7
#    (at your option) any later version.
 
8
#
 
9
#    This program is distributed in the hope that it will be useful,
 
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
#    GNU General Public License for more details.
 
13
#
 
14
#    You should have received a copy of the GNU General Public License
 
15
#    along with this program; if not, write to the Free Software
 
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
19
"""Simple text-mode progress indicator.
35
35
# TODO: Optionally show elapsed time instead/as well as ETA; nicer
36
36
# when the rate is unpredictable
37
37
 
 
38
 
38
39
import sys
39
40
import time
40
41
import os
41
42
 
42
 
from bzrlib.lazy_import import lazy_import
43
 
lazy_import(globals(), """
44
 
from bzrlib import (
45
 
    errors,
46
 
    )
47
 
""")
48
 
 
 
43
import bzrlib.errors as errors
49
44
from bzrlib.trace import mutter
50
45
 
51
46
 
179
174
        self._stack = _stack
180
175
        # seed throttler
181
176
        self.MIN_PAUSE = 0.1 # seconds
182
 
        now = time.time()
 
177
        now = time.clock()
183
178
        # starting now
184
179
        self.start_time = now
185
180
        # next update should not throttle
297
292
    def throttle(self, old_msg):
298
293
        """Return True if the bar was updated too recently"""
299
294
        # time.time consistently takes 40/4000 ms = 0.01 ms.
300
 
        # time.clock() is faster, but gives us CPU time, not wall-clock time
301
 
        now = time.time()
 
295
        # but every single update to the pb invokes it.
 
296
        # so we use time.clock which takes 20/4000 ms = 0.005ms
 
297
        # on the downside, time.clock() appears to have approximately
 
298
        # 10ms granularity, so we treat a zero-time change as 'throttled.'
 
299
        now = time.clock()
302
300
        if self.start_time is not None and (now - self.start_time) < 1:
303
301
            return True
304
302
        if old_msg != self.last_msg:
429
427
            bar_str = ''
430
428
 
431
429
        m = spin_str + bar_str + self.last_msg + count_str + pct_str + eta_str
432
 
        self.to_file.write('\r%-*.*s' % (self.width - 1, self.width - 1, m))
 
430
 
 
431
        assert len(m) < self.width
 
432
        self.to_file.write('\r' + m.ljust(self.width - 1))
433
433
        self._have_output = True
434
434
        #self.to_file.flush()
435
435
            
508
508
    if current > total:
509
509
        return None                     # wtf?
510
510
 
511
 
    elapsed = time.time() - start_time
 
511
    elapsed = time.clock() - start_time
512
512
 
513
513
    if elapsed < 2.0:                   # not enough time to estimate
514
514
        return None