本文整理汇总了Python中fs.base.FS._shutil_copyfile方法的典型用法代码示例。如果您正苦于以下问题:Python FS._shutil_copyfile方法的具体用法?Python FS._shutil_copyfile怎么用?Python FS._shutil_copyfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs.base.FS
的用法示例。
在下文中一共展示了FS._shutil_copyfile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copyfile
# 需要导入模块: from fs.base import FS [as 别名]
# 或者: from fs.base.FS import _shutil_copyfile [as 别名]
def copyfile(src_fs, src_path, dst_fs, dst_path, overwrite=True, update=False,
chunk_size=64*1024):
"""Copy a file from one filesystem to another. Will use system copyfile, if both files have a syspath.
Otherwise file will be copied a chunk at a time. In the case where ``overwrite`` is False and
``update`` is True, the behaviour of ``update`` takes precedence.
:param src_fs: Source filesystem object
:param src_path: -- Source path
:param dst_fs: Destination filesystem object
:param dst_path: Destination filesystem object
:param overwrite: Write to destination files even if they already exist
:param update: Write to destination files only if the source is newer
:param chunk_size: Size of chunks to move if system copyfile is not available (default 64K)
"""
assert_write(src_fs, src_path, dst_fs, dst_path, overwrite, update)
# If the src and dst fs objects are the same, then use a direct copy
if src_fs is dst_fs:
src_fs.copy(src_path, dst_path, overwrite=overwrite)
return
src_syspath = src_fs.getsyspath(src_path, allow_none=True)
dst_syspath = dst_fs.getsyspath(dst_path, allow_none=True)
# System copy if there are two sys paths
if src_syspath is not None and dst_syspath is not None:
FS._shutil_copyfile(src_syspath, dst_syspath)
return
src_lock = getattr(src_fs, '_lock', None)
if src_lock is not None:
src_lock.acquire()
try:
src = None
try:
src = src_fs.open(src_path, 'rb')
dst_fs.setcontents(dst_path, src, chunk_size=chunk_size)
finally:
if src is not None:
src.close()
finally:
if src_lock is not None:
src_lock.release()
示例2: copyfile
# 需要导入模块: from fs.base import FS [as 别名]
# 或者: from fs.base.FS import _shutil_copyfile [as 别名]
def copyfile(src_fs, src_path, dst_fs, dst_path, overwrite=True, chunk_size=64*1024):
"""Copy a file from one filesystem to another. Will use system copyfile, if both files have a syspath.
Otherwise file will be copied a chunk at a time.
:param src_fs: Source filesystem object
:param src_path: -- Source path
:param dst_fs: Destination filesystem object
:param dst_path: Destination filesystem object
:param chunk_size: Size of chunks to move if system copyfile is not available (default 64K)
"""
# If the src and dst fs objects are the same, then use a direct copy
if src_fs is dst_fs:
src_fs.copy(src_path, dst_path, overwrite=overwrite)
return
src_syspath = src_fs.getsyspath(src_path, allow_none=True)
dst_syspath = dst_fs.getsyspath(dst_path, allow_none=True)
if not overwrite and dst_fs.exists(dst_path):
raise DestinationExistsError(dst_path)
# System copy if there are two sys paths
if src_syspath is not None and dst_syspath is not None:
FS._shutil_copyfile(src_syspath, dst_syspath)
return
src_lock = getattr(src_fs, '_lock', None)
if src_lock is not None:
src_lock.acquire()
try:
src = None
try:
src = src_fs.open(src_path, 'rb')
dst_fs.setcontents(dst_path, src, chunk_size=chunk_size)
finally:
if src is not None:
src.close()
finally:
if src_lock is not None:
src_lock.release()