| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 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 """ |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 """ | 50 """ |
| 51 Args: | 51 Args: |
| 52 diff_base_url: base URL indicating where diff images can be loaded from | 52 diff_base_url: base URL indicating where diff images can be loaded from |
| 53 descriptions: a (string, string) tuple describing the two image sets. | 53 descriptions: a (string, string) tuple describing the two image sets. |
| 54 If not specified, DEFAULT_DESCRIPTIONS will be used. | 54 If not specified, DEFAULT_DESCRIPTIONS will be used. |
| 55 """ | 55 """ |
| 56 self._column_header_factories = {} | 56 self._column_header_factories = {} |
| 57 self._descriptions = descriptions or DEFAULT_DESCRIPTIONS | 57 self._descriptions = descriptions or DEFAULT_DESCRIPTIONS |
| 58 self._extra_column_tallies = {} # maps column_id -> values | 58 self._extra_column_tallies = {} # maps column_id -> values |
| 59 # -> instances_per_value | 59 # -> instances_per_value |
| 60 self._image_base_url = None | 60 self._imageA_base_url = None |
| 61 self._imageB_base_url = None |
| 61 self._diff_base_url = diff_base_url | 62 self._diff_base_url = diff_base_url |
| 62 | 63 |
| 63 # We build self._image_pair_objects incrementally as calls come into | 64 # We build self._image_pair_objects incrementally as calls come into |
| 64 # add_image_pair(); self._image_pair_dicts is filled in lazily (so that | 65 # add_image_pair(); self._image_pair_dicts is filled in lazily (so that |
| 65 # we put off asking ImageDiffDB for results as long as possible). | 66 # we put off asking ImageDiffDB for results as long as possible). |
| 66 self._image_pair_objects = [] | 67 self._image_pair_objects = [] |
| 67 self._image_pair_dicts = None | 68 self._image_pair_dicts = None |
| 68 | 69 |
| 69 def add_image_pair(self, image_pair): | 70 def add_image_pair(self, image_pair): |
| 70 """Adds an ImagePair; this may be repeated any number of times.""" | 71 """Adds an ImagePair; this may be repeated any number of times.""" |
| 71 # Special handling when we add the first ImagePair... | 72 # Special handling when we add the first ImagePair... |
| 72 if not self._image_pair_objects: | 73 if not self._image_pair_objects: |
| 73 self._image_base_url = image_pair.base_url | 74 self._imageA_base_url = image_pair.imageA_base_url |
| 75 self._imageB_base_url = image_pair.imageB_base_url |
| 74 | 76 |
| 75 if image_pair.base_url != self._image_base_url: | 77 if(image_pair.imageA_base_url != self._imageA_base_url): |
| 76 raise Exception('added ImagePair with base_url "%s" instead of "%s"' % ( | 78 raise Exception('added ImagePair with base_url "%s" instead of "%s"' % ( |
| 77 image_pair.base_url, self._image_base_url)) | 79 image_pair.imageA_base_url, self._imageA_base_url)) |
| 80 if(image_pair.imageB_base_url != self._imageB_base_url): |
| 81 raise Exception('added ImagePair with base_url "%s" instead of "%s"' % ( |
| 82 image_pair.imageB_base_url, self._imageB_base_url)) |
| 78 self._image_pair_objects.append(image_pair) | 83 self._image_pair_objects.append(image_pair) |
| 79 extra_columns_dict = image_pair.extra_columns_dict | 84 extra_columns_dict = image_pair.extra_columns_dict |
| 80 if extra_columns_dict: | 85 if extra_columns_dict: |
| 81 for column_id, value in extra_columns_dict.iteritems(): | 86 for column_id, value in extra_columns_dict.iteritems(): |
| 82 self._add_extra_column_value_to_summary(column_id, value) | 87 self._add_extra_column_value_to_summary(column_id, value) |
| 83 | 88 |
| 84 def set_column_header_factory(self, column_id, column_header_factory): | 89 def set_column_header_factory(self, column_id, column_header_factory): |
| 85 """Overrides the default settings for one of the extraColumn headers. | 90 """Overrides the default settings for one of the extraColumn headers. |
| 86 | 91 |
| 87 Args: | 92 Args: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 specified_column_ids = set(column_ids_in_order) | 169 specified_column_ids = set(column_ids_in_order) |
| 165 forgotten_column_ids = all_column_ids - specified_column_ids | 170 forgotten_column_ids = all_column_ids - specified_column_ids |
| 166 assert not forgotten_column_ids, ( | 171 assert not forgotten_column_ids, ( |
| 167 'column_ids_in_order %s missing these column_ids: %s' % ( | 172 'column_ids_in_order %s missing these column_ids: %s' % ( |
| 168 column_ids_in_order, forgotten_column_ids)) | 173 column_ids_in_order, forgotten_column_ids)) |
| 169 column_ids_in_order = [c for c in column_ids_in_order | 174 column_ids_in_order = [c for c in column_ids_in_order |
| 170 if c in all_column_ids] | 175 if c in all_column_ids] |
| 171 | 176 |
| 172 key_description = KEY__IMAGESETS__FIELD__DESCRIPTION | 177 key_description = KEY__IMAGESETS__FIELD__DESCRIPTION |
| 173 key_base_url = KEY__IMAGESETS__FIELD__BASE_URL | 178 key_base_url = KEY__IMAGESETS__FIELD__BASE_URL |
| 174 if gs_utils.GSUtils.is_gs_url(self._image_base_url): | 179 if gs_utils.GSUtils.is_gs_url(self._imageA_base_url): |
| 175 value_base_url = self._convert_gs_url_to_http_url(self._image_base_url) | 180 valueA_base_url = self._convert_gs_url_to_http_url(self._imageA_base_url) |
| 176 else: | 181 else: |
| 177 value_base_url = self._image_base_url | 182 valueA_base_url = self._imageA_base_url |
| 183 if gs_utils.GSUtils.is_gs_url(self._imageB_base_url): |
| 184 valueB_base_url = self._convert_gs_url_to_http_url(self._imageB_base_url) |
| 185 else: |
| 186 valueB_base_url = self._imageB_base_url |
| 178 | 187 |
| 179 # We've waited as long as we can to ask ImageDiffDB for details of the | 188 # We've waited as long as we can to ask ImageDiffDB for details of the |
| 180 # image diffs, so that it has time to compute them. | 189 # image diffs, so that it has time to compute them. |
| 181 if self._image_pair_dicts == None: | 190 if self._image_pair_dicts == None: |
| 182 self._image_pair_dicts = [ip.as_dict() for ip in self._image_pair_objects] | 191 self._image_pair_dicts = [ip.as_dict() for ip in self._image_pair_objects] |
| 183 | 192 |
| 184 return { | 193 return { |
| 185 KEY__ROOT__EXTRACOLUMNHEADERS: self._column_headers_as_dict(), | 194 KEY__ROOT__EXTRACOLUMNHEADERS: self._column_headers_as_dict(), |
| 186 KEY__ROOT__EXTRACOLUMNORDER: column_ids_in_order, | 195 KEY__ROOT__EXTRACOLUMNORDER: column_ids_in_order, |
| 187 KEY__ROOT__IMAGEPAIRS: self._image_pair_dicts, | 196 KEY__ROOT__IMAGEPAIRS: self._image_pair_dicts, |
| 188 KEY__ROOT__IMAGESETS: { | 197 KEY__ROOT__IMAGESETS: { |
| 189 KEY__IMAGESETS__SET__IMAGE_A: { | 198 KEY__IMAGESETS__SET__IMAGE_A: { |
| 190 key_description: self._descriptions[0], | 199 key_description: self._descriptions[0], |
| 191 key_base_url: value_base_url, | 200 key_base_url: valueA_base_url, |
| 192 }, | 201 }, |
| 193 KEY__IMAGESETS__SET__IMAGE_B: { | 202 KEY__IMAGESETS__SET__IMAGE_B: { |
| 194 key_description: self._descriptions[1], | 203 key_description: self._descriptions[1], |
| 195 key_base_url: value_base_url, | 204 key_base_url: valueB_base_url, |
| 196 }, | 205 }, |
| 197 KEY__IMAGESETS__SET__DIFFS: { | 206 KEY__IMAGESETS__SET__DIFFS: { |
| 198 key_description: 'color difference per channel', | 207 key_description: 'color difference per channel', |
| 199 key_base_url: posixpath.join( | 208 key_base_url: posixpath.join( |
| 200 self._diff_base_url, imagediffdb.RGBDIFFS_SUBDIR), | 209 self._diff_base_url, imagediffdb.RGBDIFFS_SUBDIR), |
| 201 }, | 210 }, |
| 202 KEY__IMAGESETS__SET__WHITEDIFFS: { | 211 KEY__IMAGESETS__SET__WHITEDIFFS: { |
| 203 key_description: 'differing pixels in white', | 212 key_description: 'differing pixels in white', |
| 204 key_base_url: posixpath.join( | 213 key_base_url: posixpath.join( |
| 205 self._diff_base_url, imagediffdb.WHITEDIFFS_SUBDIR), | 214 self._diff_base_url, imagediffdb.WHITEDIFFS_SUBDIR), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 216 anyfile_utils.py for copying files between HTTP/GS/local filesystem') | 225 anyfile_utils.py for copying files between HTTP/GS/local filesystem') |
| 217 | 226 |
| 218 Args: | 227 Args: |
| 219 gs_url: "gs://bucket/path" format URL | 228 gs_url: "gs://bucket/path" format URL |
| 220 """ | 229 """ |
| 221 bucket, path = gs_utils.GSUtils.split_gs_url(gs_url) | 230 bucket, path = gs_utils.GSUtils.split_gs_url(gs_url) |
| 222 http_url = 'http://storage.cloud.google.com/' + bucket | 231 http_url = 'http://storage.cloud.google.com/' + bucket |
| 223 if path: | 232 if path: |
| 224 http_url += '/' + path | 233 http_url += '/' + path |
| 225 return http_url | 234 return http_url |
| OLD | NEW |