Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: gm/gm_json.py

Issue 143653006: new tool: download all GM images for a given builder, ready for skdiff (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: final touches Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gm/rebaseline_server/download_actuals.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)))
OLDNEW
« no previous file with comments | « no previous file | gm/rebaseline_server/download_actuals.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698