Esempio n. 1
0
    def _serve_report(self, id, kinds_filter):
        ''' Serve a specific report for a file '''
        id = int(id)
        view_report = View.get().report

        try:
            file = view_report.files[id]
        except IndexError:
            self._serve_not_found()
            return

        try:
            with io.open(file.path, 'r', encoding='utf-8',
                         errors='ignore') as f:
                code = f.read()
        except (OSError, IOError):
            self._serve_error("No such file: %s" % file.path)
            return

        fmt = Formatter(file)
        lexer = CppLexer(stripnl=False)
        code = highlight(code, lexer, fmt)
        check_kinds_filter = self._check_kinds_filter(param=kinds_filter)
        self._write_template(
            'report.html', {
                'filepath': html.escape(report.format_path(file.path)),
                'check_kinds': json.dumps(self._check_kinds()),
                'check_kinds_filter': json.dumps(check_kinds_filter),
                'code': code,
                'functions': json.dumps(fmt.functions),
                'call_contexts': json.dumps(fmt.call_contexts),
                'checks': json.dumps(fmt.checks),
                'pygments_css': fmt.get_style_defs('.highlight')
            })
Esempio n. 2
0
    def _files(self):
        ''' Generate the Javascript variable files '''
        view_report = View.get().report
        files = []

        for file in view_report.files:
            files.append({
                'id': file.id,
                'path': report.format_path(file.path),
                'status_kinds': view_report.files_status_kinds[file.id]
            })

        # Sort by path
        files.sort(key=operator.itemgetter('path'))

        return files
Esempio n. 3
0
    def _build_call_context(self, call_context):
        call_context_id = call_context.id

        if call_context_id in self.call_contexts:
            return

        lines = []
        while not call_context.empty():
            call_statement = call_context.call()
            function = call_context.function()
            line = "%s:%s:%s: function '%s'" % (
                report.format_path(call_statement.file_path())
                or '?', call_statement.line_or('?'),
                call_statement.column_or('?'), function.pretty_name())
            lines.append(line)
            call_context = call_context.parent()

        self.call_contexts[call_context_id] = '\n'.join(lines)