~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-24 18:26:21 UTC
  • mfrom: (4567 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4568.
  • Revision ID: john@arbash-meinel.com-20090724182621-68s2jhoqf3pn72n7
Merge bzr.dev 4567 to resolve NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    )
38
38
 
39
39
 
40
 
# XXX: deprecated; can be removed when the ProgressBar factory is removed
41
40
def _supports_progress(f):
42
 
    """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.
43
42
 
44
43
    If this returns true we expect that a human may be looking at that
45
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.
46
47
    """
47
48
    isatty = getattr(f, 'isatty', None)
48
49
    if isatty is None:
49
50
        return False
50
51
    if not isatty():
51
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.
52
57
    if os.environ.get('TERM') == 'dumb':
53
58
        # e.g. emacs compile window
54
59
        return False
66
71
    will not necessarily respect all these fields.
67
72
    """
68
73
 
69
 
    def __init__(self, parent_task=None, ui_factory=None):
 
74
    def __init__(self, parent_task=None, ui_factory=None, progress_view=None):
70
75
        """Construct a new progress task.
71
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
 
72
84
        Normally you should not call this directly but rather through
73
85
        `ui_factory.nested_progress_bar`.
74
86
        """
77
89
        self.total_cnt = None
78
90
        self.current_cnt = None
79
91
        self.msg = ''
 
92
        # TODO: deprecate passing ui_factory
80
93
        self.ui_factory = ui_factory
 
94
        self.progress_view = progress_view
81
95
        self.show_pct = False
82
96
        self.show_spinner = True
83
97
        self.show_eta = False,
96
110
        self.current_cnt = current_cnt
97
111
        if total_cnt:
98
112
            self.total_cnt = total_cnt
99
 
        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)
100
117
 
101
118
    def tick(self):
102
119
        self.update(self.msg)
103
120
 
104
121
    def finished(self):
105
 
        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)
106
126
 
107
127
    def make_sub_task(self):
108
 
        return ProgressTask(self, self.ui_factory)
 
128
        return ProgressTask(self, ui_factory=self.ui_factory,
 
129
            progress_view=self.progress_view)
109
130
 
110
131
    def _overall_completion_fraction(self, child_fraction=0.0):
111
132
        """Return fractional completion of this task and its parents
134
155
 
135
156
    def clear(self):
136
157
        # XXX: shouldn't be here; put it in mutter or the ui instead
137
 
        self.ui_factory.clear_term()
 
158
        if self.progress_view:
 
159
            self.progress_view.clear()
 
160
        else:
 
161
            self.ui_factory.clear_term()
138
162
 
139
163
 
140
164
@deprecated_function(deprecated_in((1, 16, 0)))
161
185
        return _progress_bar_types[requested_bar_type](to_file=to_file, **kwargs)
162
186
 
163
187
 
 
188
# NOTE: This is also deprecated; you should provide a ProgressView instead.
164
189
class _BaseProgressBar(object):
165
190
 
166
191
    def __init__(self,
448
473
        #self.to_file.flush()
449
474
 
450
475
 
 
476
 
 
477
# DEPRECATED
451
478
class ChildProgress(_BaseProgressBar):
452
479
    """A progress indicator that pushes its data to the parent"""
453
480