[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59079] trunk/blender/release/scripts/ modules/bpy_extras/image_utils.py: image_load() utility function's ' recursive' option wasn't functional since 2.4x

Campbell Barton ideasman42 at gmail.com
Mon Aug 12 09:48:31 CEST 2013


Revision: 59079
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59079
Author:   campbellbarton
Date:     2013-08-12 07:48:31 +0000 (Mon, 12 Aug 2013)
Log Message:
-----------
image_load() utility function's 'recursive' option wasn't functional since 2.4x

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy_extras/image_utils.py

Modified: trunk/blender/release/scripts/modules/bpy_extras/image_utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_extras/image_utils.py	2013-08-12 07:47:44 UTC (rev 59078)
+++ trunk/blender/release/scripts/modules/bpy_extras/image_utils.py	2013-08-12 07:48:31 UTC (rev 59079)
@@ -66,8 +66,6 @@
     import os
     import bpy
 
-    # TODO: recursive
-
     # -------------------------------------------------------------------------
     # Utility Functions
 
@@ -111,6 +109,18 @@
 
         return image
 
+    def _recursive_search(paths, filename_check):
+        for path in paths:
+            for dirpath, dirnames, filenames in os.walk(path):
+
+                # skip '.svn'
+                if dirpath[0] in {".", b'.'}:
+                    continue
+
+                for filename in filenames:
+                    if filename_check(filename):
+                        yield os.path.join(dirpath, filename)
+
     # -------------------------------------------------------------------------
 
     if verbose:
@@ -138,6 +148,28 @@
             if os.path.exists(nfilepath):
                 return _image_load(nfilepath)
 
+    if recursive:
+        search_paths = []
+
+        for dirpath_test in (os.path.dirname(imagepath), dirname):
+            if os.path.exists(dirpath_test):
+                search_paths.append(dirpath_test)
+        search_paths[:] = bpy.path.reduce_dirs(search_paths)
+
+        imagepath_base = bpy.path.basename(imagepath)
+        if ncase_cmp:
+            imagepath_base = imagepath_base.lower()
+
+            def image_filter(fn):
+                return (imagepath_base == fn.lower())
+        else:
+            def image_filter(fn):
+                return (imagepath_base == fn)
+
+        nfilepath = next(_recursive_search(search_paths, image_filter), None)
+        if nfilepath is not None:
+            return _image_load(nfilepath)
+
     # None of the paths exist so return placeholder
     if place_holder:
         return _image_load_placeholder(imagepath)




More information about the Bf-blender-cvs mailing list