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:48:31 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-12 11:48:31 +0400
commit1c5b416cbf989d81b7a74b87df352be0551e0d7d (patch)
tree68ff22a0244586ef76fa815a10dac2f5e41e8cc8
parent98e5e544b55d2d358fbf38df27e06a5dc3b36406 (diff)
image_load() utility function's 'recursive' option wasn't functional since 2.4x
-rw-r--r--release/scripts/modules/bpy_extras/image_utils.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/release/scripts/modules/bpy_extras/image_utils.py b/release/scripts/modules/bpy_extras/image_utils.py
index 5c63ce1218e..551689c5a75 100644
--- a/release/scripts/modules/bpy_extras/image_utils.py
+++ b/release/scripts/modules/bpy_extras/image_utils.py
@@ -66,8 +66,6 @@ def load_image(imagepath,
import os
import bpy
- # TODO: recursive
-
# -------------------------------------------------------------------------
# Utility Functions
@@ -111,6 +109,18 @@ def load_image(imagepath,
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 @@ def load_image(imagepath,
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)