Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import difflib | 5 import difflib |
| 6 import hashlib | 6 import hashlib |
| 7 import itertools | 7 import itertools |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 import zipfile | 11 import zipfile |
| 12 | 12 |
| 13 | 13 |
| 14 # When set and a difference is detected, a diff of what changed is printed. | 14 # When set and a difference is detected, a diff of what changed is printed. |
| 15 _PRINT_MD5_DIFFS = int(os.environ.get('PRINT_MD5_DIFFS', 0)) | 15 PRINT_EXPLANATIONS = int(os.environ.get('PRINT_MD5_DIFFS', 0)) |
|
Yaron
2015/09/30 02:19:25
update actually env variable too?
agrieve
2015/10/01 16:26:11
Done.
| |
| 16 | 16 |
| 17 | 17 |
| 18 def CallAndRecordIfStale( | 18 def CallAndRecordIfStale( |
| 19 function, record_path=None, input_paths=None, input_strings=None, | 19 function, record_path=None, input_paths=None, input_strings=None, |
| 20 output_paths=None, force=False, pass_changes=False): | 20 output_paths=None, force=False, pass_changes=False): |
| 21 """Calls function if outputs are stale. | 21 """Calls function if outputs are stale. |
| 22 | 22 |
| 23 Outputs are considered stale if: | 23 Outputs are considered stale if: |
| 24 - any output_paths are missing, or | 24 - any output_paths are missing, or |
| 25 - the contents of any file within input_paths has changed, or | 25 - the contents of any file within input_paths has changed, or |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 with open(record_path, 'r') as jsonfile: | 66 with open(record_path, 'r') as jsonfile: |
| 67 try: | 67 try: |
| 68 old_metadata = _Metadata.FromFile(jsonfile) | 68 old_metadata = _Metadata.FromFile(jsonfile) |
| 69 except: # pylint: disable=bare-except | 69 except: # pylint: disable=bare-except |
| 70 pass # Not yet using new file format. | 70 pass # Not yet using new file format. |
| 71 | 71 |
| 72 changes = Changes(old_metadata, new_metadata, force, missing_outputs) | 72 changes = Changes(old_metadata, new_metadata, force, missing_outputs) |
| 73 if not changes.HasChanges(): | 73 if not changes.HasChanges(): |
| 74 return | 74 return |
| 75 | 75 |
| 76 if _PRINT_MD5_DIFFS: | 76 if PRINT_EXPLANATIONS: |
| 77 print '=' * 80 | 77 print '=' * 80 |
| 78 print 'Target is stale: %s' % record_path | 78 print 'Target is stale: %s' % record_path |
| 79 print changes.DescribeDifference() | 79 print changes.DescribeDifference() |
| 80 print '=' * 80 | 80 print '=' * 80 |
| 81 | 81 |
| 82 # Delete the old metdata beforehand since failures leave it in an | 82 # Delete the old metdata beforehand since failures leave it in an |
| 83 # inderterminate state. | 83 # inderterminate state. |
| 84 if old_metadata: | 84 if old_metadata: |
| 85 os.unlink(record_path) | 85 os.unlink(record_path) |
| 86 | 86 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 | 390 |
| 391 def _ExtractZipEntries(path): | 391 def _ExtractZipEntries(path): |
| 392 """Returns a list of (path, CRC32) of all files within |path|.""" | 392 """Returns a list of (path, CRC32) of all files within |path|.""" |
| 393 entries = [] | 393 entries = [] |
| 394 with zipfile.ZipFile(path) as zip_file: | 394 with zipfile.ZipFile(path) as zip_file: |
| 395 for zip_info in zip_file.infolist(): | 395 for zip_info in zip_file.infolist(): |
| 396 # Skip directories and empty files. | 396 # Skip directories and empty files. |
| 397 if zip_info.CRC: | 397 if zip_info.CRC: |
| 398 entries.append((zip_info.filename, zip_info.CRC)) | 398 entries.append((zip_info.filename, zip_info.CRC)) |
| 399 return entries | 399 return entries |
| OLD | NEW |