| OLD | NEW |
| 1 # Copyright 2014 The LUCI Authors. All rights reserved. | 1 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Understands .isolated files and can do local operations on them.""" | 5 """Understands .isolated files and can do local operations on them.""" |
| 6 | 6 |
| 7 import hashlib | 7 import hashlib |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 """Verifies the .isolated file is valid and loads this object with the json | 429 """Verifies the .isolated file is valid and loads this object with the json |
| 430 data. | 430 data. |
| 431 | 431 |
| 432 Arguments: | 432 Arguments: |
| 433 - content: raw serialized content to load. | 433 - content: raw serialized content to load. |
| 434 - algo: hashlib algorithm class. Used to confirm the algorithm matches the | 434 - algo: hashlib algorithm class. Used to confirm the algorithm matches the |
| 435 algorithm used on the Isolate Server. | 435 algorithm used on the Isolate Server. |
| 436 """ | 436 """ |
| 437 try: | 437 try: |
| 438 data = json.loads(content) | 438 data = json.loads(content) |
| 439 except ValueError: | 439 except ValueError as v: |
| 440 raise IsolatedError('Failed to parse: %s...' % content[:100]) | 440 raise IsolatedError('Failed to parse (%s): %s...' % (v, content[:100])) |
| 441 | 441 |
| 442 if not isinstance(data, dict): | 442 if not isinstance(data, dict): |
| 443 raise IsolatedError('Expected dict, got %r' % data) | 443 raise IsolatedError('Expected dict, got %r' % data) |
| 444 | 444 |
| 445 # Check 'version' first, since it could modify the parsing after. | 445 # Check 'version' first, since it could modify the parsing after. |
| 446 value = data.get('version', '1.0') | 446 value = data.get('version', '1.0') |
| 447 if not isinstance(value, basestring): | 447 if not isinstance(value, basestring): |
| 448 raise IsolatedError('Expected string, got %r' % value) | 448 raise IsolatedError('Expected string, got %r' % value) |
| 449 try: | 449 try: |
| 450 version = tuple(map(int, value.split('.'))) | 450 version = tuple(map(int, value.split('.'))) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 data['files'] = dict( | 574 data['files'] = dict( |
| 575 (k.replace(wrong_path_sep, os.path.sep), v) | 575 (k.replace(wrong_path_sep, os.path.sep), v) |
| 576 for k, v in data['files'].iteritems()) | 576 for k, v in data['files'].iteritems()) |
| 577 for v in data['files'].itervalues(): | 577 for v in data['files'].itervalues(): |
| 578 if 'l' in v: | 578 if 'l' in v: |
| 579 v['l'] = v['l'].replace(wrong_path_sep, os.path.sep) | 579 v['l'] = v['l'].replace(wrong_path_sep, os.path.sep) |
| 580 if 'relative_cwd' in data: | 580 if 'relative_cwd' in data: |
| 581 data['relative_cwd'] = data['relative_cwd'].replace( | 581 data['relative_cwd'] = data['relative_cwd'].replace( |
| 582 wrong_path_sep, os.path.sep) | 582 wrong_path_sep, os.path.sep) |
| 583 return data | 583 return data |
| OLD | NEW |