Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: presubmit_support.py

Issue 118370: Add InputApi.ReadFile() and presubmit_canned_checks.CheckChangeHasNoCR(). (Closed)
Patch Set: Use mode 'rb' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « presubmit_canned_checks.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.3' 9 __version__ = '1.3.1'
10 10
11 # TODO(joi) Add caching where appropriate/needed. The API is designed to allow 11 # TODO(joi) Add caching where appropriate/needed. The API is designed to allow
12 # caching (between all different invocations of presubmit scripts for a given 12 # caching (between all different invocations of presubmit scripts for a given
13 # change). We should add it as our presubmit scripts start feeling slow. 13 # change). We should add it as our presubmit scripts start feeling slow.
14 14
15 import cPickle # Exposed through the API. 15 import cPickle # Exposed through the API.
16 import cStringIO # Exposed through the API. 16 import cStringIO # Exposed through the API.
17 import exceptions 17 import exceptions
18 import fnmatch 18 import fnmatch
19 import glob 19 import glob
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 the AffectedFile instance of the current file; 264 the AffectedFile instance of the current file;
265 integer line number (1-based); and 265 integer line number (1-based); and
266 the contents of the line as a string. 266 the contents of the line as a string.
267 267
268 Note: The cariage return (LF or CR) is stripped off. 268 Note: The cariage return (LF or CR) is stripped off.
269 """ 269 """
270 return InputApi._RightHandSideLinesImpl( 270 return InputApi._RightHandSideLinesImpl(
271 filter(lambda x: x.IsTextFile(), 271 filter(lambda x: x.IsTextFile(),
272 self.AffectedFiles(include_deletes=False))) 272 self.AffectedFiles(include_deletes=False)))
273 273
274 def ReadFile(self, file, mode='r'):
275 """Reads an arbitrary file.
276
277 Deny reading anything outside the repository."""
Jói Sigurðsson 2009/06/08 10:52:50 For consistency with the rest of the code, please
278 if isinstance(file, AffectedFile):
279 file = file.AbsoluteLocalPath()
280 if not file.startswith(self.change.RepositoryRoot()):
281 raise IOError('Access outside the repository root is denied.')
282 return gcl.ReadFile(file, mode)
283
274 @staticmethod 284 @staticmethod
275 def _RightHandSideLinesImpl(affected_files): 285 def _RightHandSideLinesImpl(affected_files):
276 """Implements RightHandSideLines for InputApi and GclChange.""" 286 """Implements RightHandSideLines for InputApi and GclChange."""
277 for af in affected_files: 287 for af in affected_files:
278 lines = af.NewContents() 288 lines = af.NewContents()
279 line_number = 0 289 line_number = 0
280 for line in lines: 290 for line in lines:
281 line_number += 1 291 line_number += 1
282 yield (af, line_number, line) 292 yield (af, line_number, line)
283 293
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 return not DoPresubmitChecks(gcl.ChangeInfo('No name', 0, 0, '', files), 744 return not DoPresubmitChecks(gcl.ChangeInfo('No name', 0, 0, '', files),
735 options.commit, 745 options.commit,
736 options.verbose, 746 options.verbose,
737 sys.stdout, 747 sys.stdout,
738 sys.stdin, 748 sys.stdin,
739 default_presubmit=None) 749 default_presubmit=None)
740 750
741 751
742 if __name__ == '__main__': 752 if __name__ == '__main__':
743 sys.exit(Main(sys.argv)) 753 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « presubmit_canned_checks.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698