| OLD | NEW | 
|    1 #!/usr/bin/python |    1 #!/usr/bin/python | 
|    2  |    2  | 
|    3 """ |    3 """ | 
|    4 Copyright 2013 Google Inc. |    4 Copyright 2013 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 Calulate differences between image pairs, and store them in a database. |    9 Calulate differences between image pairs, and store them in a database. | 
|   10 """ |   10 """ | 
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  168       # write the image files into, rather than having to move them around |  168       # write the image files into, rather than having to move them around | 
|  169       # after skpdiff writes them out. |  169       # after skpdiff writes them out. | 
|  170       shutil.copyfile(rgb_diff_path, |  170       shutil.copyfile(rgb_diff_path, | 
|  171                       os.path.join(storage_root, RGBDIFFS_SUBDIR, basename)) |  171                       os.path.join(storage_root, RGBDIFFS_SUBDIR, basename)) | 
|  172       shutil.copyfile(white_diff_path, |  172       shutil.copyfile(white_diff_path, | 
|  173                       os.path.join(storage_root, WHITEDIFFS_SUBDIR, basename)) |  173                       os.path.join(storage_root, WHITEDIFFS_SUBDIR, basename)) | 
|  174  |  174  | 
|  175     finally: |  175     finally: | 
|  176       shutil.rmtree(skpdiff_output_dir) |  176       shutil.rmtree(skpdiff_output_dir) | 
|  177  |  177  | 
 |  178   # TODO(epoger): Use properties instead of getters throughout. | 
 |  179   # See http://stackoverflow.com/a/6618176 | 
|  178   def get_num_pixels_differing(self): |  180   def get_num_pixels_differing(self): | 
|  179     """Returns the absolute number of pixels that differ.""" |  181     """Returns the absolute number of pixels that differ.""" | 
|  180     return self._num_pixels_differing |  182     return self._num_pixels_differing | 
|  181  |  183  | 
|  182   def get_percent_pixels_differing(self): |  184   def get_percent_pixels_differing(self): | 
|  183     """Returns the percentage of pixels that differ, as a float between |  185     """Returns the percentage of pixels that differ, as a float between | 
|  184     0 and 100 (inclusive).""" |  186     0 and 100 (inclusive).""" | 
|  185     return ((float(self._num_pixels_differing) * 100) / |  187     return ((float(self._num_pixels_differing) * 100) / | 
|  186             (self._width * self._height)) |  188             (self._width * self._height)) | 
|  187  |  189  | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|  214     """ |  216     """ | 
|  215     Args: |  217     Args: | 
|  216       storage_root: string; root path within the DB will store all of its stuff |  218       storage_root: string; root path within the DB will store all of its stuff | 
|  217     """ |  219     """ | 
|  218     self._storage_root = storage_root |  220     self._storage_root = storage_root | 
|  219  |  221  | 
|  220     # Dictionary of DiffRecords, keyed by (expected_image_locator, |  222     # Dictionary of DiffRecords, keyed by (expected_image_locator, | 
|  221     # actual_image_locator) tuples. |  223     # actual_image_locator) tuples. | 
|  222     self._diff_dict = {} |  224     self._diff_dict = {} | 
|  223  |  225  | 
 |  226   @property | 
 |  227   def storage_root(self): | 
 |  228     return self._storage_root | 
 |  229  | 
|  224   def add_image_pair(self, |  230   def add_image_pair(self, | 
|  225                      expected_image_url, expected_image_locator, |  231                      expected_image_url, expected_image_locator, | 
|  226                      actual_image_url, actual_image_locator): |  232                      actual_image_url, actual_image_locator): | 
|  227     """Download this pair of images (unless we already have them on local disk), |  233     """Download this pair of images (unless we already have them on local disk), | 
|  228     and prepare a DiffRecord for them. |  234     and prepare a DiffRecord for them. | 
|  229  |  235  | 
|  230     TODO(epoger): Make this asynchronously download images, rather than blocking |  236     TODO(epoger): Make this asynchronously download images, rather than blocking | 
|  231     until the images have been downloaded and processed. |  237     until the images have been downloaded and processed. | 
|  232     When we do that, we should probably add a new method that will block |  238     When we do that, we should probably add a new method that will block | 
|  233     until all of the images have been downloaded and processed.  Otherwise, |  239     until all of the images have been downloaded and processed.  Otherwise, | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  324  |  330  | 
|  325   Args: |  331   Args: | 
|  326     expected_image_locator: locator string pointing at expected image |  332     expected_image_locator: locator string pointing at expected image | 
|  327     actual_image_locator: locator string pointing at actual image |  333     actual_image_locator: locator string pointing at actual image | 
|  328  |  334  | 
|  329   Returns: already-sanitized locator where the diffs between expected and |  335   Returns: already-sanitized locator where the diffs between expected and | 
|  330       actual images can be found |  336       actual images can be found | 
|  331   """ |  337   """ | 
|  332   return "%s-vs-%s" % (_sanitize_locator(expected_image_locator), |  338   return "%s-vs-%s" % (_sanitize_locator(expected_image_locator), | 
|  333                        _sanitize_locator(actual_image_locator)) |  339                        _sanitize_locator(actual_image_locator)) | 
| OLD | NEW |