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

Side by Side Diff: presubmit_support.py

Issue 385007: Run pychecker over most scripts in depot_tools. Catched a few bugs. (Closed)
Patch Set: . Created 11 years, 1 month 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
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.3' 9 __version__ = '1.3.3'
10 10
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 a 3 tuple: 338 a 3 tuple:
339 the AffectedFile instance of the current file; 339 the AffectedFile instance of the current file;
340 integer line number (1-based); and 340 integer line number (1-based); and
341 the contents of the line as a string. 341 the contents of the line as a string.
342 342
343 Note: The cariage return (LF or CR) is stripped off. 343 Note: The cariage return (LF or CR) is stripped off.
344 """ 344 """
345 files = self.AffectedSourceFiles(source_file_filter) 345 files = self.AffectedSourceFiles(source_file_filter)
346 return InputApi._RightHandSideLinesImpl(files) 346 return InputApi._RightHandSideLinesImpl(files)
347 347
348 def ReadFile(self, file, mode='r'): 348 def ReadFile(self, file_item, mode='r'):
349 """Reads an arbitrary file. 349 """Reads an arbitrary file.
350 350
351 Deny reading anything outside the repository. 351 Deny reading anything outside the repository.
352 """ 352 """
353 if isinstance(file, AffectedFile): 353 if isinstance(file_item, AffectedFile):
354 file = file.AbsoluteLocalPath() 354 file_item = file_item.AbsoluteLocalPath()
355 if not file.startswith(self.change.RepositoryRoot()): 355 if not file_item.startswith(self.change.RepositoryRoot()):
356 raise IOError('Access outside the repository root is denied.') 356 raise IOError('Access outside the repository root is denied.')
357 return gcl.ReadFile(file, mode) 357 return gcl.ReadFile(file_item, mode)
358 358
359 @staticmethod 359 @staticmethod
360 def _RightHandSideLinesImpl(affected_files): 360 def _RightHandSideLinesImpl(affected_files):
361 """Implements RightHandSideLines for InputApi and GclChange.""" 361 """Implements RightHandSideLines for InputApi and GclChange."""
362 for af in affected_files: 362 for af in affected_files:
363 lines = af.NewContents() 363 lines = af.NewContents()
364 line_number = 0 364 line_number = 0
365 for line in lines: 365 for line in lines:
366 line_number += 1 366 line_number += 1
367 yield (af, line_number, line) 367 yield (af, line_number, line)
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 dirs.remove('.git') 982 dirs.remove('.git')
983 for name in files: 983 for name in files:
984 if fnmatch.fnmatch(name, mask): 984 if fnmatch.fnmatch(name, mask):
985 results.append(os.path.join(root, name)) 985 results.append(os.path.join(root, name))
986 return results 986 return results
987 987
988 988
989 def ParseFiles(args, recursive): 989 def ParseFiles(args, recursive):
990 files = [] 990 files = []
991 for arg in args: 991 for arg in args:
992 files.extend([('M', file) for file in ScanSubDirs(arg, recursive)]) 992 files.extend([('M', f) for f in ScanSubDirs(arg, recursive)])
993 return files 993 return files
994 994
995 995
996 def Main(argv): 996 def Main(argv):
997 parser = optparse.OptionParser(usage="%prog [options]", 997 parser = optparse.OptionParser(usage="%prog [options]",
998 version="%prog " + str(__version__)) 998 version="%prog " + str(__version__))
999 parser.add_option("-c", "--commit", action="store_true", default=False, 999 parser.add_option("-c", "--commit", action="store_true", default=False,
1000 help="Use commit instead of upload checks") 1000 help="Use commit instead of upload checks")
1001 parser.add_option("-u", "--upload", action="store_false", dest='commit', 1001 parser.add_option("-u", "--upload", action="store_false", dest='commit',
1002 help="Use upload instead of commit checks") 1002 help="Use upload instead of commit checks")
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 options.commit, 1048 options.commit,
1049 options.verbose, 1049 options.verbose,
1050 sys.stdout, 1050 sys.stdout,
1051 sys.stdin, 1051 sys.stdin,
1052 options.default_presubmit, 1052 options.default_presubmit,
1053 options.may_prompt) 1053 options.may_prompt)
1054 1054
1055 1055
1056 if __name__ == '__main__': 1056 if __name__ == '__main__':
1057 sys.exit(Main(sys.argv)) 1057 sys.exit(Main(sys.argv))
OLDNEW
« gclient.py ('K') | « presubmit_canned_checks.py ('k') | tests/gcl_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698