[Bf-blender-cvs] [f34d5d99dce] master: Cleanup: remove local copy of shutil.copytree from Python 3.8

Campbell Barton noreply at git.blender.org
Tue Feb 16 06:01:09 CET 2021


Commit: f34d5d99dce8dde6559e7d5ebd8060cc942a7491
Author: Campbell Barton
Date:   Tue Feb 16 14:02:56 2021 +1100
Branches: master
https://developer.blender.org/rBf34d5d99dce8dde6559e7d5ebd8060cc942a7491

Cleanup: remove local copy of shutil.copytree from Python 3.8

===================================================================

M	release/scripts/startup/bl_operators/userpref.py

===================================================================

diff --git a/release/scripts/startup/bl_operators/userpref.py b/release/scripts/startup/bl_operators/userpref.py
index fa6338fa614..7f2fa1292ee 100644
--- a/release/scripts/startup/bl_operators/userpref.py
+++ b/release/scripts/startup/bl_operators/userpref.py
@@ -50,49 +50,6 @@ def module_filesystem_remove(path_base, module_name):
                 os.remove(f_full)
 
 
-# This duplicates shutil.copytree from Python 3.8, with the new dirs_exist_ok
-# argument that we need. Once we upgrade to 3.8 we can remove this.
-def _preferences_copytree(entries, src, dst):
-    import os
-    import shutil
-    from shutil import Error
-
-    os.makedirs(dst, exist_ok=True)
-    errors = []
-
-    for srcentry in entries:
-        srcname = os.path.join(src, srcentry.name)
-        dstname = os.path.join(dst, srcentry.name)
-        srcobj = srcentry
-        try:
-            if srcentry.is_symlink():
-                linkto = os.readlink(srcname)
-                os.symlink(linkto, dstname)
-                shutil.copystat(srcobj, dstname, follow_symlinks=False)
-            elif srcentry.is_dir():
-                preferences_copytree(srcobj, dstname)
-            else:
-                shutil.copy2(srcentry, dstname)
-        except Error as err:
-            errors.extend(err.args[0])
-        except OSError as why:
-            errors.append((srcname, dstname, str(why)))
-    try:
-        shutil.copystat(src, dst)
-    except OSError as why:
-        if getattr(why, 'winerror', None) is None:
-            errors.append((src, dst, str(why)))
-    if errors:
-        raise Error(errors)
-    return dst
-
-
-def preferences_copytree(src, dst):
-    import os
-    with os.scandir(src) as entries:
-        return _preferences_copytree(entries=entries, src=src, dst=dst)
-
-
 class PREFERENCES_OT_keyconfig_activate(Operator):
     bl_idname = "preferences.keyconfig_activate"
     bl_label = "Activate Keyconfig"
@@ -168,10 +125,8 @@ class PREFERENCES_OT_copy_prev(Operator):
         return os.path.isfile(old_userpref) and not os.path.isfile(new_userpref)
 
     def execute(self, _context):
-        # Use this instead once we upgrade to Python 3.8 with dirs_exist_ok.
-        # import shutil
-        # shutil.copytree(self._old_path(), self._new_path(), dirs_exist_ok=True)
-        preferences_copytree(self._old_path(), self._new_path())
+        import shutil
+        shutil.copytree(self._old_path(), self._new_path(), dirs_exist_ok=True)
 
         # reload preferences and recent-files.txt
         bpy.ops.wm.read_userpref()



More information about the Bf-blender-cvs mailing list