本文整理匯總了Python中waterbutler.core.path.WaterButlerPath.rename方法的典型用法代碼示例。如果您正苦於以下問題:Python WaterButlerPath.rename方法的具體用法?Python WaterButlerPath.rename怎麽用?Python WaterButlerPath.rename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類waterbutler.core.path.WaterButlerPath
的用法示例。
在下文中一共展示了WaterButlerPath.rename方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_rename
# 需要導入模塊: from waterbutler.core.path import WaterButlerPath [as 別名]
# 或者: from waterbutler.core.path.WaterButlerPath import rename [as 別名]
def test_rename(self):
path = WaterButlerPath('/this/is/a/long/path')
assert path.name == 'path'
path.rename('journey')
assert path.name == 'journey'
示例2: copy
# 需要導入模塊: from waterbutler.core.path import WaterButlerPath [as 別名]
# 或者: from waterbutler.core.path.WaterButlerPath import rename [as 別名]
async def copy(self,
dest_provider: 'BaseProvider',
src_path: wb_path.WaterButlerPath,
dest_path: wb_path.WaterButlerPath,
rename: str=None, conflict: str='replace',
handle_naming: bool=True) \
-> typing.Tuple[wb_metadata.BaseMetadata, bool]:
args = (dest_provider, src_path, dest_path)
kwargs = {'rename': rename, 'conflict': conflict, 'handle_naming': handle_naming}
self.provider_metrics.add('copy', {
'got_handle_naming': handle_naming,
'conflict': conflict,
'got_rename': rename is not None,
})
if handle_naming:
dest_path = await dest_provider.handle_naming(
src_path,
dest_path,
rename=rename,
conflict=conflict,
)
args = (dest_provider, src_path, dest_path)
kwargs = {}
# files and folders shouldn't overwrite themselves
if (
self.shares_storage_root(dest_provider) and
src_path.materialized_path == dest_path.materialized_path
):
raise exceptions.OverwriteSelfError(src_path)
self.provider_metrics.add('copy.can_intra_copy', False)
if self.can_intra_copy(dest_provider, src_path):
self.provider_metrics.add('copy.can_intra_copy', True)
return await self.intra_copy(*args)
if src_path.is_dir:
return await self._folder_file_op(self.copy, *args, **kwargs) # type: ignore
download_stream = await self.download(src_path)
if getattr(download_stream, 'name', None):
dest_path.rename(download_stream.name)
return await dest_provider.upload(download_stream, dest_path)
示例3: copy
# 需要導入模塊: from waterbutler.core.path import WaterButlerPath [as 別名]
# 或者: from waterbutler.core.path.WaterButlerPath import rename [as 別名]
async def copy(self,
dest_provider: provider.BaseProvider,
src_path: WaterButlerPath,
dest_path: WaterButlerPath,
rename: str=None,
conflict: str='replace',
handle_naming: bool=True) -> typing.Tuple[BaseMetadata, bool]:
"""Override parent's copy to support cross-region osfstorage copies. Delegates to
:meth:`.BaseProvider.copy` when destination is not osfstorage. If both providers are in the
same region (i.e. `.can_intra_copy` is true), call `.intra_copy`. Otherwise, grab a
download stream from the source region, send it to the destination region, *then* execute
an `.intra_copy` to make new file metadata entries in the OSF.
This is needed because a same-region osfstorage copy will duplicate *all* the versions of
the file, but `.BaseProvider.copy` will only copy the most recent version.
"""
# when moving to non-osfstorage, default move is fine
if dest_provider.NAME != 'osfstorage':
return await super().copy(dest_provider, src_path, dest_path, rename=rename,
conflict=conflict, handle_naming=handle_naming)
args = (dest_provider, src_path, dest_path)
kwargs = {'rename': rename, 'conflict': conflict}
self.provider_metrics.add('copy', {
'got_handle_naming': handle_naming,
'conflict': conflict,
'got_rename': rename is not None,
})
if handle_naming:
dest_path = await dest_provider.handle_naming(
src_path,
dest_path,
rename=rename,
conflict=conflict,
)
args = (dest_provider, src_path, dest_path)
kwargs = {}
# files and folders shouldn't overwrite themselves
if (
self.shares_storage_root(dest_provider) and
src_path.materialized_path == dest_path.materialized_path
):
raise exceptions.OverwriteSelfError(src_path)
self.provider_metrics.add('copy.can_intra_copy', False)
if self.can_intra_copy(dest_provider, src_path):
self.provider_metrics.add('copy.can_intra_copy', True)
return await self.intra_copy(*args)
if src_path.is_dir:
meta_data, created = await self._folder_file_op(self.copy, *args, **kwargs) # type: ignore
else:
download_stream = await self.download(src_path)
if getattr(download_stream, 'name', None):
dest_path.rename(download_stream.name)
await dest_provider._send_to_storage_provider(download_stream, # type: ignore
dest_path, **kwargs)
meta_data, created = await self.intra_copy(dest_provider, src_path, dest_path)
return meta_data, created
示例4: move
# 需要導入模塊: from waterbutler.core.path import WaterButlerPath [as 別名]
# 或者: from waterbutler.core.path.WaterButlerPath import rename [as 別名]
async def move(self,
dest_provider: provider.BaseProvider,
src_path: WaterButlerPath,
dest_path: WaterButlerPath,
rename: str=None,
conflict: str='replace',
handle_naming: bool=True) -> typing.Tuple[BaseMetadata, bool]:
"""Override parent's move to support cross-region osfstorage moves while preserving guids
and versions. Delegates to :meth:`.BaseProvider.move` when destination is not osfstorage.
If both providers are in the same region (i.e. `.can_intra_move` is true), then calls that.
Otherwise, will grab a download stream from the source region, send it to the destination
region, *then* execute an `.intra_move` to update the file metada in-place.
"""
# when moving to non-osfstorage, default move is fine
if dest_provider.NAME != 'osfstorage':
return await super().move(dest_provider, src_path, dest_path, rename=rename,
conflict=conflict, handle_naming=handle_naming)
args = (dest_provider, src_path, dest_path)
kwargs = {'rename': rename, 'conflict': conflict}
self.provider_metrics.add('move', {
'got_handle_naming': handle_naming,
'conflict': conflict,
'got_rename': rename is not None,
})
if handle_naming:
dest_path = await dest_provider.handle_naming(
src_path,
dest_path,
rename=rename,
conflict=conflict,
)
args = (dest_provider, src_path, dest_path)
kwargs = {}
# files and folders shouldn't overwrite themselves
if (
self.shares_storage_root(dest_provider) and
src_path.materialized_path == dest_path.materialized_path
):
raise exceptions.OverwriteSelfError(src_path)
self.provider_metrics.add('move.can_intra_move', False)
if self.can_intra_move(dest_provider, src_path):
self.provider_metrics.add('move.can_intra_move', True)
return await self.intra_move(*args)
if src_path.is_dir:
meta_data, created = await self._folder_file_op(self.move, *args, **kwargs) # type: ignore
await self.delete(src_path)
else:
download_stream = await self.download(src_path)
if getattr(download_stream, 'name', None):
dest_path.rename(download_stream.name)
await dest_provider._send_to_storage_provider(download_stream, # type: ignore
dest_path, **kwargs)
meta_data, created = await self.intra_move(dest_provider, src_path, dest_path)
return meta_data, created