| OLD | NEW |
| (Empty) |
| 1 # Copyright 2012 Google Inc. All Rights Reserved. | |
| 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 from gslib.exception import CommandException | |
| 24 | |
| 25 | |
| 26 class StorageUriBuilder(object): | |
| 27 | |
| 28 def __init__(self, debug, bucket_storage_uri_class): | |
| 29 """ | |
| 30 Args: | |
| 31 debug: Debug level to pass in to boto connection (range 0..3). | |
| 32 bucket_storage_uri_class: Class to instantiate for cloud StorageUris. | |
| 33 Settable for testing/mocking. | |
| 34 """ | |
| 35 self.bucket_storage_uri_class = bucket_storage_uri_class | |
| 36 self.debug = debug | |
| 37 | |
| 38 def StorageUri(self, uri_str, is_latest=False): | |
| 39 """ | |
| 40 Instantiates StorageUri using class state and gsutil default flag values. | |
| 41 | |
| 42 Args: | |
| 43 uri_str: StorageUri naming bucket or object. | |
| 44 is_latest: boolean indicating whether this versioned object represents the | |
| 45 current version. | |
| 46 | |
| 47 Returns: | |
| 48 boto.StorageUri for given uri_str. | |
| 49 | |
| 50 Raises: | |
| 51 InvalidUriError: if uri_str not valid. | |
| 52 """ | |
| 53 return boto.storage_uri( | |
| 54 uri_str, 'file', debug=self.debug, validate=False, | |
| 55 bucket_storage_uri_class=self.bucket_storage_uri_class, | |
| 56 suppress_consec_slashes=False, is_latest=is_latest) | |
| OLD | NEW |