| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2012 Google Inc. |
| 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at |
| 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. |
| 14 |
| 15 """ |
| 16 Class that holds state (bucket_storage_uri_class and debug) needed for |
| 17 instantiating StorageUri objects. The StorageUri func defined in this class |
| 18 uses that state plus gsutil default flag values to instantiate this frequently |
| 19 constructed object with just one param for most cases. |
| 20 """ |
| 21 |
| 22 import boto |
| 23 |
| 24 |
| 25 class StorageUriBuilder(object): |
| 26 |
| 27 def __init__(self, debug, bucket_storage_uri_class): |
| 28 """ |
| 29 Args: |
| 30 debug: Debug level to pass in to boto connection (range 0..3). |
| 31 bucket_storage_uri_class: Class to instantiate for cloud StorageUris. |
| 32 Settable for testing/mocking. |
| 33 """ |
| 34 self.bucket_storage_uri_class = bucket_storage_uri_class |
| 35 self.debug = debug |
| 36 |
| 37 def StorageUri(self, uri_str): |
| 38 """ |
| 39 Instantiates StorageUri using class state and gsutil default flag values. |
| 40 |
| 41 Args: |
| 42 uri_str: StorageUri naming bucket + optional object. |
| 43 |
| 44 Returns: |
| 45 boto.StorageUri for given uri_str. |
| 46 |
| 47 Raises: |
| 48 InvalidUriError: if uri_str not valid. |
| 49 """ |
| 50 return boto.storage_uri( |
| 51 uri_str, 'file', debug=self.debug, validate=False, |
| 52 bucket_storage_uri_class=self.bucket_storage_uri_class, |
| 53 suppress_consec_slashes=False) |
| OLD | NEW |