OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """Schema of the JSON summary file written out by the GM tool. | 6 """Schema of the JSON summary file written out by the GM tool. |
7 | 7 |
8 This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp ! | 8 This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp ! |
9 """ | 9 """ |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 gm_actuals_root_url=GM_ACTUALS_ROOT_HTTP_URL): | 97 gm_actuals_root_url=GM_ACTUALS_ROOT_HTTP_URL): |
98 """Return the URL we can use to download a particular version of | 98 """Return the URL we can use to download a particular version of |
99 the actually-generated image for this particular GM test. | 99 the actually-generated image for this particular GM test. |
100 | 100 |
101 test_name: name of the test, e.g. 'perlinnoise' | 101 test_name: name of the test, e.g. 'perlinnoise' |
102 hash_type: string indicating the hash type used to generate hash_digest, | 102 hash_type: string indicating the hash type used to generate hash_digest, |
103 e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5 | 103 e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5 |
104 hash_digest: the hash digest of the image to retrieve | 104 hash_digest: the hash digest of the image to retrieve |
105 gm_actuals_root_url: root url where actual images are stored | 105 gm_actuals_root_url: root url where actual images are stored |
106 """ | 106 """ |
| 107 # TODO(epoger): Maybe use url_or_path.join() so that, for testing, this can |
| 108 # return either a URL or a local filepath? |
107 return '%s/%s/%s/%s.png' % (gm_actuals_root_url, hash_type, test_name, | 109 return '%s/%s/%s/%s.png' % (gm_actuals_root_url, hash_type, test_name, |
108 hash_digest) | 110 hash_digest) |
109 | 111 |
110 def LoadFromString(file_contents): | 112 def LoadFromString(file_contents): |
111 """Loads the JSON summary written out by the GM tool. | 113 """Loads the JSON summary written out by the GM tool. |
112 Returns a dictionary keyed by the values listed as JSONKEY_ constants | 114 Returns a dictionary keyed by the values listed as JSONKEY_ constants |
113 above.""" | 115 above.""" |
114 # TODO(epoger): we should add a version number to the JSON file to ensure | 116 # TODO(epoger): we should add a version number to the JSON file to ensure |
115 # that the writer and reader agree on the schema (raising an exception | 117 # that the writer and reader agree on the schema (raising an exception |
116 # otherwise). | 118 # otherwise). |
117 json_dict = json.loads(file_contents) | 119 json_dict = json.loads(file_contents) |
118 return json_dict | 120 return json_dict |
119 | 121 |
120 def LoadFromFile(file_path): | 122 def LoadFromFile(file_path): |
121 """Loads the JSON summary written out by the GM tool. | 123 """Loads the JSON summary written out by the GM tool. |
122 Returns a dictionary keyed by the values listed as JSONKEY_ constants | 124 Returns a dictionary keyed by the values listed as JSONKEY_ constants |
123 above.""" | 125 above.""" |
124 file_contents = open(file_path, 'r').read() | 126 file_contents = open(file_path, 'r').read() |
125 return LoadFromString(file_contents) | 127 return LoadFromString(file_contents) |
126 | 128 |
127 def WriteToFile(json_dict, file_path): | 129 def WriteToFile(json_dict, file_path): |
128 """Writes the JSON summary in json_dict out to file_path. | 130 """Writes the JSON summary in json_dict out to file_path. |
129 | 131 |
130 The file is written Unix-style (each line ends with just LF, not CRLF); | 132 The file is written Unix-style (each line ends with just LF, not CRLF); |
131 see https://code.google.com/p/skia/issues/detail?id=1815 for reasons.""" | 133 see https://code.google.com/p/skia/issues/detail?id=1815 for reasons.""" |
132 with io.open(file_path, mode='w', newline='', encoding='utf-8') as outfile: | 134 with io.open(file_path, mode='w', newline='', encoding='utf-8') as outfile: |
133 outfile.write(unicode(json.dumps(json_dict, outfile, sort_keys=True, | 135 outfile.write(unicode(json.dumps(json_dict, outfile, sort_keys=True, |
134 indent=2))) | 136 indent=2))) |
OLD | NEW |