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

Side by Side Diff: gm/gm_json.py

Issue 178253010: rebaseline_server: use new intermediate JSON format (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: line wraps 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/column.py » ('j') | gm/rebaseline_server/results.py » ('J')
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
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 io
16 import json 16 import json
17 import os 17 import os
18 import re
18 19
19 20
20 # Key strings used in GM results JSON files (both expected-results.json and 21 # Key strings used in GM results JSON files (both expected-results.json and
21 # actual-results.json). 22 # actual-results.json).
22 # 23 #
23 # These constants must be kept in sync with the kJsonKey_ constants in 24 # These constants must be kept in sync with the kJsonKey_ constants in
24 # gm_expectations.cpp ! 25 # gm_expectations.cpp !
25 26
26 27
27 JSONKEY_ACTUALRESULTS = 'actual-results' 28 JSONKEY_ACTUALRESULTS = 'actual-results'
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 87
87 # Root directory where buildbots store skimage actual results json files. 88 # Root directory where buildbots store skimage actual results json files.
88 SKIMAGE_ACTUALS_BASE_URL = ( 89 SKIMAGE_ACTUALS_BASE_URL = (
89 'http://chromium-skia-gm.commondatastorage.googleapis.com/skimage/actuals') 90 'http://chromium-skia-gm.commondatastorage.googleapis.com/skimage/actuals')
90 # Root directory inside trunk where skimage expectations are stored. 91 # Root directory inside trunk where skimage expectations are stored.
91 SKIMAGE_EXPECTATIONS_ROOT = os.path.join('expectations', 'skimage') 92 SKIMAGE_EXPECTATIONS_ROOT = os.path.join('expectations', 'skimage')
92 93
93 # Pattern used to assemble each image's filename 94 # Pattern used to assemble each image's filename
94 IMAGE_FILENAME_PATTERN = '(.+)_(.+)\.png' # matches (testname, config) 95 IMAGE_FILENAME_PATTERN = '(.+)_(.+)\.png' # matches (testname, config)
95 96
97 # Pattern used to create image URLs, relative to some base URL.
98 GM_RELATIVE_URL_FORMATTER = '%s/%s/%s.png' # pass in (hash_type, test_name,
99 # hash_digest)
epoger 2014/02/26 04:38:14 As I recall, the Python style guide recommends aga
100 GM_RELATIVE_URL_PATTERN = '(.+)/(.+)/(.+).png' # matches (hash_type, test_name,
101 # hash_digest)
102 GM_RELATIVE_URL_RE = re.compile(GM_RELATIVE_URL_PATTERN)
103
104
96 def CreateGmActualUrl(test_name, hash_type, hash_digest, 105 def CreateGmActualUrl(test_name, hash_type, hash_digest,
97 gm_actuals_root_url=GM_ACTUALS_ROOT_HTTP_URL): 106 gm_actuals_root_url=GM_ACTUALS_ROOT_HTTP_URL):
98 """Return the URL we can use to download a particular version of 107 """Return the URL we can use to download a particular version of
99 the actually-generated image for this particular GM test. 108 the actually-generated image for this particular GM test.
100 109
101 test_name: name of the test, e.g. 'perlinnoise' 110 test_name: name of the test, e.g. 'perlinnoise'
102 hash_type: string indicating the hash type used to generate hash_digest, 111 hash_type: string indicating the hash type used to generate hash_digest,
103 e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5 112 e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5
104 hash_digest: the hash digest of the image to retrieve 113 hash_digest: the hash digest of the image to retrieve
105 gm_actuals_root_url: root url where actual images are stored 114 gm_actuals_root_url: root url where actual images are stored
106 """ 115 """
107 # TODO(epoger): Maybe use url_or_path.join() so that, for testing, this can 116 return '%s/%s' % (gm_actuals_root_url, CreateGmRelativeUrl(
108 # return either a URL or a local filepath? 117 test_name=test_name, hash_type=hash_type, hash_digest=hash_digest))
109 return '%s/%s/%s/%s.png' % (gm_actuals_root_url, hash_type, test_name, 118
110 hash_digest) 119 def CreateGmRelativeUrl(test_name, hash_type, hash_digest):
120 """Returns a relative URL pointing at a test result's image.
121
122 Returns the URL we can use to download a particular version of
123 the actually-generated image for this particular GM test,
124 relative to the URL root.
125
126 Args:
127 test_name: name of the test, e.g. 'perlinnoise'
128 hash_type: string indicating the hash type used to generate hash_digest,
129 e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5
130 hash_digest: the hash digest of the image to retrieve
131 """
132 return GM_RELATIVE_URL_FORMATTER % (hash_type, test_name, hash_digest)
133
134 def SplitGmRelativeUrl(url):
135 """Splits the relative URL into (test_name, hash_type, hash_digest) tuple.
136
137 This is the inverse of CreateGmRelativeUrl().
138
139 Args:
140 url: a URL generated with CreateGmRelativeUrl().
141
142 Returns: (test_name, hash_type, hash_digest) tuple.
143 """
144 hash_type, test_name, hash_digest = GM_RELATIVE_URL_RE.match(url).groups()
145 return (test_name, hash_type, hash_digest)
111 146
112 def LoadFromString(file_contents): 147 def LoadFromString(file_contents):
113 """Loads the JSON summary written out by the GM tool. 148 """Loads the JSON summary written out by the GM tool.
114 Returns a dictionary keyed by the values listed as JSONKEY_ constants 149 Returns a dictionary keyed by the values listed as JSONKEY_ constants
115 above.""" 150 above."""
116 # TODO(epoger): we should add a version number to the JSON file to ensure 151 # TODO(epoger): we should add a version number to the JSON file to ensure
117 # that the writer and reader agree on the schema (raising an exception 152 # that the writer and reader agree on the schema (raising an exception
118 # otherwise). 153 # otherwise).
119 json_dict = json.loads(file_contents) 154 json_dict = json.loads(file_contents)
120 return json_dict 155 return json_dict
121 156
122 def LoadFromFile(file_path): 157 def LoadFromFile(file_path):
123 """Loads the JSON summary written out by the GM tool. 158 """Loads the JSON summary written out by the GM tool.
124 Returns a dictionary keyed by the values listed as JSONKEY_ constants 159 Returns a dictionary keyed by the values listed as JSONKEY_ constants
125 above.""" 160 above."""
126 file_contents = open(file_path, 'r').read() 161 file_contents = open(file_path, 'r').read()
127 return LoadFromString(file_contents) 162 return LoadFromString(file_contents)
128 163
129 def WriteToFile(json_dict, file_path): 164 def WriteToFile(json_dict, file_path):
130 """Writes the JSON summary in json_dict out to file_path. 165 """Writes the JSON summary in json_dict out to file_path.
131 166
132 The file is written Unix-style (each line ends with just LF, not CRLF); 167 The file is written Unix-style (each line ends with just LF, not CRLF);
133 see https://code.google.com/p/skia/issues/detail?id=1815 for reasons.""" 168 see https://code.google.com/p/skia/issues/detail?id=1815 for reasons."""
134 with io.open(file_path, mode='w', newline='', encoding='utf-8') as outfile: 169 with io.open(file_path, mode='w', newline='', encoding='utf-8') as outfile:
135 outfile.write(unicode(json.dumps(json_dict, outfile, sort_keys=True, 170 outfile.write(unicode(json.dumps(json_dict, outfile, sort_keys=True,
136 indent=2))) 171 indent=2)))
OLDNEW
« no previous file with comments | « no previous file | gm/rebaseline_server/column.py » ('j') | gm/rebaseline_server/results.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698