OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """ Newline checking step """ | |
7 | |
8 import os | |
9 import sys | |
10 | |
11 | |
12 _FILE_SUFFIXES_TO_CHECK = ['.cpp', '.h', '.c'] | |
13 | |
14 _SUBDIRS_TO_IGNORE = ['.svn', 'third_party'] | |
15 | |
16 | |
17 def NewlineChecker(): | |
18 files_without_trailing_newlines = _ListFiles( | |
19 os.getcwd()) # Assuming current directory is trunk. | |
20 if files_without_trailing_newlines: | |
21 raise Exception( | |
22 'The following file(s) have no newlines at the end:\n %s' % ( | |
23 '\n'.join(files_without_trailing_newlines))) | |
24 | |
25 | |
26 def _ListFiles(directory): | |
27 files_without_trailing_newlines = [] | |
28 for item in os.listdir(directory): | |
29 full_item_path = os.path.join(directory, item) | |
30 if os.path.isfile(full_item_path): | |
31 for suffix in _FILE_SUFFIXES_TO_CHECK: | |
32 if item.endswith(suffix): | |
33 file_content = file(full_item_path).read() | |
34 if file_content and file_content[-1] != '\n': | |
35 files_without_trailing_newlines.append(full_item_path) | |
36 elif item not in _SUBDIRS_TO_IGNORE: | |
37 files_without_trailing_newlines.extend(_ListFiles(full_item_path)) | |
38 return files_without_trailing_newlines | |
39 | |
40 | |
41 if '__main__' == __name__: | |
42 sys.exit(NewlineChecker()) | |
43 | |
OLD | NEW |