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

Side by Side Diff: gm/rebaseline_server/imagepairset.py

Issue 197213033: rebaseline_server: serve JSON from static file, rather than generating it live (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 9 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
epoger 2014/03/19 21:13:51 Reason for the change: We want to be able to store
3 """ 3 """
4 Copyright 2014 Google Inc. 4 Copyright 2014 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 ImagePairSet class; see its docstring below. 9 ImagePairSet class; see its docstring below.
10 """ 10 """
11 11
12 # System-level imports 12 # System-level imports
13 import posixpath 13 import posixpath
14 14
15 # Local imports 15 # Local imports
16 import column 16 import column
17 17
18 # Keys used within dictionary representation of ImagePairSet. 18 # Keys used within dictionary representation of ImagePairSet.
19 # NOTE: Keep these in sync with static/constants.js 19 # NOTE: Keep these in sync with static/constants.js
20 KEY__EXTRACOLUMNHEADERS = 'extraColumnHeaders' 20 KEY__EXTRACOLUMNHEADERS = 'extraColumnHeaders'
21 KEY__IMAGEPAIRS = 'imagePairs' 21 KEY__IMAGEPAIRS = 'imagePairs'
22 KEY__IMAGESETS = 'imageSets' 22 KEY__IMAGESETS = 'imageSets'
23 KEY__IMAGESETS__FIELD__BASE_URL = 'baseUrl' 23 KEY__IMAGESETS__FIELD__BASE_URL = 'baseUrl'
24 KEY__IMAGESETS__FIELD__DESCRIPTION = 'description' 24 KEY__IMAGESETS__FIELD__DESCRIPTION = 'description'
25 KEY__IMAGESETS__SET__DIFFS = 'diffs' 25 KEY__IMAGESETS__SET__DIFFS = 'diffs'
26 KEY__IMAGESETS__SET__IMAGE_A = 'imageA' 26 KEY__IMAGESETS__SET__IMAGE_A = 'imageA'
27 KEY__IMAGESETS__SET__IMAGE_B = 'imageB' 27 KEY__IMAGESETS__SET__IMAGE_B = 'imageB'
28 KEY__IMAGESETS__SET__WHITEDIFFS = 'whiteDiffs' 28 KEY__IMAGESETS__SET__WHITEDIFFS = 'whiteDiffs'
29 29
30 DEFAULT_DESCRIPTIONS = ('setA', 'setB') 30 DEFAULT_DESCRIPTIONS = ('setA', 'setB')
31 DIFF_BASE_URL = '/static/generated-images'
32 31
33 32
34 class ImagePairSet(object): 33 class ImagePairSet(object):
35 """A collection of ImagePairs, representing two arbitrary sets of images. 34 """A collection of ImagePairs, representing two arbitrary sets of images.
36 35
37 These could be: 36 These could be:
38 - images generated before and after a code patch 37 - images generated before and after a code patch
39 - expected and actual images for some tests 38 - expected and actual images for some tests
40 - or any other pairwise set of images. 39 - or any other pairwise set of images.
41 """ 40 """
42 41
43 def __init__(self, descriptions=None): 42 def __init__(self, diff_base_url, descriptions=None):
44 """ 43 """
45 Args: 44 Args:
45 diff_base_url: base URL indicating where diff images can be loaded from
46 descriptions: a (string, string) tuple describing the two image sets. 46 descriptions: a (string, string) tuple describing the two image sets.
47 If not specified, DEFAULT_DESCRIPTIONS will be used. 47 If not specified, DEFAULT_DESCRIPTIONS will be used.
48 """ 48 """
49 self._column_header_factories = {} 49 self._column_header_factories = {}
50 self._descriptions = descriptions or DEFAULT_DESCRIPTIONS 50 self._descriptions = descriptions or DEFAULT_DESCRIPTIONS
51 self._extra_column_tallies = {} # maps column_id -> values 51 self._extra_column_tallies = {} # maps column_id -> values
52 # -> instances_per_value 52 # -> instances_per_value
53 self._image_pair_dicts = [] 53 self._image_pair_dicts = []
54 self._image_base_url = None 54 self._image_base_url = None
55 self._diff_base_url = DIFF_BASE_URL 55 self._diff_base_url = diff_base_url
56 56
57 def add_image_pair(self, image_pair): 57 def add_image_pair(self, image_pair):
58 """Adds an ImagePair; this may be repeated any number of times.""" 58 """Adds an ImagePair; this may be repeated any number of times."""
59 # Special handling when we add the first ImagePair... 59 # Special handling when we add the first ImagePair...
60 if not self._image_pair_dicts: 60 if not self._image_pair_dicts:
61 self._image_base_url = image_pair.base_url 61 self._image_base_url = image_pair.base_url
62 62
63 if image_pair.base_url != self._image_base_url: 63 if image_pair.base_url != self._image_base_url:
64 raise Exception('added ImagePair with base_url "%s" instead of "%s"' % ( 64 raise Exception('added ImagePair with base_url "%s" instead of "%s"' % (
65 image_pair.base_url, self._image_base_url)) 65 image_pair.base_url, self._image_base_url))
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 key_base_url: posixpath.join( 157 key_base_url: posixpath.join(
158 self._diff_base_url, 'diffs'), 158 self._diff_base_url, 'diffs'),
159 }, 159 },
160 KEY__IMAGESETS__SET__WHITEDIFFS: { 160 KEY__IMAGESETS__SET__WHITEDIFFS: {
161 key_description: 'differing pixels in white', 161 key_description: 'differing pixels in white',
162 key_base_url: posixpath.join( 162 key_base_url: posixpath.join(
163 self._diff_base_url, 'whitediffs'), 163 self._diff_base_url, 'whitediffs'),
164 }, 164 },
165 }, 165 },
166 } 166 }
OLDNEW
« no previous file with comments | « no previous file | gm/rebaseline_server/imagepairset_test.py » ('j') | gm/rebaseline_server/server.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698