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 |
11 __author__ = 'Elliot Poger' | 11 __author__ = 'Elliot Poger' |
12 | 12 |
13 | 13 |
14 # system-level imports | 14 # system-level imports |
| 15 import io |
15 import json | 16 import json |
16 import os | 17 import os |
17 | 18 |
18 | 19 |
19 # Key strings used in GM results JSON files (both expected-results.json and | 20 # Key strings used in GM results JSON files (both expected-results.json and |
20 # actual-results.json). | 21 # actual-results.json). |
21 # | 22 # |
22 # These constants must be kept in sync with the kJsonKey_ constants in | 23 # These constants must be kept in sync with the kJsonKey_ constants in |
23 # gm_expectations.cpp ! | 24 # gm_expectations.cpp ! |
24 | 25 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 return json_dict | 118 return json_dict |
118 | 119 |
119 def LoadFromFile(file_path): | 120 def LoadFromFile(file_path): |
120 """Loads the JSON summary written out by the GM tool. | 121 """Loads the JSON summary written out by the GM tool. |
121 Returns a dictionary keyed by the values listed as JSONKEY_ constants | 122 Returns a dictionary keyed by the values listed as JSONKEY_ constants |
122 above.""" | 123 above.""" |
123 file_contents = open(file_path, 'r').read() | 124 file_contents = open(file_path, 'r').read() |
124 return LoadFromString(file_contents) | 125 return LoadFromString(file_contents) |
125 | 126 |
126 def WriteToFile(json_dict, file_path): | 127 def WriteToFile(json_dict, file_path): |
127 """Writes the JSON summary in json_dict out to file_path.""" | 128 """Writes the JSON summary in json_dict out to file_path. |
128 with open(file_path, 'w') as outfile: | 129 |
129 json.dump(json_dict, outfile, sort_keys=True, indent=2) | 130 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.""" |
| 132 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, |
| 134 indent=2))) |
OLD | NEW |