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
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.

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

try:
from urllib.parse import quote, unquote
Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import Any, Dict

try:
from urllib.parse import urlparse, quote
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# license information.
# --------------------------------------------------------------------------
# pylint: disable=invalid-overridden-method
from typing import Any

try:
from urllib.parse import quote, unquote
except ImportError:
Expand Down Expand Up @@ -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
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# license information.
# --------------------------------------------------------------------------
# pylint: disable=invalid-overridden-method
from azure.core.exceptions import HttpResponseError

from typing import Any
try:
from urllib.parse import quote, unquote
except ImportError:
from urllib2 import quote, unquote # type: ignore

from azure.core.exceptions import HttpResponseError
from ._download_async import StorageStreamDownloader
from ._path_client_async import PathClient
from .._data_lake_file_client import DataLakeFileClient as DataLakeFileClientBase
Expand Down Expand Up @@ -130,6 +130,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
"""
Expand Down Expand Up @@ -461,9 +472,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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]]
Expand Down
Loading