| 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 |
| 11 import gzip | 11 import gzip |
| 12 import json | 12 import json |
| 13 import models | |
| 14 import logging | 13 import logging |
| 15 import os | 14 import os |
| 16 import shutil | 15 import shutil |
| 17 | 16 |
| 17 import models |
| 18 |
| 18 | 19 |
| 19 # File format version for .size files. | 20 # File format version for .size files. |
| 20 _SERIALIZATION_VERSION = 'Size File Format v1' | 21 _SERIALIZATION_VERSION = 'Size File Format v1' |
| 21 | 22 |
| 22 | 23 |
| 23 def _LogSize(file_obj, desc): | 24 def _LogSize(file_obj, desc): |
| 24 if not hasattr(file_obj, 'fileno'): | 25 if not hasattr(file_obj, 'fileno'): |
| 25 return | 26 return |
| 26 file_obj.flush() | 27 file_obj.flush() |
| 27 size = os.fstat(file_obj.fileno()).st_size | 28 size = os.fstat(file_obj.fileno()).st_size |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 logging.debug('Serialization complete. Gzipping...') | 167 logging.debug('Serialization complete. Gzipping...') |
| 167 stringio.seek(0) | 168 stringio.seek(0) |
| 168 with gzip.open(path, 'wb') as f: | 169 with gzip.open(path, 'wb') as f: |
| 169 shutil.copyfileobj(stringio, f) | 170 shutil.copyfileobj(stringio, f) |
| 170 | 171 |
| 171 | 172 |
| 172 def LoadSizeInfo(path): | 173 def LoadSizeInfo(path): |
| 173 """Returns a SizeInfo loaded from |path|.""" | 174 """Returns a SizeInfo loaded from |path|.""" |
| 174 with gzip.open(path) as f: | 175 with gzip.open(path) as f: |
| 175 return _LoadSizeInfoFromFile(f) | 176 return _LoadSizeInfoFromFile(f) |
| OLD | NEW |