Пример #1
0
    def handle_file(self, f):
        if not f.dest_file.endswith('.py'):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        output = execute(
            [
                'pep8',
                '-r',
                '--max-line-length=%i' % self.settings['max_line_length'],
                path
            ],
            split_lines=True,
            ignore_errors=True)

        for line in output:
            parsed = line.split(':')
            lnum = int(parsed[1])
            col = int(parsed[2])
            msg = parsed[3]
            f.comment('Col: %s\n%s' % (col, msg), lnum)

        return True
Пример #2
0
    def handle_file(self, f):
        # Check if we should process this file, based on its extension.
        if not (f.dest_file.endswith('.js') or
                (self.file_exts and f.dest_file.endswith(self.file_exts))):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()

        if not path:
            return False

        cmd = ['jshint',
               '--extract=%s' % self.settings['extract_js_from_html']]

        if self.settings['verbose']:
            cmd.append('--verbose')

        if self.config_file:
            cmd.append('--config=%s' % self.config_file)

        cmd.append(path)
        output = execute(cmd, split_lines=True, ignore_errors=True)

        for line in output:
            m = re.match(self.REGEX, line)

            if m:
                f.comment('Col: %s\n%s' % (m.group('col'), m.group('msg')),
                          int(m.group('line_num')))

        return True
Пример #3
0
    def handle_file(self, f):
        if not f.dest_file.endswith(".py"):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        output = execute(
            [
                "pep8",
                "-r",
                "--max-line-length=%i" % self.settings["max_line_length"],
                "--ignore=%s" % self.settings["ignore"],
                path,
            ],
            split_lines=True,
            ignore_errors=True,
        )

        for line in output:
            parsed = line.split(":", 3)
            lnum = int(parsed[1])
            col = int(parsed[2])
            msg = parsed[3]
            f.comment("Col: %s\n%s" % (col, msg), lnum)

        return True
Пример #4
0
    def handle_file(self, f):
        if not f.dest_file.endswith('.py'):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        output = execute([
            'pep8', '-r',
            '--max-line-length=%i' % self.settings['max_line_length'],
            '--ignore=%s' % self.settings['ignore'], path
        ],
                         split_lines=True,
                         ignore_errors=True)

        for line in output:
            parsed = line.split(':', 3)
            lnum = int(parsed[1])
            col = int(parsed[2])
            msg = parsed[3]
            f.comment('Col: %s\n%s' % (col, msg), lnum)

        return True
Пример #5
0
    def handle_file(self, f):
        # Check if we should process this file, based on its extension.
        if not (f.dest_file.endswith('.js') or
                (self.file_exts and f.dest_file.endswith(self.file_exts))):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()

        if not path:
            return False

        cmd = [
            'jshint',
            '--extract=%s' % self.settings['extract_js_from_html']
        ]

        if self.settings['verbose']:
            cmd.append('--verbose')

        if self.config_file:
            cmd.append('--config=%s' % self.config_file)

        cmd.append(path)
        output = execute(cmd, split_lines=True, ignore_errors=True)

        for line in output:
            m = re.match(self.REGEX, line)

            if m:
                f.comment('Col: %s\n%s' % (m.group('col'), m.group('msg')),
                          int(m.group('line_num')))

        return True
