classification
Title: Allow choice of copy function in shutil.copytree
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.1, Python 2.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: tarek Nosy List: arandrea, tarek
Priority: normal Keywords: easy, patch

Created on 2006-08-14 16:49 by arandrea, last changed 2010-04-19 22:32 by tarek. This issue is now closed.

Messages (3)
msg61252 - (view) Author: Tony (arandrea) Date: 2006-08-14 16:49
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)
.
.
.
msg61253 - (view) Author: Tony (arandrea) Date: 2006-08-14 17:24
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)


msg103651 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2010-04-19 22:32
done in r80230, thanks !
History
Date User Action Args
2010-04-20 14:17:28tareklinkissue8395 superseder
2010-04-19 22:32:36tareksetstatus: open -> closed

nosy: + tarek
messages: + msg103651

assignee: tarek
2009-04-22 05:06:07ajaksu2setkeywords: + easy
2009-03-30 03:52:05ajaksu2setkeywords: + patch
stage: test needed
versions: + Python 3.1, Python 2.7
2006-08-14 16:49:58arandreacreate