Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added exists() to Datalake clients #16733

Merged
merged 4 commits into from
Feb 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added exists() to Datalake clients
  • Loading branch information
tasherif-msft committed Feb 13, 2021
commit d67af2b766c79713a52b6cd0a9c94839abd042c5
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import Any

try:
from urllib.parse import quote, unquote
except ImportError:
@@ -241,9 +243,19 @@ def get_directory_properties(self, **kwargs):
"""
return self._get_path_properties(cls=deserialize_dir_properties, **kwargs) # pylint: disable=protected-access

def rename_directory(self, new_name, # type: str
**kwargs):
# type: (**Any) -> DataLakeDirectoryClient
def exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a directory exists and returns False otherwise.

:kwarg int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
return self._exists(**kwargs)

def rename_directory(self, new_name, **kwargs):
# type: (str, **Any) -> DataLakeDirectoryClient
"""
Rename the source directory.

Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
# license information.
# --------------------------------------------------------------------------
from io import BytesIO
from typing import Any

try:
from urllib.parse import quote, unquote
@@ -596,9 +597,19 @@ def download_file(self, offset=None, length=None, **kwargs):
downloader = self._blob_client.download_blob(offset=offset, length=length, **kwargs)
return StorageStreamDownloader(downloader)

def rename_file(self, new_name, # type: str
**kwargs):
# type: (**Any) -> DataLakeFileClient
def exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a file exists and returns False otherwise.

:kwarg int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
return self._exists(**kwargs)

def rename_file(self, new_name, **kwargs):
# type: (str, **Any) -> DataLakeFileClient
"""
Rename the source file.

Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import Optional
from typing import Optional, Any

try:
from urllib.parse import urlparse, quote
@@ -247,6 +247,17 @@ def create_file_system(self, metadata=None, # type: Optional[Dict[str, str]]
public_access=public_access,
**kwargs)

def exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a file system exists and returns False otherwise.

:kwarg int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
return self._container_client.exists(**kwargs)

def _rename_file_system(self, new_name, **kwargs):
# type: (str, **Any) -> FileSystemClient
"""Renames a filesystem.
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
from urllib2 import quote # type: ignore

import six
from typing import Any, Dict

from azure.core.exceptions import AzureError, HttpResponseError
from azure.storage.blob import BlobClient
@@ -657,9 +658,8 @@ def _rename_path_options(self, rename_source, content_settings=None, metadata=No
options.update(kwargs)
return options

def _rename_path(self, rename_source,
**kwargs):
# type: (**Any) -> Dict[str, Any]
def _rename_path(self, rename_source, **kwargs):
# type: (str, **Any) -> Dict[str, Any]
"""
Rename directory or file

@@ -764,6 +764,17 @@ def _get_path_properties(self, **kwargs):
path_properties = self._blob_client.get_blob_properties(**kwargs)
return path_properties

def _exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a path exists and returns False otherwise.

:kwarg int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
return self._blob_client.exists(**kwargs)

def set_metadata(self, metadata, # type: Dict[str, str]
**kwargs):
# type: (...) -> Dict[str, Union[str, datetime]]
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
# license information.
# --------------------------------------------------------------------------
# pylint: disable=invalid-overridden-method
from typing import Any

try:
from urllib.parse import quote, unquote
except ImportError:
@@ -128,6 +130,17 @@ async def create_directory(self, metadata=None, # type: Optional[Dict[str, str]
"""
return await self._create('directory', metadata=metadata, **kwargs)

async def exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a directory exists and returns False otherwise.

:kwarg int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
return await self._exists(**kwargs)

async def delete_directory(self, **kwargs):
# type: (...) -> None
"""
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
# pylint: disable=invalid-overridden-method
from azure.core.exceptions import HttpResponseError

from typing import Any
try:
from urllib.parse import quote, unquote
except ImportError:
@@ -130,6 +131,17 @@ async def create_file(self, content_settings=None, # type: Optional[ContentSett
"""
return await self._create('file', content_settings=content_settings, metadata=metadata, **kwargs)

async def exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a file exists and returns False otherwise.

:kwarg int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
return await self._exists(**kwargs)

async def delete_file(self, **kwargs):
# type: (...) -> None
"""
@@ -461,9 +473,8 @@ async def download_file(self, offset=None, length=None, **kwargs):
downloader = await self._blob_client.download_blob(offset=offset, length=length, **kwargs)
return StorageStreamDownloader(downloader)

async def rename_file(self, new_name, # type: str
**kwargs):
# type: (**Any) -> DataLakeFileClient
async def rename_file(self, new_name, **kwargs):
# type: (str, **Any) -> DataLakeFileClient
"""
Rename the source file.

Original file line number Diff line number Diff line change
@@ -193,6 +193,19 @@ async def create_file_system(self, metadata=None, # type: Optional[Dict[str, st
return await self._container_client.create_container(metadata=metadata,
public_access=public_access,
**kwargs)

@distributed_trace_async
async def exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a file system exists and returns False otherwise.

:kwarg int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
return await self._container_client.exists(**kwargs)

@distributed_trace_async
async def _rename_file_system(self, new_name, **kwargs):
# type: (str, **Any) -> FileSystemClient
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
# license information.
# --------------------------------------------------------------------------
# pylint: disable=invalid-overridden-method
from typing import Any, Dict

from azure.core.exceptions import AzureError, HttpResponseError
from azure.storage.blob.aio import BlobClient
from .._shared.base_client_async import AsyncStorageAccountHostsMixin
@@ -489,9 +491,8 @@ async def _set_access_control_internal(self, options, progress_hook, max_batches
error.continuation_token = last_continuation_token
raise error

async def _rename_path(self, rename_source,
**kwargs):
# type: (**Any) -> Dict[str, Any]
async def _rename_path(self, rename_source, **kwargs):
# type: (str, **Any) -> Dict[str, Any]
"""
Rename directory or file

@@ -585,6 +586,17 @@ async def _get_path_properties(self, **kwargs):
path_properties = await self._blob_client.get_blob_properties(**kwargs)
return path_properties

async def _exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a path exists and returns False otherwise.

:kwarg int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
return await self._blob_client.exists(**kwargs)

async def set_metadata(self, metadata, # type: Dict[str, str]
**kwargs):
# type: (...) -> Dict[str, Union[str, datetime]]