예제 #1
0
파일: logs.py 프로젝트: crogers1/buildbot
    def content(self, entries):
        html_entries = []
        text_data = ''
        for type, entry in entries:
            if type >= len(logfile.ChunkTypes) or type < 0:
                # non-std channel, don't display
                continue

            is_header = type == logfile.HEADER

            if not self.asText:
                # jinja only works with unicode, or pure ascii, so assume utf-8 in logs
                if not isinstance(entry, unicode):
                    entry = unicode(entry, 'utf-8', 'replace')
                first_entry = True
                _type = logfile.ChunkTypes[type]
                for ansi_entry in entry.split("\033["):
                    code = ""
                    if not first_entry:
                        ansi_entry, ansi_classes = parse_ansi_sgr(ansi_entry)
                        if ansi_classes:
                            code = "".join([" ansi" + i for i in ansi_classes])
                    html_entries.append(
                        dict(type=_type + code,
                             text=ansi_entry,
                             is_header=is_header))
                    first_entry = False

            elif not is_header:
                text_data += entry

        if self.asText:
            return text_data
        else:
            return self.template.module.chunks(html_entries)
예제 #2
0
파일: logs.py 프로젝트: Captricity/buildbot
    def content(self, entries):
        html_entries = []
        text_data = ''
        for type, entry in entries:
            if type >= len(logfile.ChunkTypes) or type < 0:
                # non-std channel, don't display
                continue

            is_header = type == logfile.HEADER

            if not self.asText:
                # jinja only works with unicode, or pure ascii, so assume utf-8 in logs
                if not isinstance(entry, unicode):
                    entry = unicode(entry, 'utf-8', 'replace')
                first_entry = True
                _type = logfile.ChunkTypes[type]
                for ansi_entry in entry.split("\033["):
                    code = ""
                    if not first_entry:
                        ansi_entry, ansi_classes = parse_ansi_sgr(ansi_entry)
                        if ansi_classes:
                            code = "".join([" ansi" + i for i in ansi_classes])
                    html_entries.append(dict(type=_type + code,
                                             text=ansi_entry,
                                             is_header=is_header))
                    first_entry = False

            elif not is_header:
                text_data += entry

        if self.asText:
            return text_data
        else:
            return self.template.module.chunks(html_entries)
예제 #3
0
 def runTest(self, string, expected):
     ret = parse_ansi_sgr(string)
     self.assertEqual(ret, expected)