~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to progress.py

  • Committer: abentley
  • Date: 2005-05-02 07:04:00 UTC
  • Revision ID: abentley@lappy-20050502070400-d14eee47272c8cdf
added bzr-push command

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
import sys
19
 
import datetime
20
 
from bzrlib.progress import ProgressBar
21
19
 
22
20
class Progress(object):
23
21
    def __init__(self, units, current, total=None):
24
22
        self.units = units
25
23
        self.current = current
26
24
        self.total = total
27
 
 
28
 
    def _get_percent(self):
29
 
        if self.total is None:
30
 
            return None
31
 
        return 100.0 * self.current / self.total
32
 
 
33
 
    percent = property(_get_percent)
 
25
        self.percent = None
 
26
        if self.total is not None:
 
27
            self.percent = 100.0 * current / total
34
28
 
35
29
    def __str__(self):
36
30
        if self.total is not None:
39
33
        else:
40
34
            return "%i %s" (self.current, self.units) 
41
35
 
42
 
def show_progress(pi, prog):
43
 
    pi.update(prog.units, prog.current, prog.total)
44
 
        
 
36
 
 
37
def progress_bar(progress):
 
38
    fmt = " %i of %i %s (%.1f%%)"
 
39
    f = fmt % (progress.total, progress.total, progress.units, 100.0)
 
40
    max = len(f)
 
41
    cols = 77 - max
 
42
    markers = int (float(cols) * progress.current / progress.total)
 
43
    txt = fmt % (progress.current, progress.total, progress.units,
 
44
                 progress.percent)
 
45
    sys.stdout.write("\r[%s%s]%s" % ('='*markers, ' '*(cols-markers), txt))
 
46
 
45
47
def clear_progress_bar():
46
 
    sys.stderr.write('\r%s\r' % (' '*79))
 
48
    sys.stdout.write('\r%s\r' % (' '*79))
 
49