| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 """Deals with loading & saving .size files.""" | 5 """Deals with loading & saving .size files.""" |
| 6 | 6 |
| 7 import cStringIO | 7 import cStringIO |
| 8 import calendar | 8 import calendar |
| 9 import collections | 9 import collections |
| 10 import datetime | 10 import datetime |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 """Loads a size_info from the given file.""" | 92 """Loads a size_info from the given file.""" |
| 93 lines = iter(file_obj) | 93 lines = iter(file_obj) |
| 94 next(lines) # Comment line. | 94 next(lines) # Comment line. |
| 95 actual_version = next(lines)[:-1] | 95 actual_version = next(lines)[:-1] |
| 96 assert actual_version == _SERIALIZATION_VERSION, ( | 96 assert actual_version == _SERIALIZATION_VERSION, ( |
| 97 'Version mismatch. Need to write some upgrade code.') | 97 'Version mismatch. Need to write some upgrade code.') |
| 98 json_len = int(next(lines)) | 98 json_len = int(next(lines)) |
| 99 json_str = file_obj.read(json_len) | 99 json_str = file_obj.read(json_len) |
| 100 headers = json.loads(json_str) | 100 headers = json.loads(json_str) |
| 101 section_sizes = headers['section_sizes'] | 101 section_sizes = headers['section_sizes'] |
| 102 metadata = headers['metadata'] | 102 metadata = headers.get('metadata') |
| 103 lines = iter(file_obj) | 103 lines = iter(file_obj) |
| 104 next(lines) # newline after closing } of json. | 104 next(lines) # newline after closing } of json. |
| 105 | 105 |
| 106 num_path_tuples = int(next(lines)) | 106 num_path_tuples = int(next(lines)) |
| 107 path_tuples = [None] * num_path_tuples | 107 path_tuples = [None] * num_path_tuples |
| 108 for i in xrange(num_path_tuples): | 108 for i in xrange(num_path_tuples): |
| 109 path_tuples[i] = next(lines)[:-1].split('\t') | 109 path_tuples[i] = next(lines)[:-1].split('\t') |
| 110 | 110 |
| 111 section_names = next(lines)[:-1].split('\t') | 111 section_names = next(lines)[:-1].split('\t') |
| 112 section_counts = [int(c) for c in next(lines)[:-1].split('\t')] | 112 section_counts = [int(c) for c in next(lines)[:-1].split('\t')] |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 logging.debug('Serialization complete. Gzipping...') | 166 logging.debug('Serialization complete. Gzipping...') |
| 167 stringio.seek(0) | 167 stringio.seek(0) |
| 168 with gzip.open(path, 'wb') as f: | 168 with gzip.open(path, 'wb') as f: |
| 169 shutil.copyfileobj(stringio, f) | 169 shutil.copyfileobj(stringio, f) |
| 170 | 170 |
| 171 | 171 |
| 172 def LoadSizeInfo(path): | 172 def LoadSizeInfo(path): |
| 173 """Returns a SizeInfo loaded from |path|.""" | 173 """Returns a SizeInfo loaded from |path|.""" |
| 174 with gzip.open(path) as f: | 174 with gzip.open(path) as f: |
| 175 return _LoadSizeInfoFromFile(f) | 175 return _LoadSizeInfoFromFile(f) |
| OLD | NEW |