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