Пример #6
0
    def execute(self, review, settings={}):
        cmd = [
            'buildbot',
            'try',
            '--wait',
            '--quiet',
            '--diff=%s' % review.get_patch_file_path(),
            '--patchlevel=1',
            '--username=%s' % settings['username'],
            '--master=%s:%s' % (settings['address'],
                                settings['port']
                                ),
        ]

        branch = review.api_root.get_review_request(
            review_request_id=review.request_id).branch

        if branch != '' and settings['use_branch']:
            cmd.append('--branch=%s' % branch)
        elif 'default_branch' in settings:
            cmd.append('--branch=%s' % settings['default_branch'])

        if settings['connect_method'] == 'PB':
            cmd.extend([
                '--connect=pb',
                '--passwd=%s' % settings['password'],
            ])
        else:
            #Assume SSH
            cmd.extend([
                '--connect=ssh',
                '--jobdir=%s' % settings['jobdir'],
                '--host=%s' % settings['address'],
            ])

            for builder in settings['builders'].split(','):
                cmd.append('--builder=%s' % builder.strip())

            if settings['buildbotbin'] != '':
                cmd.append('--buildbotbin=%s' % settings['buildbotbin'])

        output = execute(cmd, ignore_errors=True)

        review.body_top = "This is a review from Review Bot.\n"
        review.body_top += "  Tool: %s\n\n" % self.name
        review.body_top += "Buildbot Output:\n%s" % output

        self.post_process(review)
Пример #7
0
    def handle_file(self, f):
        if not f.dest_file.endswith('.py'):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        output = execute(['pyflakes', path],
                         split_lines=True,
                         ignore_errors=True)

        for line in output:
            parsed = line.split(':', 2)
            lnum = int(parsed[1])
            msg = parsed[2]
            f.comment('%s' % (msg, ), lnum)

        return True
Пример #8
0
    def handle_file(self, f):
        if not f.dest_file.lower().endswith('.js'):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        output = execute(
            [
                'js',
                '-e',
                "load('%s'); runJSLint('%s', read('%s'), %s);" % (
                    self.runjslint_path,
                    self.jslint_path,
                    path,
                    json.dumps(self.jslint_options), )
            ],
            split_lines=True,
            ignore_errors=True)

        for line in output:
            try:
                parsed = line.split(':')
                lnum = int(parsed[0])
                col = int(parsed[1])
                msg = parsed[2]
                f.comment('Col: %s\n%s' % (col, msg), lnum)
            except ValueError:
                # A non-numeral was given in the output; don't use it.
                # There was likely an error in processing the .js file.
                # TODO : properly display an error message to the user saying
                #  there was an error processing the file. Also display success
                #  message if there were no errors found by this tool at all
                #  (ie no comments on the review).
                return False

        return True
Пример #9
0
    def handle_file(self, f):
        if not f.dest_file.lower().endswith('.js'):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        output = execute([
            'js', '-e',
            "load('%s'); runJSLint('%s', read('%s'), %s);" % (
                self.runjslint_path,
                self.jslint_path,
                path,
                json.dumps(self.jslint_options),
            )
        ],
                         split_lines=True,
                         ignore_errors=True)

        for line in output:
            try:
                parsed = line.split(':')
                lnum = int(parsed[0])
                col = int(parsed[1])
                msg = parsed[2]
                f.comment('Col: %s\n%s' % (col, msg), lnum)
            except ValueError:
                # A non-numeral was given in the output; don't use it.
                # There was likely an error in processing the .js file.
                # TODO : properly display an error message to the user saying
                #  there was an error processing the file. Also display success
                #  message if there were no errors found by this tool at all
                #  (ie no comments on the review).
                return False

        return True
Пример #10
0
    def handle_file(self, f):
        if not f.dest_file.endswith('.py'):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        output = execute(
            [
                'pyflakes',
                path
            ],
            split_lines=True,
            ignore_errors=True)

        for line in output:
            parsed = line.split(':', 2)
            lnum = int(parsed[1])
            msg = parsed[2]
            f.comment('%s' % (msg, ), lnum)

        return True
