~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/modules/bpy_extras/image_utils.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    import os
67
67
    import bpy
68
68
 
69
 
    # TODO: recursive
70
 
 
71
69
    # -------------------------------------------------------------------------
72
70
    # Utility Functions
73
71
 
107
105
            if relpath is not None:
108
106
                # make relative
109
107
                from bpy.path import relpath as relpath_fn
110
 
                image.filepath_raw = relpath_fn(path, start=relpath)
 
108
                # can't always find the relative path
 
109
                # (between drive letters on windows)
 
110
                try:
 
111
                    filepath_rel = relpath_fn(path, start=relpath)
 
112
                except ValueError:
 
113
                    filepath_rel = None
 
114
 
 
115
                if filepath_rel is not None:
 
116
                    image.filepath_raw = filepath_rel
111
117
 
112
118
        return image
113
119
 
 
120
    def _recursive_search(paths, filename_check):
 
121
        for path in paths:
 
122
            for dirpath, dirnames, filenames in os.walk(path):
 
123
 
 
124
                # skip '.svn'
 
125
                if dirpath[0] in {".", b'.'}:
 
126
                    continue
 
127
 
 
128
                for filename in filenames:
 
129
                    if filename_check(filename):
 
130
                        yield os.path.join(dirpath, filename)
 
131
 
114
132
    # -------------------------------------------------------------------------
115
133
 
116
134
    if verbose:
138
156
            if os.path.exists(nfilepath):
139
157
                return _image_load(nfilepath)
140
158
 
 
159
    if recursive:
 
160
        search_paths = []
 
161
 
 
162
        for dirpath_test in (os.path.dirname(imagepath), dirname):
 
163
            if os.path.exists(dirpath_test):
 
164
                search_paths.append(dirpath_test)
 
165
        search_paths[:] = bpy.path.reduce_dirs(search_paths)
 
166
 
 
167
        imagepath_base = bpy.path.basename(imagepath)
 
168
        if ncase_cmp:
 
169
            imagepath_base = imagepath_base.lower()
 
170
 
 
171
            def image_filter(fn):
 
172
                return (imagepath_base == fn.lower())
 
173
        else:
 
174
            def image_filter(fn):
 
175
                return (imagepath_base == fn)
 
176
 
 
177
        nfilepath = next(_recursive_search(search_paths, image_filter), None)
 
178
        if nfilepath is not None:
 
179
            return _image_load(nfilepath)
 
180
 
141
181
    # None of the paths exist so return placeholder
142
182
    if place_holder:
143
183
        return _image_load_placeholder(imagepath)