[ python-Feature Requests-1540112 ] Allow choice of copy function in shutil.copytree
SourceForge.net
noreply at sourceforge.net
Mon Aug 14 19:24:49 CEST 2006
Feature Requests item #1540112, was opened at 2006-08-14 09:49
Message generated for change (Comment added) made by arandrea
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1540112&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Tony (arandrea)
Assigned to: Nobody/Anonymous (nobody)
Summary: Allow choice of copy function in shutil.copytree
Initial Comment:
It would be nice to be able to choose which of the copy
functions is used in copytree. I am currently working
on a project where I would like to copy a tree, but I
do not want to preserve permissions so I'd like
copytree to use copyfile instead of copy2.
Here is a snippet of copytree from shutil.py that I
modified by adding a func parameter and defaulting it
to copy2.
def copytree(src, dst, symlinks=False, func=copy2):
.
.
.
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, symlinks)
else:
func(srcname, dstname)
.
.
.
----------------------------------------------------------------------
>Comment By: Tony (arandrea)
Date: 2006-08-14 10:24
Message:
Logged In: YES
user_id=1575524
I guess I should have tested it first. I forgot to add the
func parameter to the copytree call within copytree.
Something like this:
.try:
. if symlinks and os.path.islink(srcname):
. linkto = os.readlink(srcname)
. os.symlink(linkto, dstname)
. elif os.path.isdir(srcname):
. copytree(srcname, dstname, symlinks, func)
. else:
. func(srcname, dstname)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1540112&group_id=5470
More information about the Python-bugs-list
mailing list