| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Internal utilities for managing I-Spy test results in Google Cloud Storage. | 5 """Utilities for managing I-Spy test results in Google Cloud Storage.""" |
| 6 | |
| 7 See the ispy.client.chrome_utils module for the external API. | |
| 8 """ | |
| 9 | 6 |
| 10 import collections | 7 import collections |
| 11 import itertools | 8 import itertools |
| 12 import json | 9 import json |
| 13 import os | 10 import os |
| 14 import sys | 11 import sys |
| 15 | 12 |
| 16 import image_tools | 13 import image_tools |
| 17 | 14 |
| 18 | 15 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 40 """Get the path to a failure file in the given test run and test. | 37 """Get the path to a failure file in the given test run and test. |
| 41 | 38 |
| 42 Args: | 39 Args: |
| 43 test_run: name of the test run. | 40 test_run: name of the test run. |
| 44 expectation: name of the expectation. | 41 expectation: name of the expectation. |
| 45 file_name: name of the file. | 42 file_name: name of the file. |
| 46 | 43 |
| 47 Returns: | 44 Returns: |
| 48 the path as a string relative to the bucket. | 45 the path as a string relative to the bucket. |
| 49 """ | 46 """ |
| 50 return GetTestRunPath(test_run, '%s/%s' % (expectation, file_name)) | 47 return 'failures/%s/%s/%s' % (test_run, expectation, file_name) |
| 51 | |
| 52 | |
| 53 def GetTestRunPath(test_run, file_name=''): | |
| 54 """Get the path to a the given test run. | |
| 55 | |
| 56 Args: | |
| 57 test_run: name of the test run. | |
| 58 file_name: name of the file. | |
| 59 | |
| 60 Returns: | |
| 61 the path as a string relative to the bucket. | |
| 62 """ | |
| 63 return 'failures/%s/%s' % (test_run, file_name) | |
| 64 | 48 |
| 65 | 49 |
| 66 class ISpyUtils(object): | 50 class ISpyUtils(object): |
| 67 """Utility functions for working with an I-Spy google storage bucket.""" | 51 """Utility functions for working with an I-Spy google storage bucket.""" |
| 68 | 52 |
| 69 def __init__(self, cloud_bucket): | 53 def __init__(self, cloud_bucket): |
| 70 """Initialize with a cloud bucket instance to supply GS functionality. | 54 """Initialize with a cloud bucket instance to supply GS functionality. |
| 71 | 55 |
| 72 Args: | 56 Args: |
| 73 cloud_bucket: An object implementing the cloud_bucket.BaseCloudBucket | 57 cloud_bucket: An object implementing the cloud_bucket.BaseCloudBucket |
| (...skipping 27 matching lines...) Expand all Loading... |
| 101 | 85 |
| 102 def UpdateImage(self, full_path, image): | 86 def UpdateImage(self, full_path, image): |
| 103 """Updates an existing image in GS, preserving permissions and metadata. | 87 """Updates an existing image in GS, preserving permissions and metadata. |
| 104 | 88 |
| 105 Args: | 89 Args: |
| 106 full_path: the path to the file in GS including the file extension. | 90 full_path: the path to the file in GS including the file extension. |
| 107 image: a RGB PIL.Image. | 91 image: a RGB PIL.Image. |
| 108 """ | 92 """ |
| 109 self.cloud_bucket.UpdateFile(full_path, image_tools.EncodePNG(image)) | 93 self.cloud_bucket.UpdateFile(full_path, image_tools.EncodePNG(image)) |
| 110 | 94 |
| 95 |
| 111 def GenerateExpectation(self, expectation, images): | 96 def GenerateExpectation(self, expectation, images): |
| 112 """Creates and uploads an expectation to GS from a set of images and name. | 97 """Creates and uploads an expectation to GS from a set of images and name. |
| 113 | 98 |
| 114 This method generates a mask from the uploaded images, then | 99 This method generates a mask from the uploaded images, then |
| 115 uploads the mask and first of the images to GS as a expectation. | 100 uploads the mask and first of the images to GS as a expectation. |
| 116 | 101 |
| 117 Args: | 102 Args: |
| 118 expectation: name for this expectation, any existing expectation with the | 103 expectation: name for this expectation, any existing expectation with the |
| 119 name will be replaced. | 104 name will be replaced. |
| 120 images: a list of RGB encoded PIL.Images | 105 images: a list of RGB encoded PIL.Images |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 280 |
| 296 Args: | 281 Args: |
| 297 prefix: the prefix to filter files in GS by. | 282 prefix: the prefix to filter files in GS by. |
| 298 | 283 |
| 299 Returns: | 284 Returns: |
| 300 a list containing urls to all objects that started with | 285 a list containing urls to all objects that started with |
| 301 the prefix. | 286 the prefix. |
| 302 """ | 287 """ |
| 303 return self.cloud_bucket.GetAllPaths(prefix) | 288 return self.cloud_bucket.GetAllPaths(prefix) |
| 304 | 289 |
| OLD | NEW |