コード例 #1
0
    def _lint(self, file_name, print_diff):
        """Check the specified file has the correct format
        """
        with open(file_name, 'rb') as original_text:
            original_file = original_text.read()

        # Get formatted file as clang-format would format the file
        formatted_file = callo([self.clang_path, "--style=file", file_name])

        if original_file != formatted_file:
            if print_diff:
                original_lines = original_file.splitlines()
                formatted_lines = formatted_file.splitlines()
                result = difflib.unified_diff(original_lines, formatted_lines)

                # Take a lock to ensure diffs do not get mixed when printed to
                # the screen
                with self.print_lock:
                    logger.error("Found diff for " + file_name)
                    logger.info("To fix formatting errors, run %s "
                                "--style=file -i %s" % (self.clang_path,
                                                        file_name))
                    for line in result:
                        logger.info(line.rstrip())

            return False

        return True
コード例 #2
0
ファイル: clang_format.py プロジェクト: yangshuo11/mrpt
    def _validate_version(self):
        """Validate clang-format is the expected version
        """
        cf_version = callo([self.clang_path, "--version"])

        # JLBC: Disable version checks and just use the version we find:
        return True
コード例 #3
0
ファイル: clang_format.py プロジェクト: jiapei100/mrpt
    def _validate_version(self):
        """Validate clang-format is the expected version
        """
        cf_version = callo([self.clang_path, "--version"])
        logger.warn("Using clang-format version: %s" % cf_version)

        # JLBC: Disable version checks and just use the version we find:
        return True
コード例 #4
0
 def _callgito(self, args):
     """Call git for this repository, and return the captured output
     """
     # These two flags are the equivalent of -C in newer versions of Git but
     # we use these to support versions pre 1.8.5 but it depends on the
     # command and what the current directory is
     return callo([
         'git', '--git-dir',
         os.path.join(self.path, ".git"), '--work-tree', self.path
     ] + args)
コード例 #5
0
ファイル: repo.py プロジェクト: Jarlene/mrpt
 def _callgito(self, args):
     """Call git for this repository, and return the captured output
     """
     # These two flags are the equivalent of -C in newer versions of Git but
     # we use these to support versions pre 1.8.5 but it depends on the
     # command and what the current directory is
     return callo([
         'git', '--git-dir',
         os.path.join(self.path, ".git"), '--work-tree', self.path
     ] + args)
コード例 #6
0
    def _validate_version(self):
        """Validate clang-format is the expected version
        """
        cf_version = callo([self.clang_path, "--version"])

        if CLANG_FORMAT_VERSION in cf_version:
            return True

        logger.warn("clang-format found in path, "
                    "but incorrect version found at " + self.clang_path +
                    " with version: " + cf_version)

        return False