From 6f374309f0c31614c29225aedaf5c6b7bb4bfdb3 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 3 Jan 2019 19:18:41 +0100 Subject: [PATCH 1/7] Add use_srcentry to copytree() --- Lib/shutil.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index 8d0de72b44a3a4..a7bc4612238b71 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -432,7 +432,7 @@ def _ignore_patterns(path, names): return _ignore_patterns def _copytree(entries, src, dst, symlinks, ignore, copy_function, - ignore_dangling_symlinks, dirs_exist_ok=False): + ignore_dangling_symlinks, dirs_exist_ok, use_srcentry): if ignore is not None: ignored_names = ignore(src, set(os.listdir(src))) else: @@ -440,7 +440,6 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function, os.makedirs(dst, exist_ok=dirs_exist_ok) errors = [] - use_srcentry = copy_function is copy2 or copy_function is copy for srcentry in entries: if srcentry.name in ignored_names: @@ -490,7 +489,8 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function, return dst def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, - ignore_dangling_symlinks=False, dirs_exist_ok=False): + ignore_dangling_symlinks=False, dirs_exist_ok=False, + use_srcentry=True): """Recursively copy a directory tree and return the destination directory. dirs_exist_ok dictates whether to raise an exception in case dst or any @@ -525,13 +525,18 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, 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. + + When this copy_function should recieve a srcentry (like copy2() and + copy()), set use_srcentry to true, otherwise the function will pass + only the srcname to the copy_function. """ with os.scandir(src) as entries: return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks, ignore=ignore, copy_function=copy_function, ignore_dangling_symlinks=ignore_dangling_symlinks, - dirs_exist_ok=dirs_exist_ok) + dirs_exist_ok=dirs_exist_ok, + use_srcentry=use_srcentry) # version vulnerable to race conditions def _rmtree_unsafe(path, onerror): From 70e95019b48b8322c92947d7c1dfe2a12d57742f Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 3 Jan 2019 19:23:03 +0100 Subject: [PATCH 2/7] Add use_srcentry documentation --- Doc/library/shutil.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 427a120159633d..3d32e2b32092c6 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -210,7 +210,7 @@ Directory and files operations .. function:: copytree(src, dst, symlinks=False, ignore=None, \ copy_function=copy2, ignore_dangling_symlinks=False, \ - dirs_exist_ok=False) + dirs_exist_ok=False, use_srcentry=True) Recursively copy an entire directory tree rooted at *src* to a directory named *dst* and return the destination directory. *dirs_exist_ok* dictates @@ -248,6 +248,9 @@ Directory and files operations each file. It will be called with the source path and the destination path as arguments. By default, :func:`shutil.copy2` is used, but any function that supports the same signature (like :func:`shutil.copy`) can be used. + If *use_srcentry* is true, the *copy_function* gets the srcentry, otherwise + it gets the srcname. The functions copy() and copy2() can handle the + srcentry. .. versionchanged:: 3.3 Copy metadata when *symlinks* is false. @@ -263,6 +266,8 @@ Directory and files operations Platform-specific fast-copy syscalls may be used internally in order to copy the file more efficiently. See :ref:`shutil-platform-dependent-efficient-copy-operations` section. + Added *use_srcentry* parameter to control if the srcentry or the srcname + is passed to the *copy_fucntion*. .. versionadded:: 3.8 The *dirs_exist_ok* parameter. From cb771b76d25c2335990617462c5fb2864ac24ee7 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 3 Jan 2019 20:01:22 +0100 Subject: [PATCH 3/7] Update shutil.py --- Lib/shutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index a7bc4612238b71..1956e37a16c98e 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -526,7 +526,7 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, destination path as arguments. By default, copy2() is used, but any function that supports the same signature (like copy()) can be used. - When this copy_function should recieve a srcentry (like copy2() and + When the copy_function should recieve a srcentry (like copy2() and copy()), set use_srcentry to true, otherwise the function will pass only the srcname to the copy_function. From bad1fe4c3ded81997cc5356083b097f1a7f31b63 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 3 Jan 2019 20:02:17 +0100 Subject: [PATCH 4/7] Function name fix --- Doc/library/shutil.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 3d32e2b32092c6..b46480e1453046 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -267,7 +267,7 @@ Directory and files operations copy the file more efficiently. See :ref:`shutil-platform-dependent-efficient-copy-operations` section. Added *use_srcentry* parameter to control if the srcentry or the srcname - is passed to the *copy_fucntion*. + is passed to the *copy_function*. .. versionadded:: 3.8 The *dirs_exist_ok* parameter. From 601e2d6b3438544a59c94649007d4de0756142c0 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Thu, 3 Jan 2019 19:08:44 +0000 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-01-03-19-08-44.bpo-35652.6c7eB5.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-01-03-19-08-44.bpo-35652.6c7eB5.rst diff --git a/Misc/NEWS.d/next/Library/2019-01-03-19-08-44.bpo-35652.6c7eB5.rst b/Misc/NEWS.d/next/Library/2019-01-03-19-08-44.bpo-35652.6c7eB5.rst new file mode 100644 index 00000000000000..5ceb9f0663c561 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-01-03-19-08-44.bpo-35652.6c7eB5.rst @@ -0,0 +1 @@ +shutil.copytree has now the `use_srcentry` argument. With this it's possible to control if the *copy_function* will get a srcentry or srcname. \ No newline at end of file From a93f2cae68d2c6cad15fa203ed7e95f29eb4fd16 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 3 Jan 2019 20:19:46 +0100 Subject: [PATCH 6/7] Fix trailing whitespace --- Lib/shutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index 1956e37a16c98e..f1de1535654dc6 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -525,7 +525,7 @@ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, 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. - + When the copy_function should recieve a srcentry (like copy2() and copy()), set use_srcentry to true, otherwise the function will pass only the srcname to the copy_function. From 6420edbf5cdece2462a4430243a8302af708b363 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 3 Jan 2019 20:21:04 +0100 Subject: [PATCH 7/7] Fix trailing whitespace --- Doc/library/shutil.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index b46480e1453046..e91c35a856bc71 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -248,8 +248,8 @@ Directory and files operations each file. It will be called with the source path and the destination path as arguments. By default, :func:`shutil.copy2` is used, but any function that supports the same signature (like :func:`shutil.copy`) can be used. - If *use_srcentry* is true, the *copy_function* gets the srcentry, otherwise - it gets the srcname. The functions copy() and copy2() can handle the + If *use_srcentry* is true, the *copy_function* gets the srcentry, otherwise + it gets the srcname. The functions copy() and copy2() can handle the srcentry. .. versionchanged:: 3.3