~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: 2006-04-24 01:20:27 UTC
  • mfrom: (1681.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060424012027-0017c749480ad462
Make TextUIFactory allow selection of the progress bar type.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
 
59
59
 
60
60
 
61
 
def ProgressBar(to_file=sys.stderr, **kwargs):
 
61
def ProgressBar(to_file=None, **kwargs):
62
62
    """Abstract factory"""
 
63
    if to_file is None:
 
64
        to_file = sys.stderr
63
65
    if _supports_progress(to_file):
64
66
        return TTYProgressBar(to_file=to_file, **kwargs)
65
67
    else:
70
72
    """A stack of progress bars."""
71
73
 
72
74
    def __init__(self,
73
 
                 to_file=sys.stderr,
 
75
                 to_file=None,
74
76
                 show_pct=False,
75
77
                 show_spinner=True,
76
78
                 show_eta=False,
77
79
                 show_bar=True,
78
80
                 show_count=True,
79
 
                 to_messages_file=sys.stdout,
 
81
                 to_messages_file=None,
80
82
                 klass=None):
81
83
        """Setup the stack with the parameters the progress bars should have."""
 
84
        if to_file is None:
 
85
            to_file = sys.stderr
 
86
        if to_messages_file is None:
 
87
            to_messages_file = sys.stdout
82
88
        self._to_file = to_file
83
89
        self._show_pct = show_pct
84
90
        self._show_spinner = show_spinner
128
134
class _BaseProgressBar(object):
129
135
 
130
136
    def __init__(self,
131
 
                 to_file=sys.stderr,
 
137
                 to_file=None,
132
138
                 show_pct=False,
133
139
                 show_spinner=False,
134
140
                 show_eta=True,
135
141
                 show_bar=True,
136
142
                 show_count=True,
137
 
                 to_messages_file=sys.stdout,
 
143
                 to_messages_file=None,
138
144
                 _stack=None):
139
145
        object.__init__(self)
 
146
        if to_file is None:
 
147
            to_file = sys.stderr
 
148
        if to_messages_file is None:
 
149
            to_messages_file = sys.stdout
140
150
        self.to_file = to_file
141
151
        self.to_messages_file = to_messages_file
142
152
        self.last_msg = None
195
205
    def child_progress(self, **kwargs):
196
206
        return DummyProgress(**kwargs)
197
207
 
 
208
 
198
209
class DotsProgressBar(_BaseProgressBar):
199
210
 
200
211
    def __init__(self, **kwargs):
209
220
        if msg and msg != self.last_msg:
210
221
            if self.need_nl:
211
222
                self.to_file.write('\n')
212
 
            
213
223
            self.to_file.write(msg + ': ')
214
224
            self.last_msg = msg
215
225
        self.need_nl = True
218
228
    def clear(self):
219
229
        if self.need_nl:
220
230
            self.to_file.write('\n')
 
231
        self.need_nl = False
221
232
        
222
233
    def child_update(self, message, current, total):
223
234
        self.tick()
 
235
 
224
236
    
225
237
class TTYProgressBar(_BaseProgressBar):
226
238
    """Progress bar display object.
397
409
 
398
410
class ChildProgress(_BaseProgressBar):
399
411
    """A progress indicator that pushes its data to the parent"""
 
412
 
400
413
    def __init__(self, _stack, **kwargs):
401
414
        _BaseProgressBar.__init__(self, _stack=_stack, **kwargs)
402
415
        self.parent = _stack.top()