~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Martin Pool
  • Date: 2010-08-18 04:26:39 UTC
  • mfrom: (129.1.8 packaging-karmic)
  • Revision ID: mbp@sourcefrog.net-20100818042639-mjoxtngyjwiu05fo
* PPA rebuild for lucid.
* PPA rebuild for karmic.
* PPA rebuild onto jaunty.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
    This tells the library how to display things to the user.  Through this
107
107
    layer different applications can choose the style of UI.
108
108
 
 
109
    UI Factories are also context managers, for some syntactic sugar some users
 
110
    need.
 
111
 
109
112
    :ivar suppressed_warnings: Identifiers for user warnings that should 
110
113
        no be emitted.
111
114
    """
123
126
        self.suppressed_warnings = set()
124
127
        self._quiet = False
125
128
 
 
129
    def __enter__(self):
 
130
        """Context manager entry support.
 
131
 
 
132
        Override in a concrete factory class if initialisation before use is
 
133
        needed.
 
134
        """
 
135
        return self # This is bound to the 'as' clause in a with statement.
 
136
 
 
137
    def __exit__(self, exc_type, exc_val, exc_tb):
 
138
        """Context manager exit support.
 
139
 
 
140
        Override in a concrete factory class if more cleanup than a simple
 
141
        self.clear_term() is needed when the UIFactory is finished with.
 
142
        """
 
143
        self.clear_term()
 
144
        return False # propogate exceptions.
 
145
 
126
146
    def be_quiet(self, state):
127
147
        """Tell the UI to be more quiet, or not.
128
148
 
158
178
        version of stdout, but in a GUI it might be appropriate to send it to a 
159
179
        window displaying the text.
160
180
     
161
 
        :param encoding: Unicode encoding for output; default is the 
162
 
            terminal encoding, which may be different from the user encoding.
 
181
        :param encoding: Unicode encoding for output; if not specified 
 
182
            uses the configured 'output_encoding' if any; otherwise the 
 
183
            terminal encoding. 
163
184
            (See get_terminal_encoding.)
164
185
 
165
186
        :param encoding_type: How to handle encoding errors:
167
188
        """
168
189
        # XXX: is the caller supposed to close the resulting object?
169
190
        if encoding is None:
170
 
            encoding = osutils.get_terminal_encoding()
 
191
            from bzrlib import config
 
192
            encoding = config.GlobalConfig().get_user_option(
 
193
                'output_encoding')
 
194
        if encoding is None:
 
195
            encoding = osutils.get_terminal_encoding(trace=True)
171
196
        if encoding_type is None:
172
197
            encoding_type = 'replace'
173
198
        out_stream = self._make_output_stream_explicit(encoding, encoding_type)
195
220
        if not self._task_stack:
196
221
            warnings.warn("%r finished but nothing is active"
197
222
                % (task,))
198
 
        elif task != self._task_stack[-1]:
199
 
            warnings.warn("%r is not the active task %r"
200
 
                % (task, self._task_stack[-1]))
 
223
        if task in self._task_stack:
 
224
            self._task_stack.remove(task)
201
225
        else:
202
 
            del self._task_stack[-1]
 
226
            warnings.warn("%r is not in active stack %r"
 
227
                % (task, self._task_stack))
203
228
        if not self._task_stack:
204
229
            self._progress_all_finished()
205
230
 
344
369
        self.show_user_warning('cross_format_fetch', from_format=from_format,
345
370
            to_format=to_format)
346
371
 
 
372
    def warn_experimental_format_fetch(self, inter):
 
373
        """Warn about fetching into experimental repository formats."""
 
374
        if inter.target._format.experimental:
 
375
            trace.warning("Fetching into experimental format %s.\n"
 
376
                "This format may be unreliable or change in the future "
 
377
                "without an upgrade path.\n" % (inter.target._format,))
 
378
 
347
379
 
348
380
class SilentUIFactory(UIFactory):
349
381
    """A UI Factory which never prints anything.