OLD | NEW |
1 # Copyright (C) 2009 Google Inc. All rights reserved. | 1 # Copyright (C) 2009 Google Inc. All rights reserved. |
2 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) | 2 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) |
3 # Copyright (C) 2010 ProFUSION embedded systems | 3 # Copyright (C) 2010 ProFUSION embedded systems |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 to the processor's process() method. The process() | 105 to the processor's process() method. The process() |
106 method should support these keyword arguments. | 106 method should support these keyword arguments. |
107 | 107 |
108 Raises: | 108 Raises: |
109 SystemExit: If no file at file_path exists. | 109 SystemExit: If no file at file_path exists. |
110 | 110 |
111 """ | 111 """ |
112 self.file_count += 1 | 112 self.file_count += 1 |
113 | 113 |
114 if not self.filesystem.exists(file_path) and file_path != "-": | 114 if not self.filesystem.exists(file_path) and file_path != "-": |
115 _log.error("File does not exist: '%s'" % file_path) | 115 _log.error("File does not exist: '%s'", file_path) |
116 sys.exit(1) # FIXME: This should throw or return instead of exiting
directly. | 116 sys.exit(1) # FIXME: This should throw or return instead of exiting
directly. |
117 | 117 |
118 if not self._processor.should_process(file_path): | 118 if not self._processor.should_process(file_path): |
119 _log.debug("Skipping file: '%s'" % file_path) | 119 _log.debug("Skipping file: '%s'", file_path) |
120 return | 120 return |
121 _log.debug("Processing file: '%s'" % file_path) | 121 _log.debug("Processing file: '%s'", file_path) |
122 | 122 |
123 try: | 123 try: |
124 lines = self._read_lines(file_path) | 124 lines = self._read_lines(file_path) |
125 except IOError as err: | 125 except IOError as err: |
126 message = ("Could not read file. Skipping: '%s'\n %s" % (file_path,
err)) | 126 message = ("Could not read file. Skipping: '%s'\n %s" % (file_path,
err)) |
127 _log.warn(message) | 127 _log.warning(message) |
128 return | 128 return |
129 | 129 |
130 self._processor.process(lines, file_path, **kwargs) | 130 self._processor.process(lines, file_path, **kwargs) |
131 | 131 |
132 def _process_directory(self, directory): | 132 def _process_directory(self, directory): |
133 """Process all files in the given directory, recursively.""" | 133 """Process all files in the given directory, recursively.""" |
134 # FIXME: We should consider moving to self.filesystem.files_under() (or
adding walk() to FileSystem) | 134 # FIXME: We should consider moving to self.filesystem.files_under() (or
adding walk() to FileSystem) |
135 for dir_path, _, file_names in os.walk(directory): | 135 for dir_path, _, file_names in os.walk(directory): |
136 for file_name in file_names: | 136 for file_name in file_names: |
137 file_path = self.filesystem.join(dir_path, file_name) | 137 file_path = self.filesystem.join(dir_path, file_name) |
138 self.process_file(file_path) | 138 self.process_file(file_path) |
139 | 139 |
140 def process_paths(self, paths): | 140 def process_paths(self, paths): |
141 for path in paths: | 141 for path in paths: |
142 if self.filesystem.isdir(path): | 142 if self.filesystem.isdir(path): |
143 self._process_directory(directory=path) | 143 self._process_directory(directory=path) |
144 else: | 144 else: |
145 self.process_file(path) | 145 self.process_file(path) |
146 | 146 |
147 def count_delete_only_file(self): | 147 def count_delete_only_file(self): |
148 """Count up files that contains only deleted lines. | 148 """Count up files that contains only deleted lines. |
149 | 149 |
150 Files which has no modified or newly-added lines don't need | 150 Files which has no modified or newly-added lines don't need |
151 to check style, but should be treated as checked. For that | 151 to check style, but should be treated as checked. For that |
152 purpose, we just count up the number of such files. | 152 purpose, we just count up the number of such files. |
153 """ | 153 """ |
154 self.delete_only_file_count += 1 | 154 self.delete_only_file_count += 1 |
OLD | NEW |