| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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.0.1' | 9 __version__ = '1.0.1' |
| 10 | 10 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 self.marshal = marshal | 174 self.marshal = marshal |
| 175 self.re = re | 175 self.re = re |
| 176 self.subprocess = subprocess | 176 self.subprocess = subprocess |
| 177 self.tempfile = tempfile | 177 self.tempfile = tempfile |
| 178 self.urllib2 = urllib2 | 178 self.urllib2 = urllib2 |
| 179 | 179 |
| 180 # InputApi.platform is the platform you're currently running on. | 180 # InputApi.platform is the platform you're currently running on. |
| 181 self.platform = sys.platform | 181 self.platform = sys.platform |
| 182 | 182 |
| 183 # The local path of the currently-being-processed presubmit script. | 183 # The local path of the currently-being-processed presubmit script. |
| 184 self.current_presubmit_path = presubmit_path | 184 self._current_presubmit_path = os.path.dirname(presubmit_path) |
| 185 | 185 |
| 186 # We carry the canned checks so presubmit scripts can easily use them. | 186 # We carry the canned checks so presubmit scripts can easily use them. |
| 187 self.canned_checks = presubmit_canned_checks | 187 self.canned_checks = presubmit_canned_checks |
| 188 | 188 |
| 189 def PresubmitLocalPath(self): | 189 def PresubmitLocalPath(self): |
| 190 """Returns the local path of the presubmit script currently being run. | 190 """Returns the local path of the presubmit script currently being run. |
| 191 | 191 |
| 192 This is useful if you don't want to hard-code absolute paths in the | 192 This is useful if you don't want to hard-code absolute paths in the |
| 193 presubmit script. For example, It can be used to find another file | 193 presubmit script. For example, It can be used to find another file |
| 194 relative to the PRESUBMIT.py script, so the whole tree can be branched and | 194 relative to the PRESUBMIT.py script, so the whole tree can be branched and |
| 195 the presubmit script still works, without editing its content. | 195 the presubmit script still works, without editing its content. |
| 196 """ | 196 """ |
| 197 return self.current_presubmit_path | 197 return self._current_presubmit_path |
| 198 | 198 |
| 199 @staticmethod | 199 @staticmethod |
| 200 def DepotToLocalPath(depot_path): | 200 def DepotToLocalPath(depot_path): |
| 201 """Translate a depot path to a local path (relative to client root). | 201 """Translate a depot path to a local path (relative to client root). |
| 202 | 202 |
| 203 Args: | 203 Args: |
| 204 Depot path as a string. | 204 Depot path as a string. |
| 205 | 205 |
| 206 Returns: | 206 Returns: |
| 207 The local path of the depot path under the user's current client, or None | 207 The local path of the depot path under the user's current client, or None |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 if not mime_type or mime_type.startswith('text/'): | 251 if not mime_type or mime_type.startswith('text/'): |
| 252 output_files.append(af) | 252 output_files.append(af) |
| 253 return output_files | 253 return output_files |
| 254 | 254 |
| 255 def AffectedFiles(self, include_dirs=False, include_deletes=True): | 255 def AffectedFiles(self, include_dirs=False, include_deletes=True): |
| 256 """Same as input_api.change.AffectedFiles() except only lists files | 256 """Same as input_api.change.AffectedFiles() except only lists files |
| 257 (and optionally directories) in the same directory as the current presubmit | 257 (and optionally directories) in the same directory as the current presubmit |
| 258 script, or subdirectories thereof. | 258 script, or subdirectories thereof. |
| 259 """ | 259 """ |
| 260 output_files = [] | 260 output_files = [] |
| 261 dir_with_slash = normpath( | 261 dir_with_slash = normpath("%s/" % self.PresubmitLocalPath()) |
| 262 "%s/" % os.path.dirname(self.current_presubmit_path)) | |
| 263 if len(dir_with_slash) == 1: | 262 if len(dir_with_slash) == 1: |
| 264 dir_with_slash = '' | 263 dir_with_slash = '' |
| 265 for af in self.change.AffectedFiles(include_dirs, include_deletes): | 264 for af in self.change.AffectedFiles(include_dirs, include_deletes): |
| 266 af_path = normpath(af.LocalPath()) | 265 af_path = normpath(af.LocalPath()) |
| 267 if af_path.startswith(dir_with_slash): | 266 if af_path.startswith(dir_with_slash): |
| 268 output_files.append(af) | 267 output_files.append(af) |
| 269 return output_files | 268 return output_files |
| 270 | 269 |
| 271 def LocalPaths(self, include_dirs=False): | 270 def LocalPaths(self, include_dirs=False): |
| 272 """Returns local paths of input_api.AffectedFiles().""" | 271 """Returns local paths of input_api.AffectedFiles().""" |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 | 622 |
| 624 Return: | 623 Return: |
| 625 True if execution can continue, False if not. | 624 True if execution can continue, False if not. |
| 626 """ | 625 """ |
| 627 presubmit_files = ListRelevantPresubmitFiles(change_info.FileList()) | 626 presubmit_files = ListRelevantPresubmitFiles(change_info.FileList()) |
| 628 if not presubmit_files and verbose: | 627 if not presubmit_files and verbose: |
| 629 print "Warning, no presubmit.py found." | 628 print "Warning, no presubmit.py found." |
| 630 results = [] | 629 results = [] |
| 631 executer = PresubmitExecuter(change_info, committing) | 630 executer = PresubmitExecuter(change_info, committing) |
| 632 for filename in presubmit_files: | 631 for filename in presubmit_files: |
| 632 filename = os.path.abspath(filename) |
| 633 if verbose: | 633 if verbose: |
| 634 print "Running %s" % filename | 634 print "Running %s" % filename |
| 635 # Accept CRLF presubmit script. | 635 # Accept CRLF presubmit script. |
| 636 presubmit_script = gcl.ReadFile(filename, 'rU') | 636 presubmit_script = gcl.ReadFile(filename, 'rU') |
| 637 results += executer.ExecPresubmitScript(presubmit_script, filename) | 637 results += executer.ExecPresubmitScript(presubmit_script, filename) |
| 638 | 638 |
| 639 errors = [] | 639 errors = [] |
| 640 notifications = [] | 640 notifications = [] |
| 641 warnings = [] | 641 warnings = [] |
| 642 for result in results: | 642 for result in results: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 print "Found %d files." % len(files) | 703 print "Found %d files." % len(files) |
| 704 return DoPresubmitChecks(gcl.ChangeInfo(name='temp', files=files), | 704 return DoPresubmitChecks(gcl.ChangeInfo(name='temp', files=files), |
| 705 options.commit, | 705 options.commit, |
| 706 options.verbose, | 706 options.verbose, |
| 707 sys.stdout, | 707 sys.stdout, |
| 708 sys.stdin) | 708 sys.stdin) |
| 709 | 709 |
| 710 | 710 |
| 711 if __name__ == '__main__': | 711 if __name__ == '__main__': |
| 712 sys.exit(Main(sys.argv)) | 712 sys.exit(Main(sys.argv)) |
| OLD | NEW |