/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: John Arbash Meinel
  • Date: 2009-08-04 14:10:09 UTC
  • mfrom: (4585 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4588.
  • Revision ID: john@arbash-meinel.com-20090804141009-uety2n17v1atk5ok
Merge bzr.dev 4585, 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
64
69
    Code updating the task may also set fields as hints about how to display
65
70
    it: show_pct, show_spinner, show_eta, show_count, show_bar.  UIs
66
71
    will not necessarily respect all these fields.
 
72
    
 
73
    :ivar update_latency: The interval (in seconds) at which the PB should be
 
74
        updated.  Setting this to zero suggests every update should be shown
 
75
        synchronously.
 
76
 
 
77
    :ivar show_transport_activity: If true (default), transport activity
 
78
        will be shown when this task is drawn.  Disable it if you're sure 
 
79
        that only irrelevant or uninteresting transport activity can occur
 
80
        during this task.
67
81
    """
68
82
 
69
 
    def __init__(self, parent_task=None, ui_factory=None):
 
83
    def __init__(self, parent_task=None, ui_factory=None, progress_view=None):
70
84
        """Construct a new progress task.
71
85
 
 
86
        :param parent_task: Enclosing ProgressTask or None.
 
87
 
 
88
        :param progress_view: ProgressView to display this ProgressTask.
 
89
 
 
90
        :param ui_factory: The UI factory that will display updates; 
 
91
            deprecated in favor of passing progress_view directly.
 
92
 
72
93
        Normally you should not call this directly but rather through
73
94
        `ui_factory.nested_progress_bar`.
74
95
        """
77
98
        self.total_cnt = None
78
99
        self.current_cnt = None
79
100
        self.msg = ''
 
101
        # TODO: deprecate passing ui_factory
80
102
        self.ui_factory = ui_factory
 
103
        self.progress_view = progress_view
81
104
        self.show_pct = False
82
105
        self.show_spinner = True
83
106
        self.show_eta = False,
84
107
        self.show_count = True
85
108
        self.show_bar = True
 
109
        self.update_latency = 0.1
 
110
        self.show_transport_activity = True
86
111
 
87
112
    def __repr__(self):
88
113
        return '%s(%r/%r, msg=%r)' % (
96
121
        self.current_cnt = current_cnt
97
122
        if total_cnt:
98
123
            self.total_cnt = total_cnt
99
 
        self.ui_factory._progress_updated(self)
 
124
        if self.progress_view:
 
125
            self.progress_view.show_progress(self)
 
126
        else:
 
127
            self.ui_factory._progress_updated(self)
100
128
 
101
129
    def tick(self):
102
130
        self.update(self.msg)
103
131
 
104
132
    def finished(self):
105
 
        self.ui_factory._progress_finished(self)
 
133
        if self.progress_view:
 
134
            self.progress_view.task_finished(self)
 
135
        else:
 
136
            self.ui_factory._progress_finished(self)
106
137
 
107
138
    def make_sub_task(self):
108
 
        return ProgressTask(self, self.ui_factory)
 
139
        return ProgressTask(self, ui_factory=self.ui_factory,
 
140
            progress_view=self.progress_view)
109
141
 
110
142
    def _overall_completion_fraction(self, child_fraction=0.0):
111
143
        """Return fractional completion of this task and its parents
134
166
 
135
167
    def clear(self):
136
168
        # XXX: shouldn't be here; put it in mutter or the ui instead
137
 
        self.ui_factory.clear_term()
 
169
        if self.progress_view:
 
170
            self.progress_view.clear()
 
171
        else:
 
172
            self.ui_factory.clear_term()
138
173
 
139
174
 
140
175
@deprecated_function(deprecated_in((1, 16, 0)))
161
196
        return _progress_bar_types[requested_bar_type](to_file=to_file, **kwargs)
162
197
 
163
198
 
 
199
# NOTE: This is also deprecated; you should provide a ProgressView instead.
164
200
class _BaseProgressBar(object):
165
201
 
166
202
    def __init__(self,
448
484
        #self.to_file.flush()
449
485
 
450
486
 
 
487
 
 
488
# DEPRECATED
451
489
class ChildProgress(_BaseProgressBar):
452
490
    """A progress indicator that pushes its data to the parent"""
453
491