[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59077] trunk/blender/release/scripts/ modules/bpy/path.py: bpy.path.reduce_dirs() - new utility function to de-duplicate and remove nested paths before doing a recursive search .
Campbell Barton
ideasman42 at gmail.com
Mon Aug 12 09:44:38 CEST 2013
Revision: 59077
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59077
Author: campbellbarton
Date: 2013-08-12 07:44:38 +0000 (Mon, 12 Aug 2013)
Log Message:
-----------
bpy.path.reduce_dirs() - new utility function to de-duplicate and remove nested paths before doing a recursive search.
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy/path.py
Modified: trunk/blender/release/scripts/modules/bpy/path.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/path.py 2013-08-12 06:53:17 UTC (rev 59076)
+++ trunk/blender/release/scripts/modules/bpy/path.py 2013-08-12 07:44:38 UTC (rev 59077)
@@ -35,6 +35,7 @@
"extensions_audio",
"is_subdir",
"module_names",
+ "reduce_dirs",
"relpath",
"resolve_ncase",
)
@@ -304,3 +305,27 @@
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
More information about the Bf-blender-cvs
mailing list