Пример #11
0
    def handle_file(self, f):
        if not (f.dest_file.lower().endswith('.cpp') or
                f.dest_file.lower().endswith('.h')):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        # Run the script and capture the output.
        if self.settings['excluded_checks']:
            output = execute(
                [
                    'cpplint',
                    '--verbose=%i' % self.settings['verbosity'],
                    '--filter=%s' % self.settings['excluded_checks'],
                    path
                ],
                split_lines=True,
                ignore_errors=True)
        else:

            output = execute(
                [
                    'cpplint',
                    '--verbose=%i' % self.settings['verbosity'],
                    path
                ],
                split_lines=True,
                ignore_errors=True)

        # Now for each line extract the fields and add a comment to the file.
        for line in output:
            # Regexp to extract the fields from strings like:
            # filename.cpp:126: \
            #   Use int16/int64/etc, rather than the C type long \
            #   [runtime/int] [4]
            # filename.cpp:127: \
            #   Lines should be <= 132 characters long \
            #   [whitespace/line_length] [2]
            # filename.cpp:129: \
            #   Use int16/int64/etc, rather than the C type long \
            #   [runtime/int] [4]
            matching_obj = re.findall(r'(\S+:)(\d+:)(.+?\[)(.+?\])(.+)', line)
            # pre declare all the variables so that they can be used outside
            # the loop if the match (regexp search) worked.
            filename = ""
            linenumber = 0
            freetext = ""
            category = ""
            verbosity = ""
            for match in matching_obj:
                # filename (: stripped from the end)
                filename = match[0][:-1]
                # linenumber (: stripped from the end)
                linenumber = int(match[1][:-1])
                # freetext ( [ stripped from the end)
                freetext = match[2][:-1].strip()
                # category ( ] stripped from the end)
                category = match[3][:-1].strip()
                # verbosity (we just want the number between [])
                verbosity = match[4][2:-1].strip()

            # If we found a matching_obj then the variables will not be empty
            # and thus we can add a comment to this file object.
            if matching_obj:
                f.comment('%s.\n\nError Group: %s\nVerbosity Level: %s' %
                         (freetext, category, verbosity), linenumber)

        return True
Пример #12
0
    def handle_file(self, f):
        if not (f.dest_file.lower().endswith('.cpp') or
                f.dest_file.lower().endswith('.h') or
                f.dest_file.lower().endswith('.c')):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        enabled_checks = []

        # Check the options we want to pass to cppcheck.
        if self.settings['style_checks_enabled']:
            enabled_checks.append('style')

        if self.settings['all_checks_enabled']:
            enabled_checks.append('all')

        # Create string to pass to cppcheck
        enable_settings = '%s' % ','.join(map(str, enabled_checks))

        # Run the script and capture the output.
        output = execute(
            [
                'cppcheck',
                '--template=\"{file}::{line}::{severity}::{id}::{message}\"',
                '--enable=%s' % enable_settings,
                path
            ],
            split_lines=True,
            ignore_errors=True)

        # Now for each line extract the fields and add a comment to the file.
        for line in output:
            # filename.cpp,849,style,unusedFunction, \
            #   The function 'bob' is never used
            # filename.cpp,638,style,unusedFunction, \
            #   The function 'peter' is never used
            # filename.cpp,722,style,unusedFunction,
            #   The function 'test' is never used
            parsed = line.split('::')

            # If we have a useful message
            if len(parsed) == 5:
                # Sometimes we dont gets a linenumber (just and empty string)
                # Catch this case and set line number to 0.
                if parsed[1]:
                    linenumber = int(parsed[1])
                else:
                    linenumber = 0

                # Now extract the other options.
                category = parsed[2]
                sub_category = parsed[3]
                freetext = parsed[4][:-1]  # strip the " from the end

                # If the message is that its an error then override the
                # default settings and raise an Issue otherwise just
                # add a comment.
                if category == 'error':
                    f.comment('%s.\n\nCategory: %s\nSub Category: %s' %
                             (freetext, category, sub_category),
                              linenumber, issue=True)
                else:
                    f.comment('%s.\n\nCategory: %s\nSub Category: %s' %
                             (freetext, category, sub_category),
                              linenumber, issue=False)

        return True
