summaryrefslogtreecommitdiff
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2010-04-19 22:30:51 +0000
committerTarek Ziadé <ziade.tarek@gmail.com>2010-04-19 22:30:51 +0000
commit5340db38034557204de5629a4a136d0da2acd3c4 (patch)
tree19162e5a8ffb291853eb5fd238fa394d2076d45c /Lib/shutil.py
parent5fb313bb04dae9bbae82d5ca16ee1cc4e02a5e47 (diff)
downloadcpython-git-5340db38034557204de5629a4a136d0da2acd3c4.tar.gz
Fixed #1540112: now shutil.copytree will let you provide your own copy() function
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 8ad0c64293..f3a31a4ff4 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -147,8 +147,8 @@ def ignore_patterns(*patterns):
return set(ignored_names)
return _ignore_patterns
-def copytree(src, dst, symlinks=False, ignore=None):
- """Recursively copy a directory tree using copy2().
+def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2):
+ """Recursively copy a directory tree.
The destination directory must not already exist.
If exception(s) occur, an Error is raised with a list of reasons.
@@ -170,7 +170,10 @@ def copytree(src, dst, symlinks=False, ignore=None):
list of names relative to the `src` directory that should
not be copied.
- XXX Consider this example code rather than the ultimate tool.
+ The optional copy_function argument is a callable that will be used
+ to copy each file. It will be called with the source path and the
+ destination path as arguments. By default, copy2() is used, but any
+ function that supports the same signature (like copy()) can be used.
"""
names = os.listdir(src)
@@ -191,10 +194,10 @@ def copytree(src, dst, symlinks=False, ignore=None):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
- copytree(srcname, dstname, symlinks, ignore)
+ copytree(srcname, dstname, symlinks, ignore, copy_function)
else:
# Will raise a SpecialFileError for unsupported file types
- copy2(srcname, dstname)
+ copy_function(srcname, dstname)
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error as err: