~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Ross Lagerwall
  • Date: 2012-08-07 06:32:51 UTC
  • mto: (6437.63.5 2.5)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: rosslagerwall@gmail.com-20120807063251-x9p03ghg2ws8oqjc
Add bzrlib/locale to .bzrignore

bzrlib/locale is generated with ./setup.py build_mo which is in turn called
by ./setup.py build

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import warnings
32
32
 
33
33
from bzrlib import (
34
 
    config,
35
34
    debug,
36
35
    progress,
37
36
    osutils,
156
155
            return index
157
156
 
158
157
 
159
 
opt_progress_bar = config.Option(
160
 
    'progress_bar', help='Progress bar type.',
161
 
    default_from_env=['BZR_PROGRESS_BAR'], default=None,
162
 
    invalid='error')
163
 
 
164
 
 
165
158
class TextUIFactory(UIFactory):
166
 
    """A UI factory for Text user interfaces."""
 
159
    """A UI factory for Text user interefaces."""
167
160
 
168
161
    def __init__(self,
169
162
                 stdin=None,
238
231
            password = self.stdin.readline()
239
232
            if not password:
240
233
                password = None
241
 
            else:
242
 
                password = password.decode(self.stdin.encoding)
243
 
 
244
 
                if password[-1] == '\n':
245
 
                    password = password[:-1]
 
234
            elif password[-1] == '\n':
 
235
                password = password[:-1]
246
236
        return password
247
237
 
248
238
    def get_password(self, prompt=u'', **kwargs):
276
266
        username = self.stdin.readline()
277
267
        if not username:
278
268
            username = None
279
 
        else:
280
 
            username = username.decode(self.stdin.encoding)
281
 
            if username[-1] == '\n':
282
 
                username = username[:-1]
 
269
        elif username[-1] == '\n':
 
270
            username = username[:-1]
283
271
        return username
284
272
 
285
273
    def make_progress_view(self):
291
279
        # do that.  otherwise, guess based on $TERM and tty presence.
292
280
        if self.is_quiet():
293
281
            return NullProgressView()
294
 
        pb_type = config.GlobalStack().get('progress_bar')
295
 
        if pb_type == 'none': # Explicit requirement
296
 
            return NullProgressView()
297
 
        if (pb_type == 'text' # Explicit requirement
298
 
            or progress._supports_progress(self.stderr)): # Guess
299
 
            return TextProgressView(self.stderr)
300
 
        # No explicit requirement and no successful guess
301
 
        return NullProgressView()
 
282
        elif os.environ.get('BZR_PROGRESS_BAR') == 'text':
 
283
            return TextProgressView(self.stderr)
 
284
        elif os.environ.get('BZR_PROGRESS_BAR') == 'none':
 
285
            return NullProgressView()
 
286
        elif progress._supports_progress(self.stderr):
 
287
            return TextProgressView(self.stderr)
 
288
        else:
 
289
            return NullProgressView()
302
290
 
303
291
    def _make_output_stream_explicit(self, encoding, encoding_type):
304
292
        if encoding_type == 'exact':
336
324
        if kwargs:
337
325
            # See <https://launchpad.net/bugs/365891>
338
326
            prompt = prompt % kwargs
339
 
        try:
340
 
            prompt = prompt.encode(self.stderr.encoding)
341
 
        except (UnicodeError, AttributeError):
342
 
            # If stderr has no encoding attribute or can't properly encode,
343
 
            # fallback to terminal encoding for robustness (better display
344
 
            # something to the user than aborting with a traceback).
345
 
            prompt = prompt.encode(osutils.get_terminal_encoding(), 'replace')
 
327
        prompt = prompt.encode(osutils.get_terminal_encoding(), 'replace')
346
328
        self.clear_term()
347
329
        self.stdout.flush()
348
330
        self.stderr.write(prompt)