Пример #1
0
    def write(self, context, prefix='', rewind=True, append=None):
        t_cnt = len(context)

        if not self.iswindows:
            buffered = self.stdout.switch()
            for line in buffered.split('\n')[:-1]:
                print(line + CLEAR_EOL, file=sys.stderr)

        alive_color = Style.BRIGHT
        dead_color = Style.BRIGHT + Fore.BLACK

        for i in context.graph.topologically_sorted_indexes:
            node = context[i]
            name_suffix = '({})'.format(i) if settings.DEBUG.get() else ''
            if node.alive:
                _line = ''.join((
                    ' ',
                    alive_color,
                    '+',
                    Style.RESET_ALL,
                    ' ',
                    node.name,
                    name_suffix,
                    ' ',
                    node.get_statistics_as_string(),
                    Style.RESET_ALL,
                    ' ',
                ))
            else:
                _line = ''.join((
                    ' ',
                    dead_color,
                    '-',
                    ' ',
                    node.name,
                    name_suffix,
                    ' ',
                    node.get_statistics_as_string(),
                    Style.RESET_ALL,
                    ' ',
                ))
            print(prefix + _line + '\033[0K', file=sys.stderr)

        if append:
            # todo handle multiline
            print(''.join((' `-> ', ' '.join(
                '{}{}{}: {}'.format(Style.BRIGHT, k, Style.RESET_ALL, v)
                for k, v in append), CLEAR_EOL)),
                  file=sys.stderr)
            t_cnt += 1

        if rewind:
            print(CLEAR_EOL, file=sys.stderr)
            print(MOVE_CURSOR_UP(t_cnt + 2), file=sys.stderr)
Пример #2
0
    def write(context,
              prefix='',
              rewind=True,
              append=None,
              debug=False,
              profile=False):
        t_cnt = len(context)

        for i, component in enumerate(context):
            if component.alive:
                _line = ''.join((
                    Fore.BLACK,
                    '({})'.format(i + 1),
                    Style.RESET_ALL,
                    ' ',
                    Style.BRIGHT,
                    '+',
                    Style.RESET_ALL,
                    ' ',
                    component.name,
                    ' ',
                    component.get_statistics_as_string(debug=debug,
                                                       profile=profile),
                    Style.RESET_ALL,
                    ' ',
                ))
            else:
                _line = ''.join((
                    Fore.BLACK,
                    '({})'.format(i + 1),
                    ' - ',
                    component.name,
                    ' ',
                    component.get_statistics_as_string(debug=debug,
                                                       profile=profile),
                    Style.RESET_ALL,
                    ' ',
                ))
            print(prefix + _line + '\033[0K')

        if append:
            # todo handle multiline
            print(''.join((' `-> ', ' '.join(
                '{}{}{}: {}'.format(Style.BRIGHT, k, Style.RESET_ALL, v)
                for k, v in append), CLEAR_EOL)))
            t_cnt += 1

        if rewind:
            print(CLEAR_EOL)
            print(MOVE_CURSOR_UP(t_cnt + 2))
Пример #3
0
    def write(self, context, prefix="", rewind=True, append=None):
        t_cnt = len(context)

        if not self.iswindows:
            for line in self.stdout.switch().split("\n")[:-1]:
                print(line + CLEAR_EOL, file=self._stdout)
            for line in self.stderr.switch().split("\n")[:-1]:
                print(line + CLEAR_EOL, file=self._stderr)

        alive_color = Style.BRIGHT
        dead_color = Style.BRIGHT + Fore.BLACK

        for i in context.graph.topologically_sorted_indexes:
            node = context[i]
            name_suffix = "({})".format(i) if settings.DEBUG.get() else ""

            liveliness_color = alive_color if node.alive else dead_color
            liveliness_prefix = " {}{}{} ".format(liveliness_color,
                                                  node.status, Style.RESET_ALL)
            _line = "".join((
                liveliness_prefix,
                node.name,
                name_suffix,
                " ",
                node.get_statistics_as_string(),
                " ",
                node.get_flags_as_string(),
                Style.RESET_ALL,
                " ",
            ))
            print(prefix + _line + CLEAR_EOL, file=self._stderr)

        if append:
            # todo handle multiline
            print(
                "".join((
                    " `-> ",
                    " ".join("{}{}{}: {}".format(Style.BRIGHT, k,
                                                 Style.RESET_ALL, v)
                             for k, v in append),
                    CLEAR_EOL,
                )),
                file=self._stderr,
            )
            t_cnt += 1

        if rewind:
            print(CLEAR_EOL, file=self._stderr)
            print(MOVE_CURSOR_UP(t_cnt + 2), file=self._stderr)
Пример #4
0
    def write(context, prefix='', rewind=True, append=None):
        t_cnt = len(context)

        for i in context.graph.topologically_sorted_indexes:
            node = context[i]
            name_suffix = '({})'.format(i) if settings.DEBUG else ''
            if node.alive:
                _line = ''.join(
                    (
                        ' ', Style.BRIGHT, '+', Style.RESET_ALL, ' ', node.name, name_suffix, ' ',
                        node.get_statistics_as_string(), Style.RESET_ALL, ' ',
                    )
                )
            else:
                _line = ''.join(
                    (
                        ' ', Fore.BLACK, '-', ' ', node.name, name_suffix, ' ', node.get_statistics_as_string(),
                        Style.RESET_ALL, ' ',
                    )
                )
            print(prefix + _line + '\033[0K')

        if append:
            # todo handle multiline
            print(
                ''.join(
                    (
                        ' `-> ', ' '.join('{}{}{}: {}'.format(Style.BRIGHT, k, Style.RESET_ALL, v)
                                          for k, v in append), CLEAR_EOL
                    )
                )
            )
            t_cnt += 1

        if rewind:
            print(CLEAR_EOL)
            print(MOVE_CURSOR_UP(t_cnt + 2))