OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Enables directory-specific presubmit checks to run at upload and/or commit. | 6 """Enables directory-specific presubmit checks to run at upload and/or commit. |
7 """ | 7 """ |
8 | 8 |
9 __version__ = '1.6.1' | 9 __version__ = '1.6.1' |
10 | 10 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 Args: | 307 Args: |
308 Local path (relative to current directory, or absolute) as a string. | 308 Local path (relative to current directory, or absolute) as a string. |
309 | 309 |
310 Returns: | 310 Returns: |
311 The depot path (SVN URL) of the file if mapped, otherwise None. | 311 The depot path (SVN URL) of the file if mapped, otherwise None. |
312 """ | 312 """ |
313 depot_path = scm.SVN.CaptureInfo(local_path).get('URL') | 313 depot_path = scm.SVN.CaptureInfo(local_path).get('URL') |
314 if depot_path: | 314 if depot_path: |
315 return depot_path | 315 return depot_path |
316 | 316 |
317 def AffectedFiles(self, include_dirs=False, include_deletes=True): | 317 def AffectedFiles(self, include_dirs=False, include_deletes=True, |
| 318 file_filter=None): |
318 """Same as input_api.change.AffectedFiles() except only lists files | 319 """Same as input_api.change.AffectedFiles() except only lists files |
319 (and optionally directories) in the same directory as the current presubmit | 320 (and optionally directories) in the same directory as the current presubmit |
320 script, or subdirectories thereof. | 321 script, or subdirectories thereof. |
321 """ | 322 """ |
322 dir_with_slash = normpath("%s/" % self.PresubmitLocalPath()) | 323 dir_with_slash = normpath("%s/" % self.PresubmitLocalPath()) |
323 if len(dir_with_slash) == 1: | 324 if len(dir_with_slash) == 1: |
324 dir_with_slash = '' | 325 dir_with_slash = '' |
| 326 |
325 return filter( | 327 return filter( |
326 lambda x: normpath(x.AbsoluteLocalPath()).startswith(dir_with_slash), | 328 lambda x: normpath(x.AbsoluteLocalPath()).startswith(dir_with_slash), |
327 self.change.AffectedFiles(include_dirs, include_deletes)) | 329 self.change.AffectedFiles(include_dirs, include_deletes, file_filter)) |
328 | 330 |
329 def LocalPaths(self, include_dirs=False): | 331 def LocalPaths(self, include_dirs=False): |
330 """Returns local paths of input_api.AffectedFiles().""" | 332 """Returns local paths of input_api.AffectedFiles().""" |
331 return [af.LocalPath() for af in self.AffectedFiles(include_dirs)] | 333 return [af.LocalPath() for af in self.AffectedFiles(include_dirs)] |
332 | 334 |
333 def AbsoluteLocalPaths(self, include_dirs=False): | 335 def AbsoluteLocalPaths(self, include_dirs=False): |
334 """Returns absolute local paths of input_api.AffectedFiles().""" | 336 """Returns absolute local paths of input_api.AffectedFiles().""" |
335 return [af.AbsoluteLocalPath() for af in self.AffectedFiles(include_dirs)] | 337 return [af.AbsoluteLocalPath() for af in self.AffectedFiles(include_dirs)] |
336 | 338 |
337 def ServerPaths(self, include_dirs=False): | 339 def ServerPaths(self, include_dirs=False): |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 as an absolute path. | 710 as an absolute path. |
709 """ | 711 """ |
710 return self._local_root | 712 return self._local_root |
711 | 713 |
712 def __getattr__(self, attr): | 714 def __getattr__(self, attr): |
713 """Return tags directly as attributes on the object.""" | 715 """Return tags directly as attributes on the object.""" |
714 if not re.match(r"^[A-Z_]*$", attr): | 716 if not re.match(r"^[A-Z_]*$", attr): |
715 raise AttributeError(self, attr) | 717 raise AttributeError(self, attr) |
716 return self.tags.get(attr) | 718 return self.tags.get(attr) |
717 | 719 |
718 def AffectedFiles(self, include_dirs=False, include_deletes=True): | 720 def AffectedFiles(self, include_dirs=False, include_deletes=True, |
| 721 file_filter=None): |
719 """Returns a list of AffectedFile instances for all files in the change. | 722 """Returns a list of AffectedFile instances for all files in the change. |
720 | 723 |
721 Args: | 724 Args: |
722 include_deletes: If false, deleted files will be filtered out. | 725 include_deletes: If false, deleted files will be filtered out. |
723 include_dirs: True to include directories in the list | 726 include_dirs: True to include directories in the list |
| 727 file_filter: An additional filter to apply. |
724 | 728 |
725 Returns: | 729 Returns: |
726 [AffectedFile(path, action), AffectedFile(path, action)] | 730 [AffectedFile(path, action), AffectedFile(path, action)] |
727 """ | 731 """ |
728 if include_dirs: | 732 if include_dirs: |
729 affected = self._affected_files | 733 affected = self._affected_files |
730 else: | 734 else: |
731 affected = filter(lambda x: not x.IsDirectory(), self._affected_files) | 735 affected = filter(lambda x: not x.IsDirectory(), self._affected_files) |
732 | 736 |
| 737 affected = filter(file_filter, affected) |
| 738 |
733 if include_deletes: | 739 if include_deletes: |
734 return affected | 740 return affected |
735 else: | 741 else: |
736 return filter(lambda x: x.Action() != 'D', affected) | 742 return filter(lambda x: x.Action() != 'D', affected) |
737 | 743 |
738 def AffectedTextFiles(self, include_deletes=None): | 744 def AffectedTextFiles(self, include_deletes=None): |
739 """Return a list of the existing text files in a change.""" | 745 """Return a list of the existing text files in a change.""" |
740 if include_deletes is not None: | 746 if include_deletes is not None: |
741 warn("AffectedTextFiles(include_deletes=%s)" | 747 warn("AffectedTextFiles(include_deletes=%s)" |
742 " is deprecated and ignored" % str(include_deletes), | 748 " is deprecated and ignored" % str(include_deletes), |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 except PresubmitFailure, e: | 1227 except PresubmitFailure, e: |
1222 print >> sys.stderr, e | 1228 print >> sys.stderr, e |
1223 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1229 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
1224 print >> sys.stderr, 'If all fails, contact maruel@' | 1230 print >> sys.stderr, 'If all fails, contact maruel@' |
1225 return 2 | 1231 return 2 |
1226 | 1232 |
1227 | 1233 |
1228 if __name__ == '__main__': | 1234 if __name__ == '__main__': |
1229 fix_encoding.fix_encoding() | 1235 fix_encoding.fix_encoding() |
1230 sys.exit(Main(None)) | 1236 sys.exit(Main(None)) |
OLD | NEW |