~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Robert Collins
  • Date: 2006-03-28 14:29:13 UTC
  • mto: (1626.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1628.
  • Revision ID: robertc@robertcollins.net-20060328142913-ac5afb37075719c6
Convert log to use the new tsort.merge_sort routine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
 
59
59
 
60
60
 
61
 
def ProgressBar(to_file=None, **kwargs):
 
61
def ProgressBar(to_file=sys.stderr, **kwargs):
62
62
    """Abstract factory"""
63
 
    if to_file is None:
64
 
        to_file = sys.stderr
65
63
    if _supports_progress(to_file):
66
64
        return TTYProgressBar(to_file=to_file, **kwargs)
67
65
    else:
72
70
    """A stack of progress bars."""
73
71
 
74
72
    def __init__(self,
75
 
                 to_file=None,
 
73
                 to_file=sys.stderr,
76
74
                 show_pct=False,
77
75
                 show_spinner=True,
78
76
                 show_eta=False,
79
77
                 show_bar=True,
80
78
                 show_count=True,
81
 
                 to_messages_file=None,
 
79
                 to_messages_file=sys.stdout,
82
80
                 klass=None):
83
81
        """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
88
82
        self._to_file = to_file
89
83
        self._show_pct = show_pct
90
84
        self._show_spinner = show_spinner
101
95
        else:
102
96
            return None
103
97
 
104
 
    def bottom(self):
105
 
        if len(self._stack) != 0:
106
 
            return self._stack[0]
107
 
        else:
108
 
            return None
109
 
 
110
98
    def get_nested(self):
111
99
        """Return a nested progress bar."""
112
100
        if len(self._stack) == 0:
134
122
class _BaseProgressBar(object):
135
123
 
136
124
    def __init__(self,
137
 
                 to_file=None,
 
125
                 to_file=sys.stderr,
138
126
                 show_pct=False,
139
127
                 show_spinner=False,
140
128
                 show_eta=True,
141
129
                 show_bar=True,
142
130
                 show_count=True,
143
 
                 to_messages_file=None,
 
131
                 to_messages_file=sys.stdout,
144
132
                 _stack=None):
145
133
        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
150
134
        self.to_file = to_file
151
135
        self.to_messages_file = to_messages_file
152
136
        self.last_msg = None
205
189
    def child_progress(self, **kwargs):
206
190
        return DummyProgress(**kwargs)
207
191
 
208
 
 
209
192
class DotsProgressBar(_BaseProgressBar):
210
193
 
211
194
    def __init__(self, **kwargs):
220
203
        if msg and msg != self.last_msg:
221
204
            if self.need_nl:
222
205
                self.to_file.write('\n')
 
206
            
223
207
            self.to_file.write(msg + ': ')
224
208
            self.last_msg = msg
225
209
        self.need_nl = True
228
212
    def clear(self):
229
213
        if self.need_nl:
230
214
            self.to_file.write('\n')
231
 
        self.need_nl = False
232
215
        
233
216
    def child_update(self, message, current, total):
234
217
        self.tick()
235
 
 
236
218
    
237
219
class TTYProgressBar(_BaseProgressBar):
238
220
    """Progress bar display object.
409
391
 
410
392
class ChildProgress(_BaseProgressBar):
411
393
    """A progress indicator that pushes its data to the parent"""
412
 
 
413
394
    def __init__(self, _stack, **kwargs):
414
395
        _BaseProgressBar.__init__(self, _stack=_stack, **kwargs)
415
396
        self.parent = _stack.top()
446
427
    def clear(self):
447
428
        pass
448
429
 
449
 
    def note(self, *args, **kwargs):
450
 
        self.parent.note(*args, **kwargs)
451
 
 
452
430
 
453
431
def str_tdelta(delt):
454
432
    if delt is None: