cpython: cf57ef65bcd0 (original) (raw)

--- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -45,7 +45,7 @@ Directory and files operations be copied. -.. function:: copyfile(src, dst) +.. function:: copyfile(src, dst[, symlinks=False]) Copy the contents (no metadata) of the file named src to a file named dst. dst must be the complete target file name; look at :func:copy for a copy that @@ -56,37 +56,56 @@ Directory and files operations such as character or block devices and pipes cannot be copied with this function. src and dst are path names given as strings.

-.. function:: copymode(src, dst) +.. function:: copymode(src, dst[, symlinks=False]) Copy the permission bits from src to dst. The file contents, owner, and

-.. function:: copystat(src, dst) +.. function:: copystat(src, dst[, symlinks=False]) Copy the permission bits, last access time, last modification time, and flags from src to dst. The file contents, owner, and group are unaffected. src

-.. function:: copy(src, dst) +.. function:: copy(src, dst[, symlinks=False])) Copy the file src to the file or directory dst. If dst is a directory, a file with the same basename as src is created (or overwritten) in the directory specified. Permission bits are copied. src and dst are path

-.. function:: copy2(src, dst) +.. function:: copy2(src, dst[, symlinks=False]) Similar to :func:copy, but metadata is copied as well -- in fact, this is just :func:copy followed by :func:copystat. This is similar to the

.. function:: ignore_patterns(*patterns) @@ -104,9 +123,9 @@ Directory and files operations :func:copy2. If symlinks is true, symbolic links in the source tree are represented as

+ .. function:: rmtree(path, ignore_errors=False, onerror=None)

--- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -82,8 +82,13 @@ def _samefile(src, dst): return (os.path.normcase(os.path.abspath(src)) == os.path.normcase(os.path.abspath(dst))) -def copyfile(src, dst):

+def copyfile(src, dst, symlinks=False):

+

+

@@ -98,54 +103,94 @@ def copyfile(src, dst): if stat.S_ISFIFO(st.st_mode): raise SpecialFileError("%s is a named pipe" % fn)

+ +def copymode(src, dst, symlinks=False):

+

-def copymode(src, dst):

+

-def copystat(src, dst):

+def copystat(src, dst, symlinks=False):

+

+

+

+

-def copy(src, dst): +def copy(src, dst, symlinks=False): """Copy data and mode bits ("cp src dst"). The destination may be a directory.

+ """ if os.path.isdir(dst): dst = os.path.join(dst, os.path.basename(src))

-def copy2(src, dst): +def copy2(src, dst, symlinks=False): """Copy data and all stat info ("cp -p src dst"). The destination may be a directory.

+ """ if os.path.isdir(dst): dst = os.path.join(dst, os.path.basename(src))

def ignore_patterns(*patterns): """Function that can be used as copytree() ignore parameter. @@ -212,7 +257,11 @@ def copytree(src, dst, symlinks=False, i if os.path.islink(srcname): linkto = os.readlink(srcname) if symlinks:

--- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -164,6 +164,197 @@ class TestShutil(unittest.TestCase): self.assertTrue(issubclass(exc[0], OSError)) self.errorState = 2

+

+

+

+

+

+

+ def test_rmtree_dont_delete_file(self): # When called on a file instead of a directory, don't delete it. handle, path = tempfile.mkstemp() @@ -190,6 +381,34 @@ class TestShutil(unittest.TestCase): actual = read_file((dst_dir, 'test_dir', 'test.txt')) self.assertEqual(actual, '456')

+ def test_copytree_with_exclude(self): # creating data join = os.path.join

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -422,6 +422,11 @@ Core and Builtins Library ------- +- Issue #12715: Add an optional symlinks argument to shutil functions