| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Class for parsing metadata about extension samples.""" | 6 """Class for parsing metadata about extension samples.""" |
| 7 | 7 |
| 8 import locale | 8 import locale |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| 11 import re | 11 import re |
| 12 import hashlib | 12 import hashlib |
| 13 import zipfile | 13 import zipfile |
| 14 import simplejson as json | 14 import simplejson as json |
| 15 import json_minify as minify |
| 15 | 16 |
| 16 # Make sure we get consistent string sorting behavior by explicitly using the | 17 # Make sure we get consistent string sorting behavior by explicitly using the |
| 17 # default C locale. | 18 # default C locale. |
| 18 locale.setlocale(locale.LC_ALL, 'C') | 19 locale.setlocale(locale.LC_ALL, 'C') |
| 19 | 20 |
| 20 def sorted_walk(path): | 21 def sorted_walk(path): |
| 21 """ A version of os.walk that yields results in order sorted by name. | 22 """ A version of os.walk that yields results in order sorted by name. |
| 22 | 23 |
| 23 This is to prevent spurious docs changes due to os.walk returning items in a | 24 This is to prevent spurious docs changes due to os.walk returning items in a |
| 24 filesystem dependent order (by inode creation time, etc). | 25 filesystem dependent order (by inode creation time, etc). |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 Raises: | 42 Raises: |
| 42 Exception: If the file could not be read or its contents could not be | 43 Exception: If the file could not be read or its contents could not be |
| 43 parsed as JSON data. | 44 parsed as JSON data. |
| 44 """ | 45 """ |
| 45 try: | 46 try: |
| 46 json_file = open(path, 'r') | 47 json_file = open(path, 'r') |
| 47 except IOError, msg: | 48 except IOError, msg: |
| 48 raise Exception("Failed to read the file at %s: %s" % (path, msg)) | 49 raise Exception("Failed to read the file at %s: %s" % (path, msg)) |
| 49 | 50 |
| 50 try: | 51 try: |
| 51 json_obj = json.load(json_file, encoding) | 52 json_str = json_file.read() |
| 53 json_obj = json.loads(minify.json_minify(json_str), encoding) |
| 52 except ValueError, msg: | 54 except ValueError, msg: |
| 53 raise Exception("Failed to parse JSON out of file %s: %s" % (path, msg)) | 55 raise Exception("Failed to parse JSON out of file %s: %s" % (path, msg)) |
| 54 finally: | 56 finally: |
| 55 json_file.close() | 57 json_file.close() |
| 56 | 58 |
| 57 return json_obj | 59 return json_obj |
| 58 | 60 |
| 59 class ApiManifest(object): | 61 class ApiManifest(object): |
| 60 """ Represents the list of API methods contained in the extension API JSON """ | 62 """ Represents the list of API methods contained in the extension API JSON """ |
| 61 | 63 |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 zip_file.write(abspath, relpath) | 729 zip_file.write(abspath, relpath) |
| 728 if file == 'manifest.json': | 730 if file == 'manifest.json': |
| 729 info = zip_file.getinfo(zip_manifest_path) | 731 info = zip_file.getinfo(zip_manifest_path) |
| 730 info.comment = self['source_hash'] | 732 info.comment = self['source_hash'] |
| 731 except RuntimeError, msg: | 733 except RuntimeError, msg: |
| 732 raise Exception("Could not write zip at %s: %s" % (zip_path, msg)) | 734 raise Exception("Could not write zip at %s: %s" % (zip_path, msg)) |
| 733 finally: | 735 finally: |
| 734 zip_file.close() | 736 zip_file.close() |
| 735 | 737 |
| 736 return self._get_relative_zip_path() | 738 return self._get_relative_zip_path() |
| OLD | NEW |