Пример #13
0
    def handle_file(self, f):
        if not (f.dest_file.lower().endswith('.cpp')
                or f.dest_file.lower().endswith('.h')):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        # Run the script and capture the output.
        if self.settings['excluded_checks']:
            output = execute([
                'cpplint',
                '--verbose=%i' % self.settings['verbosity'],
                '--filter=%s' % self.settings['excluded_checks'], path
            ],
                             split_lines=True,
                             ignore_errors=True)
        else:

            output = execute(
                ['cpplint',
                 '--verbose=%i' % self.settings['verbosity'], path],
                split_lines=True,
                ignore_errors=True)

        # Now for each line extract the fields and add a comment to the file.
        for line in output:
            # Regexp to extract the fields from strings like:
            # filename.cpp:126: \
            #   Use int16/int64/etc, rather than the C type long \
            #   [runtime/int] [4]
            # filename.cpp:127: \
            #   Lines should be <= 132 characters long \
            #   [whitespace/line_length] [2]
            # filename.cpp:129: \
            #   Use int16/int64/etc, rather than the C type long \
            #   [runtime/int] [4]
            matching_obj = re.findall(r'(\S+:)(\d+:)(.+?\[)(.+?\])(.+)', line)
            # pre declare all the variables so that they can be used outside
            # the loop if the match (regexp search) worked.
            filename = ""
            linenumber = 0
            freetext = ""
            category = ""
            verbosity = ""
            for match in matching_obj:
                # filename (: stripped from the end)
                filename = match[0][:-1]
                # linenumber (: stripped from the end)
                linenumber = int(match[1][:-1])
                # freetext ( [ stripped from the end)
                freetext = match[2][:-1].strip()
                # category ( ] stripped from the end)
                category = match[3][:-1].strip()
                # verbosity (we just want the number between [])
                verbosity = match[4][2:-1].strip()

            # If we found a matching_obj then the variables will not be empty
            # and thus we can add a comment to this file object.
            if matching_obj:
                f.comment(
                    '%s.\n\nError Group: %s\nVerbosity Level: %s' %
                    (freetext, category, verbosity), linenumber)

        return True
Пример #14
0
    def handle_file(self, f):
        if not (f.dest_file.lower().endswith('.cpp')
                or f.dest_file.lower().endswith('.h')
                or f.dest_file.lower().endswith('.c')):
            # Ignore the file.
            return False

        path = f.get_patched_file_path()
        if not path:
            return False

        enabled_checks = []

        # Check the options we want to pass to cppcheck.
        if self.settings['style_checks_enabled']:
            enabled_checks.append('style')

        if self.settings['all_checks_enabled']:
            enabled_checks.append('all')

        # Create string to pass to cppcheck
        enable_settings = '%s' % ','.join(map(str, enabled_checks))

        # Run the script and capture the output.
        output = execute([
            'cppcheck',
            '--template=\"{file}::{line}::{severity}::{id}::{message}\"',
            '--enable=%s' % enable_settings, path
        ],
                         split_lines=True,
                         ignore_errors=True)

        # Now for each line extract the fields and add a comment to the file.
        for line in output:
            # filename.cpp,849,style,unusedFunction, \
            #   The function 'bob' is never used
            # filename.cpp,638,style,unusedFunction, \
            #   The function 'peter' is never used
            # filename.cpp,722,style,unusedFunction,
            #   The function 'test' is never used
            parsed = line.split('::')

            # If we have a useful message
            if len(parsed) == 5:
                # Sometimes we dont gets a linenumber (just and empty string)
                # Catch this case and set line number to 0.
                if parsed[1]:
                    linenumber = int(parsed[1])
                else:
                    linenumber = 0

                # Now extract the other options.
                category = parsed[2]
                sub_category = parsed[3]
                freetext = parsed[4][:-1]  # strip the " from the end

                # If the message is that its an error then override the
                # default settings and raise an Issue otherwise just
                # add a comment.
                if category == 'error':
                    f.comment('%s.\n\nCategory: %s\nSub Category: %s' %
                              (freetext, category, sub_category),
                              linenumber,
                              issue=True)
                else:
                    f.comment('%s.\n\nCategory: %s\nSub Category: %s' %
                              (freetext, category, sub_category),
                              linenumber,
                              issue=False)

        return True