~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Robert Collins
  • Date: 2009-08-04 04:36:34 UTC
  • mfrom: (4583 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4593.
  • Revision ID: robertc@robertcollins.net-20090804043634-2iu9wpcgs273i97s
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import sys
26
26
import time
27
27
import os
28
 
import warnings
29
28
 
30
29
 
31
30
from bzrlib import (
32
31
    errors,
33
 
    osutils,
34
 
    trace,
35
 
    ui,
36
32
    )
37
33
from bzrlib.trace import mutter
38
34
from bzrlib.symbol_versioning import (
39
35
    deprecated_function,
40
36
    deprecated_in,
41
 
    deprecated_method,
42
37
    )
43
38
 
44
39
 
45
 
# XXX: deprecated; can be removed when the ProgressBar factory is removed
46
40
def _supports_progress(f):
47
 
    """Detect if we can use pretty progress bars on the output stream f.
 
41
    """Detect if we can use pretty progress bars on file F.
48
42
 
49
43
    If this returns true we expect that a human may be looking at that
50
44
    output, and that we can repaint a line to update it.
 
45
 
 
46
    This doesn't check the policy for whether we *should* use them.
51
47
    """
52
48
    isatty = getattr(f, 'isatty', None)
53
49
    if isatty is None:
54
50
        return False
55
51
    if not isatty():
56
52
        return False
 
53
    # The following case also handles Win32 - on that platform $TERM is
 
54
    # typically never set, so the case None is treated as a smart terminal,
 
55
    # not dumb.  <https://bugs.launchpad.net/bugs/334808>  win32 files do have
 
56
    # isatty methods that return true.
57
57
    if os.environ.get('TERM') == 'dumb':
58
58
        # e.g. emacs compile window
59
59
        return False
71
71
    will not necessarily respect all these fields.
72
72
    """
73
73
 
74
 
    def __init__(self, parent_task=None, ui_factory=None):
 
74
    def __init__(self, parent_task=None, ui_factory=None, progress_view=None):
75
75
        """Construct a new progress task.
76
76
 
 
77
        :param parent_task: Enclosing ProgressTask or None.
 
78
 
 
79
        :param progress_view: ProgressView to display this ProgressTask.
 
80
 
 
81
        :param ui_factory: The UI factory that will display updates; 
 
82
            deprecated in favor of passing progress_view directly.
 
83
 
77
84
        Normally you should not call this directly but rather through
78
85
        `ui_factory.nested_progress_bar`.
79
86
        """
82
89
        self.total_cnt = None
83
90
        self.current_cnt = None
84
91
        self.msg = ''
 
92
        # TODO: deprecate passing ui_factory
85
93
        self.ui_factory = ui_factory
 
94
        self.progress_view = progress_view
86
95
        self.show_pct = False
87
96
        self.show_spinner = True
88
97
        self.show_eta = False,
101
110
        self.current_cnt = current_cnt
102
111
        if total_cnt:
103
112
            self.total_cnt = total_cnt
104
 
        self.ui_factory._progress_updated(self)
 
113
        if self.progress_view:
 
114
            self.progress_view.show_progress(self)
 
115
        else:
 
116
            self.ui_factory._progress_updated(self)
105
117
 
106
118
    def tick(self):
107
119
        self.update(self.msg)
108
120
 
109
121
    def finished(self):
110
 
        self.ui_factory._progress_finished(self)
 
122
        if self.progress_view:
 
123
            self.progress_view.task_finished(self)
 
124
        else:
 
125
            self.ui_factory._progress_finished(self)
111
126
 
112
127
    def make_sub_task(self):
113
 
        return ProgressTask(self, self.ui_factory)
 
128
        return ProgressTask(self, ui_factory=self.ui_factory,
 
129
            progress_view=self.progress_view)
114
130
 
115
131
    def _overall_completion_fraction(self, child_fraction=0.0):
116
132
        """Return fractional completion of this task and its parents
139
155
 
140
156
    def clear(self):
141
157
        # XXX: shouldn't be here; put it in mutter or the ui instead
142
 
        self.ui_factory.clear_term()
 
158
        if self.progress_view:
 
159
            self.progress_view.clear()
 
160
        else:
 
161
            self.ui_factory.clear_term()
143
162
 
144
163
 
145
164
@deprecated_function(deprecated_in((1, 16, 0)))
166
185
        return _progress_bar_types[requested_bar_type](to_file=to_file, **kwargs)
167
186
 
168
187
 
 
188
# NOTE: This is also deprecated; you should provide a ProgressView instead.
169
189
class _BaseProgressBar(object):
170
190
 
171
191
    def __init__(self,
453
473
        #self.to_file.flush()
454
474
 
455
475
 
 
476
 
 
477
# DEPRECATED
456
478
class ChildProgress(_BaseProgressBar):
457
479
    """A progress indicator that pushes its data to the parent"""
458
480