/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 breezy/ui/text.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        terminal.
67
67
        """
68
68
        is_tty = self.ui.raw_stdin.isatty()
69
 
        if (os.environ.get('BRZ_TEXTUI_INPUT') != 'line-based' and
70
 
                self.ui.raw_stdin == sys.stdin and is_tty):
 
69
        if (os.environ.get('BRZ_TEXTUI_INPUT') != 'line-based'
 
70
                and self.ui.raw_stdin == sys.stdin and is_tty):
71
71
            self.line_based = False
72
72
            self.echo_back = True
73
73
        else:
123
123
 
124
124
    def _getchar(self):
125
125
        char = osutils.getchar()
126
 
        if char == chr(3): # INTR
 
126
        if char == chr(3):  # INTR
127
127
            raise KeyboardInterrupt
128
 
        if char == chr(4): # EOF (^d, C-d)
 
128
        if char == chr(4):  # EOF (^d, C-d)
129
129
            raise EOFError
130
130
        if isinstance(char, bytes):
131
131
            return char.decode('ascii', 'replace')
302
302
        if self.is_quiet():
303
303
            return NullProgressView()
304
304
        pb_type = config.GlobalStack().get('progress_bar')
305
 
        if pb_type == 'none': # Explicit requirement
 
305
        if pb_type == 'none':  # Explicit requirement
306
306
            return NullProgressView()
307
 
        if (pb_type == 'text' # Explicit requirement
308
 
            or progress._supports_progress(self.stderr)): # Guess
 
307
        if (pb_type == 'text'  # or # Explicit requirement
 
308
                progress._supports_progress(self.stderr)):  # Guess
309
309
            return TextProgressView(self.stderr)
310
310
        # No explicit requirement and no successful guess
311
311
        return NullProgressView()
340
340
        By default it does nothing.
341
341
        """
342
342
        self._progress_view.show_transport_activity(transport,
343
 
            direction, byte_count)
 
343
                                                    direction, byte_count)
344
344
 
345
345
    def log_transport_activity(self, display=False):
346
346
        """See UIFactory.log_transport_activity()"""
364
364
        """
365
365
        if not self._task_stack:
366
366
            warnings.warn("%r updated but no tasks are active" %
367
 
                (task,))
 
367
                          (task,))
368
368
        elif task != self._task_stack[-1]:
369
369
            # We used to check it was the top task, but it's hard to always
370
370
            # get this right and it's not necessarily useful: any actual
371
371
            # problems will be evident in use
372
 
            #warnings.warn("%r is not the top progress task %r" %
 
372
            # warnings.warn("%r is not the top progress task %r" %
373
373
            #     (task, self._task_stack[-1]))
374
374
            pass
375
375
        self._progress_view.show_progress(task)
461
461
    def _render_bar(self):
462
462
        # return a string for the progress bar itself
463
463
        if self.enable_bar and (
464
 
            (self._last_task is None) or self._last_task.show_bar):
 
464
                (self._last_task is None) or self._last_task.show_bar):
465
465
            # If there's no task object, we show space for the bar anyhow.
466
466
            # That's because most invocations of bzr will end showing progress
467
467
            # at some point, though perhaps only after doing some initial IO.
468
468
            # It looks better to draw the progress bar initially rather than
469
469
            # to have what looks like an incomplete progress bar.
470
 
            spin_str =  r'/-\|'[self._spin_pos % 4]
 
470
            spin_str = r'/-\|'[self._spin_pos % 4]
471
471
            self._spin_pos += 1
472
472
            cols = 20
473
473
            if self._last_task is None:
477
477
                completion_fraction = \
478
478
                    self._last_task._overall_completion_fraction() or 0
479
479
            if (completion_fraction < self._fraction and 'progress' in
480
 
                debug.debug_flags):
 
480
                    debug.debug_flags):
481
481
                debug.set_trace()
482
482
            self._fraction = completion_fraction
483
483
            markers = int(round(float(cols) * completion_fraction)) - 1
485
485
            return bar_str
486
486
        elif (self._last_task is None) or self._last_task.show_spinner:
487
487
            # The last task wanted just a spinner, no bar
488
 
            spin_str =  r'/-\|'[self._spin_pos % 4]
 
488
            spin_str = r'/-\|'[self._spin_pos % 4]
489
489
            self._spin_pos += 1
490
490
            return spin_str + ' '
491
491
        else:
533
533
        avail_width = self._avail_width()
534
534
        if avail_width is not None:
535
535
            # if terminal avail_width is unknown, don't truncate
536
 
            current_len = len(bar_string) + len(trans) + len(task_part) + len(counter_part)
 
536
            current_len = len(bar_string) + len(trans) + \
 
537
                len(task_part) + len(counter_part)
537
538
            # GZ 2017-04-22: Should measure and truncate task_part properly
538
539
            gap = current_len - avail_width
539
540
            if gap > 0:
540
 
                task_part = task_part[:-gap-2] + '..'
 
541
                task_part = task_part[:-gap - 2] + '..'
541
542
        s = trans + bar_string + task_part + counter_part
542
543
        if avail_width is not None:
543
544
            if len(s) < avail_width:
603
604
        elif now >= (self._transport_update_time + 0.5):
604
605
            # guard against clock stepping backwards, and don't update too
605
606
            # often
606
 
            rate = (self._bytes_since_update
607
 
                    / (now - self._transport_update_time))
 
607
            rate = (self._bytes_since_update /
 
608
                    (now - self._transport_update_time))
608
609
            # using base-10 units (see HACKING.txt).
609
610
            msg = ("%6dkB %5dkB/s " %
610
 
                    (self._total_byte_count / 1000, int(rate) / 1000,))
 
611
                   (self._total_byte_count / 1000, int(rate) / 1000,))
611
612
            self._transport_update_time = now
612
613
            self._last_repaint = now
613
614
            self._bytes_since_update = 0
630
631
                  bps / 1000.,
631
632
                  self._bytes_by_direction['read'] / 1000.,
632
633
                  self._bytes_by_direction['write'] / 1000.,
633
 
                 ))
 
634
                  ))
634
635
        if self._bytes_by_direction['unknown'] > 0:
635
636
            msg += ' u:%.0fkB)' % (
636
637
                self._bytes_by_direction['unknown'] / 1000.