def test_execute_fails_for_inter_cloud_copy(self): source_resource = test_resources.from_url_string('s3://b/o1.txt') destination_resource = test_resources.from_url_string('gs://b/o2.txt') with self.assertRaises(ValueError): intra_cloud_copy_task.IntraCloudCopyTask(source_resource, destination_resource)
def test_execute_copies_file(self, mock_client): source_resource = test_resources.from_url_string('gs://b/o1.txt') destination_resource = test_resources.from_url_string('gs://b/o2.txt') task = intra_cloud_copy_task.IntraCloudCopyTask( source_resource, destination_resource) task.execute() mock_client.copy_object.assert_called_once_with( source_resource, destination_resource)
def get_copy_task(source_resource, destination_resource): """Factory method that returns the correct copy task for the arguments. Args: source_resource (resource_reference.Resource): Reference to file to copy. destination_resource (resource_reference.Resource): Reference to destination to copy file to. Returns: Task object that can be executed to perform a copy. Raises: NotImplementedError: Cross-cloud copy. ValueError: Local filesystem copy. """ source_url = source_resource.storage_url destination_url = destination_resource.storage_url if (isinstance(source_url, storage_url.FileUrl) and isinstance(destination_url, storage_url.FileUrl)): raise ValueError( 'Local copies not supported. Gcloud command-line tool is' ' meant for cloud operations.') if (isinstance(source_url, storage_url.CloudUrl) and isinstance(destination_url, storage_url.FileUrl)): return file_download_task.FileDownloadTask(source_resource, destination_resource) if (isinstance(source_url, storage_url.FileUrl) and isinstance(destination_url, storage_url.CloudUrl)): return file_upload_task.FileUploadTask(source_resource, destination_resource) if (isinstance(source_url, storage_url.CloudUrl) and isinstance(destination_url, storage_url.CloudUrl)): if source_url.scheme != destination_url.scheme: return daisy_chain_copy_task.DaisyChainCopyTask( source_resource, destination_resource) return intra_cloud_copy_task.IntraCloudCopyTask( source_resource, destination_resource)
def get_copy_task(source_resource, destination_resource, do_not_decompress=False, print_created_message=False, shared_stream=None, user_request_args=None): """Factory method that returns the correct copy task for the arguments. Args: source_resource (resource_reference.Resource): Reference to file to copy. destination_resource (resource_reference.Resource): Reference to destination to copy file to. do_not_decompress (bool): Prevents automatically decompressing downloaded gzips. print_created_message (bool): Print the versioned URL of each successfully copied object. shared_stream (stream): Multiple tasks may reuse this read or write stream. user_request_args (UserRequestArgs|None): Values for RequestConfig. Returns: Task object that can be executed to perform a copy. Raises: NotImplementedError: Cross-cloud copy. ValueError: Local filesystem copy. """ source_url = source_resource.storage_url destination_url = destination_resource.storage_url if (isinstance(source_url, storage_url.FileUrl) and isinstance(destination_url, storage_url.FileUrl)): raise ValueError( 'Local copies not supported. Gcloud command-line tool is' ' meant for cloud operations.') if (isinstance(source_url, storage_url.CloudUrl) and isinstance(destination_url, storage_url.FileUrl)): if destination_url.is_pipe: return streaming_download_task.StreamingDownloadTask( source_resource, shared_stream, print_created_message=print_created_message, user_request_args=user_request_args) return file_download_task.FileDownloadTask( source_resource, destination_resource, do_not_decompress=do_not_decompress, print_created_message=print_created_message, user_request_args=user_request_args) if (isinstance(source_url, storage_url.FileUrl) and isinstance(destination_url, storage_url.CloudUrl)): return file_upload_task.FileUploadTask( source_resource, destination_resource, print_created_message=print_created_message, user_request_args=user_request_args) if (isinstance(source_url, storage_url.CloudUrl) and isinstance(destination_url, storage_url.CloudUrl)): if source_url.scheme != destination_url.scheme: if getattr(user_request_args.resource_args, 'preserve_acl', False): raise ValueError( 'Cannot preserve ACLs while copying between cloud providers.' ) return daisy_chain_copy_task.DaisyChainCopyTask( source_resource, destination_resource, print_created_message=print_created_message, user_request_args=user_request_args) return intra_cloud_copy_task.IntraCloudCopyTask( source_resource, destination_resource, print_created_message=print_created_message, user_request_args=user_request_args)