Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-12 11:44:38 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-12 11:44:38 +0400
commit4fbe4261514e5dd896cf6fa213c838a184d0bc9a (patch)
tree701dd8da429a86ff4c49913b9eecf192862bd53c /release/scripts/modules/bpy/path.py
parent795fa1f199a9e4489763502fd69e4e2f23ae2a9b (diff)
bpy.path.reduce_dirs() - new utility function to de-duplicate and remove nested paths before doing a recursive search.
Diffstat (limited to 'release/scripts/modules/bpy/path.py')
-rw-r--r--release/scripts/modules/bpy/path.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/release/scripts/modules/bpy/path.py b/release/scripts/modules/bpy/path.py
index cfc0f474215..33039fa8494 100644
--- a/release/scripts/modules/bpy/path.py
+++ b/release/scripts/modules/bpy/path.py
@@ -35,6 +35,7 @@ __all__ = (
"extensions_audio",
"is_subdir",
"module_names",
+ "reduce_dirs",
"relpath",
"resolve_ncase",
)
@@ -304,3 +305,27 @@ def basename(path):
Use for Windows compatibility.
"""
return _os.path.basename(path[2:] if path[:2] in {"//", b"//"} else path)
+
+
+def reduce_dirs(dirs):
+ """
+ Given a sequence of directories, remove duplicates and
+ any directories nested in one of the other paths.
+ (Useful for recursive path searching).
+
+ :arg dirs: Sequence of directory paths.
+ :type dirs: sequence
+ :return: A unique list of paths.
+ :rtype: list
+ """
+ dirs = list({_os.path.normpath(_os.path.abspath(d)) for d in dirs})
+ dirs.sort(key=lambda d: len(d))
+ for i in range(len(dirs) -1, -1, -1):
+ for j in range(i):
+ print(i, j)
+ if len(dirs[i]) == len(dirs[j]):
+ break
+ elif is_subdir(dirs[i], dirs[j]):
+ del dirs[i]
+ break
+ return dirs