OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2012 the V8 project authors. All rights reserved. | 3 # Copyright 2012 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 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 def __init__(self, sums_file_name): | 137 def __init__(self, sums_file_name): |
138 self.sums = {} | 138 self.sums = {} |
139 self.sums_file_name = sums_file_name | 139 self.sums_file_name = sums_file_name |
140 | 140 |
141 def Load(self): | 141 def Load(self): |
142 try: | 142 try: |
143 sums_file = None | 143 sums_file = None |
144 try: | 144 try: |
145 sums_file = open(self.sums_file_name, 'r') | 145 sums_file = open(self.sums_file_name, 'r') |
146 self.sums = pickle.load(sums_file) | 146 self.sums = pickle.load(sums_file) |
147 except IOError: | 147 except: |
148 # File might not exist, this is OK. | 148 # Cannot parse pickle for any reason. Not much we can do about it. |
149 pass | 149 pass |
150 finally: | 150 finally: |
151 if sums_file: | 151 if sums_file: |
152 sums_file.close() | 152 sums_file.close() |
153 | 153 |
154 def Save(self): | 154 def Save(self): |
155 try: | 155 try: |
156 sums_file = open(self.sums_file_name, 'w') | 156 sums_file = open(self.sums_file_name, 'w') |
157 pickle.dump(self.sums, sums_file) | 157 pickle.dump(self.sums, sums_file) |
| 158 except: |
| 159 # Failed to write pickle. Try to clean-up behind us. |
| 160 if sums_file: |
| 161 sums_file.close() |
| 162 try: |
| 163 os.unlink(self.sums_file_name) |
| 164 except: |
| 165 pass |
158 finally: | 166 finally: |
159 sums_file.close() | 167 sums_file.close() |
160 | 168 |
161 def FilterUnchangedFiles(self, files): | 169 def FilterUnchangedFiles(self, files): |
162 changed_or_new = [] | 170 changed_or_new = [] |
163 for file in files: | 171 for file in files: |
164 try: | 172 try: |
165 handle = open(file, "r") | 173 handle = open(file, "r") |
166 file_sum = md5er(handle.read()).digest() | 174 file_sum = md5er(handle.read()).digest() |
167 if not file in self.sums or self.sums[file] != file_sum: | 175 if not file in self.sums or self.sums[file] != file_sum: |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 "two empty lines between declarations check..." | 434 "two empty lines between declarations check..." |
427 success = SourceProcessor().Run(workspace) and success | 435 success = SourceProcessor().Run(workspace) and success |
428 if success: | 436 if success: |
429 return 0 | 437 return 0 |
430 else: | 438 else: |
431 return 1 | 439 return 1 |
432 | 440 |
433 | 441 |
434 if __name__ == '__main__': | 442 if __name__ == '__main__': |
435 sys.exit(Main()) | 443 sys.exit(Main()) |
OLD | NEW |