fs.copy¶
Functions for copying resources between filesystem.
-
fs.copy.copy_dir(src_fs, src_path, dst_fs, dst_path, walker=None, on_copy=None, workers=0, preserve_time=False)[source]¶ Copy a directory from one filesystem to another.
Parameters: - src_fs (FS or str) – Source filesystem (instance or URL).
- src_path (str) – Path to a directory on the source filesystem.
- dst_fs (FS or str) – Destination filesystem (instance or URL).
- dst_path (str) – Path to a directory on the destination filesystem.
- walker (Walker, optional) – A walker object that will be
used to scan for files in
src_fs. Set this if you only want to consider a sub-set of the resources insrc_fs. - on_copy (callable, optional) – A function callback called after
a single file copy is executed. Expected signature is
(src_fs, src_path, dst_fs, dst_path). - workers (int) – Use
workerthreads to copy data, or0(default) for a single-threaded copy. - preserve_time (bool) – If
True, try to preserve mtime of the resources (defaults toFalse).
-
fs.copy.copy_dir_if(src_fs, src_path, dst_fs, dst_path, condition, walker=None, on_copy=None, workers=0, preserve_time=False)[source]¶ Copy a directory from one filesystem to another, depending on a condition.
Parameters: - src_fs (FS or str) – Source filesystem (instance or URL).
- src_path (str) – Path to a directory on the source filesystem.
- dst_fs (FS or str) – Destination filesystem (instance or URL).
- dst_path (str) – Path to a directory on the destination filesystem.
- condition (str) – Name of the condition to check for each file.
- walker (Walker, optional) – A walker object that will be
used to scan for files in
src_fs. Set this if you only want to consider a sub-set of the resources insrc_fs. - on_copy (callable) – A function callback called after a single file copy
is executed. Expected signature is
(src_fs, src_path, dst_fs, dst_path). - workers (int) – Use
workerthreads to copy data, or0(default) for a single-threaded copy. - preserve_time (bool) – If
True, try to preserve mtime of the resources (defaults toFalse).
See also
copy_file_iffor the full list of supported values for theconditionargument.
-
fs.copy.copy_dir_if_newer(src_fs, src_path, dst_fs, dst_path, walker=None, on_copy=None, workers=0, preserve_time=False)[source]¶ Copy a directory from one filesystem to another, checking times.
Deprecated since version 2.5.0: Use
copy_dir_ifwithcondition="newer"instead.
-
fs.copy.copy_file(src_fs, src_path, dst_fs, dst_path, preserve_time=False)[source]¶ Copy a file from one filesystem to another.
If the destination exists, and is a file, it will be first truncated.
Parameters: - src_fs (FS or str) – Source filesystem (instance or URL).
- src_path (str) – Path to a file on the source filesystem.
- dst_fs (FS or str) – Destination filesystem (instance or URL).
- dst_path (str) – Path to a file on the destination filesystem.
- preserve_time (bool) – If
True, try to preserve mtime of the resource (defaults toFalse).
-
fs.copy.copy_file_if(src_fs, src_path, dst_fs, dst_path, condition, preserve_time=False)[source]¶ Copy a file from one filesystem to another, depending on a condition.
Depending on the value of
condition, certain requirements must be fulfilled for a file to be copied todst_fs. The following values are supported:"always"- The source file is always copied.
"newer"- The last modification time of the source file must be newer than that of the destination file. If either file has no modification time, the copy is performed always.
"older"- The last modification time of the source file must be older than that of the destination file. If either file has no modification time, the copy is performed always.
"exists"- The source file is only copied if a file of the same path already
exists in
dst_fs. "not_exists"- The source file is only copied if no file of the same path already
exists in
dst_fs.
Parameters: - src_fs (FS or str) – Source filesystem (instance or URL).
- src_path (str) – Path to a file on the source filesystem.
- dst_fs (FS or str) – Destination filesystem (instance or URL).
- dst_path (str) – Path to a file on the destination filesystem.
- condition (str) – Name of the condition to check for each file.
- preserve_time (bool) – If
True, try to preserve mtime of the resource (defaults toFalse).
Returns: Return type:
-
fs.copy.copy_file_if_newer(src_fs, src_path, dst_fs, dst_path, preserve_time=False)[source]¶ Copy a file from one filesystem to another, checking times.
Deprecated since version 2.5.0: Use
copy_file_ifwithcondition="newer"instead.
-
fs.copy.copy_file_internal(src_fs, src_path, dst_fs, dst_path, preserve_time=False, lock=False)[source]¶ Copy a file at low level, without calling
manage_fsor locking.If the destination exists, and is a file, it will be first truncated.
This method exists to optimize copying in loops. In general you should prefer
copy_file.Parameters: - src_fs (FS) – Source filesystem.
- src_path (str) – Path to a file on the source filesystem.
- dst_fs (FS) – Destination filesystem.
- dst_path (str) – Path to a file on the destination filesystem.
- preserve_time (bool) – If
True, try to preserve mtime of the resource (defaults toFalse). - lock (bool) – Lock both filesystems before copying.
-
fs.copy.copy_fs(src_fs, dst_fs, walker=None, on_copy=None, workers=0, preserve_time=False)[source]¶ Copy the contents of one filesystem to another.
Parameters: - src_fs (FS or str) – Source filesystem (URL or instance).
- dst_fs (FS or str) – Destination filesystem (URL or instance).
- walker (Walker, optional) – A walker object that will be
used to scan for files in
src_fs. Set this if you only want to consider a sub-set of the resources insrc_fs. - on_copy (callable) – A function callback called after a single file copy
is executed. Expected signature is
(src_fs, src_path, dst_fs, dst_path). - workers (int) – Use
workerthreads to copy data, or0(default) for a single-threaded copy. - preserve_time (bool) – If
True, try to preserve mtime of the resources (defaults toFalse).
-
fs.copy.copy_fs_if(src_fs, dst_fs, condition='always', walker=None, on_copy=None, workers=0, preserve_time=False)[source]¶ Copy the contents of one filesystem to another, depending on a condition.
Parameters: - src_fs (FS or str) – Source filesystem (URL or instance).
- dst_fs (FS or str) – Destination filesystem (URL or instance).
- condition (str) – Name of the condition to check for each file.
- walker (Walker, optional) – A walker object that will be
used to scan for files in
src_fs. Set this if you only want to consider a sub-set of the resources insrc_fs. - on_copy (callable) – A function callback called after a single file copy
is executed. Expected signature is
(src_fs, src_path, dst_fs, dst_path). - workers (int) – Use
workerthreads to copy data, or0(default) for a single-threaded copy. - preserve_time (bool) – If
True, try to preserve mtime of the resources (defaults toFalse).
See also
copy_file_iffor the full list of supported values for theconditionargument.
-
fs.copy.copy_fs_if_newer(src_fs, dst_fs, walker=None, on_copy=None, workers=0, preserve_time=False)[source]¶ Copy the contents of one filesystem to another, checking times.
Deprecated since version 2.5.0: Use
copy_fs_ifwithcondition="newer"instead.
-
fs.copy.copy_modified_time(src_fs, src_path, dst_fs, dst_path)[source]¶ Copy modified time metadata from one file to another.
Parameters:
-
fs.copy.copy_structure(src_fs, dst_fs, walker=None, src_root='/', dst_root='/')[source]¶ Copy directories (but not files) from
src_fstodst_fs.Parameters: - src_fs (FS or str) – Source filesystem (instance or URL).
- dst_fs (FS or str) – Destination filesystem (instance or URL).
- walker (Walker, optional) – A walker object that will be
used to scan for files in
src_fs. Set this if you only want to consider a sub-set of the resources insrc_fs. - src_root (str) – Path of the base directory to consider as the root of the tree structure to copy.
- dst_root (str) – Path to the target root of the tree structure.