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

Side by Side Diff: tools/presubmit.py

Issue 3026030: Use hashlib module instead of md5 if it is present. (Closed)
Patch Set: Created 10 years, 4 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 | « no previous file | no next file » | 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/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2008 the V8 project authors. All rights reserved. 3 # Copyright 2008 the V8 project authors. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following 11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided 12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution. 13 # with the distribution.
14 # * Neither the name of Google Inc. nor the names of its 14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived 15 # contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission. 16 # from this software without specific prior written permission.
17 # 17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 try:
31 import hashlib
32 md5er = hashlib.md5
33 except ImportError, e:
34 import md5
35 md5er = md5.new
30 36
31 import md5 37
32 import optparse 38 import optparse
33 import os 39 import os
34 from os.path import abspath, join, dirname, basename, exists 40 from os.path import abspath, join, dirname, basename, exists
35 import pickle 41 import pickle
36 import re 42 import re
37 import sys 43 import sys
38 import subprocess 44 import subprocess
39 45
40 # Disabled LINT rules and reason. 46 # Disabled LINT rules and reason.
41 # build/include_what_you_use: Started giving false positives for variables 47 # build/include_what_you_use: Started giving false positives for variables
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 sums_file = open(self.sums_file_name, 'w') 125 sums_file = open(self.sums_file_name, 'w')
120 pickle.dump(self.sums, sums_file) 126 pickle.dump(self.sums, sums_file)
121 finally: 127 finally:
122 sums_file.close() 128 sums_file.close()
123 129
124 def FilterUnchangedFiles(self, files): 130 def FilterUnchangedFiles(self, files):
125 changed_or_new = [] 131 changed_or_new = []
126 for file in files: 132 for file in files:
127 try: 133 try:
128 handle = open(file, "r") 134 handle = open(file, "r")
129 file_sum = md5.new(handle.read()).digest() 135 file_sum = md5er(handle.read()).digest()
130 if not file in self.sums or self.sums[file] != file_sum: 136 if not file in self.sums or self.sums[file] != file_sum:
131 changed_or_new.append(file) 137 changed_or_new.append(file)
132 self.sums[file] = file_sum 138 self.sums[file] = file_sum
133 finally: 139 finally:
134 handle.close() 140 handle.close()
135 return changed_or_new 141 return changed_or_new
136 142
137 def RemoveFile(self, file): 143 def RemoveFile(self, file):
138 if file in self.sums: 144 if file in self.sums:
139 self.sums.pop(file) 145 self.sums.pop(file)
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 success = CppLintProcessor().Run(workspace) and success 296 success = CppLintProcessor().Run(workspace) and success
291 success = SourceProcessor().Run(workspace) and success 297 success = SourceProcessor().Run(workspace) and success
292 if success: 298 if success:
293 return 0 299 return 0
294 else: 300 else:
295 return 1 301 return 1
296 302
297 303
298 if __name__ == '__main__': 304 if __name__ == '__main__':
299 sys.exit(Main()) 305 sys.exit(Main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698