def _make_dir(self, client_kwargs): """ Make a directory. args: client_kwargs (dict): Client arguments. """ with _handle_azure_exception(): if "directory_name" in client_kwargs: return self.client.create_directory( share_name=client_kwargs["share_name"], directory_name=client_kwargs["directory_name"], ) return self.client.create_share(**client_kwargs)
def copy(self, src, dst, other_system=None): """ Copy object of the same storage. Args: src (str): Path or URL. dst (str): Path or URL. other_system (airfs.storage.azure._AzureBaseSystem subclass): The source storage system. """ with _handle_azure_exception(): self._client_block.copy_blob( copy_source=(other_system or self)._format_src_url(src, self), **self.get_client_kwargs(dst), )
def _list_objects(self, client_kwargs, path, max_results, first_level): """ Lists objects. args: client_kwargs (dict): Client arguments. path (str): Path to list. max_results (int): The maximum results that should return the method. first_level (bool): It True, may only first level objects. Yields: tuple: object path str, object header dict, has content bool """ client_kwargs = self._update_listing_client_kwargs( client_kwargs, max_results) with _handle_azure_exception(): for obj in self.client.list_directories_and_files(**client_kwargs): yield obj.name, self._model_to_dict(obj), isinstance( obj, _Directory)
def _head(self, client_kwargs): """ Returns object or bucket HTTP header. Args: client_kwargs (dict): Client arguments. Returns: dict: HTTP header. """ with _handle_azure_exception(): if "blob_name" in client_kwargs: result = self._client_block.get_blob_properties( **client_kwargs) else: result = self._client_block.get_container_properties( **client_kwargs) return self._model_to_dict(result)
def _head(self, client_kwargs): """ Returns object or bucket HTTP header. Args: client_kwargs (dict): Client arguments. Returns: dict: HTTP header. """ with _handle_azure_exception(): if "file_name" in client_kwargs: result = self.client.get_file_properties(**client_kwargs) elif "directory_name" in client_kwargs: result = self.client.get_directory_properties(**client_kwargs) else: result = self.client.get_share_properties(**client_kwargs) return self._model_to_dict(result)
def _remove(self, client_kwargs): """ Remove an object. args: client_kwargs (dict): Client arguments. """ with _handle_azure_exception(): if "file_name" in client_kwargs: return self.client.delete_file( share_name=client_kwargs["share_name"], directory_name=client_kwargs["directory_name"], file_name=client_kwargs["file_name"], ) elif "directory_name" in client_kwargs: return self.client.delete_directory( share_name=client_kwargs["share_name"], directory_name=client_kwargs["directory_name"], ) return self.client.delete_share( share_name=client_kwargs["share_name"])
def _create(self): """ Create the file if not exists. """ with _handle_azure_exception(): self._client.create_blob(**self._client_kwargs)