| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Regenerates all the .isolated test data files. | |
| 7 | |
| 8 Keep in sync with ../run_isolated_smoke_test.py. | |
| 9 """ | |
| 10 | |
| 11 import glob | |
| 12 import hashlib | |
| 13 import json | |
| 14 import os | |
| 15 import sys | |
| 16 | |
| 17 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 18 | |
| 19 | |
| 20 # Ordering is important to keep this script simple. | |
| 21 INCLUDES_TO_FIX = [ | |
| 22 ('manifest2.isolated', ['manifest1.isolated']), | |
| 23 ('check_files.isolated', ['manifest2.isolated', 'repeated_files.isolated']), | |
| 24 ] | |
| 25 | |
| 26 | |
| 27 def sha1(filename): | |
| 28 with open(filename, 'rb') as f: | |
| 29 return hashlib.sha1(f.read()).hexdigest() | |
| 30 | |
| 31 | |
| 32 def load(filename): | |
| 33 with open(filename, 'r') as f: | |
| 34 return json.load(f) | |
| 35 | |
| 36 | |
| 37 def save(filename, data): | |
| 38 """Saves data as json properly formatted. | |
| 39 | |
| 40 Strips spurious whitespace json.dump likes to add at the end of lines and add | |
| 41 a trailing \n. | |
| 42 """ | |
| 43 out = ''.join( | |
| 44 '%s\n' % l.rstrip() | |
| 45 for l in json.dumps(data, indent=2, sort_keys=True).splitlines()) | |
| 46 with open(filename, 'wb') as f: | |
| 47 f.write(out) | |
| 48 | |
| 49 | |
| 50 def main(): | |
| 51 # Simplify our life. | |
| 52 os.chdir(ROOT_DIR) | |
| 53 | |
| 54 # First, reformat all the files. | |
| 55 for filename in glob.glob('*.isolated'): | |
| 56 save(filename, load(filename)) | |
| 57 | |
| 58 # Then update the SHA-1s. | |
| 59 for manifest, includes in INCLUDES_TO_FIX: | |
| 60 data = load(manifest) | |
| 61 data['includes'] = [sha1(f) for f in includes] | |
| 62 save(manifest, data) | |
| 63 return 0 | |
| 64 | |
| 65 | |
| 66 if __name__ == '__main__': | |
| 67 sys.exit(main()) | |
| OLD | NEW |