~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-01-23 18:14:16 UTC
  • mfrom: (3948.2.8 progress)
  • Revision ID: pqm@pqm.ubuntu.com-20090123181416-tku4gdtorboy6d0y
(mbp) further progress bar fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
"""Progress indicators.
19
19
 
20
20
The usual way to use this is via bzrlib.ui.ui_factory.nested_progress_bar which
21
 
will maintain a ProgressBarStack for you.
22
 
 
23
 
For direct use, the factory ProgressBar will return an auto-detected progress
24
 
bar that should match your terminal type. You can manually create a
25
 
ProgressBarStack too if you need multiple levels of cooperating progress bars.
26
 
Note that bzrlib's internal functions use the ui module, so if you are using
27
 
bzrlib it really is best to use bzrlib.ui.ui_factory.
 
21
will manage a conceptual stack of nested activities.
28
22
"""
29
23
 
30
24
 
41
35
    ui,
42
36
    )
43
37
from bzrlib.trace import mutter
 
38
from bzrlib.symbol_versioning import (
 
39
    deprecated_in,
 
40
    deprecated_method,
 
41
    )
44
42
 
45
43
 
46
44
def _supports_progress(f):
84
82
        self.show_count = True
85
83
        self.show_bar = True
86
84
 
 
85
    def __repr__(self):
 
86
        return '%s(%r/%r, msg=%r)' % (
 
87
            self.__class__.__name__,
 
88
            self.current_cnt,
 
89
            self.total_cnt,
 
90
            self.msg)
 
91
 
87
92
    def update(self, msg, current_cnt=None, total_cnt=None):
88
93
        self.msg = msg
89
94
        self.current_cnt = current_cnt
90
95
        if total_cnt:
91
96
            self.total_cnt = total_cnt
92
 
        self.ui_factory.show_progress(self)
 
97
        self.ui_factory._progress_updated(self)
93
98
 
94
99
    def tick(self):
95
100
        self.update(self.msg)
96
101
 
97
102
    def finished(self):
98
 
        self.ui_factory.progress_finished(self)
 
103
        self.ui_factory._progress_finished(self)
99
104
 
100
105
    def make_sub_task(self):
101
106
        return ProgressTask(self, self.ui_factory)
152
157
 
153
158
 
154
159
class ProgressBarStack(object):
155
 
    """A stack of progress bars."""
 
160
    """A stack of progress bars.
 
161
    
 
162
    This class is deprecated: instead, ask the ui factory for a new progress
 
163
    task and finish it when it's done.
 
164
    """
156
165
 
 
166
    @deprecated_method(deprecated_in((1, 12, 0)))
157
167
    def __init__(self,
158
168
                 to_file=None,
159
169
                 show_pct=False,