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:
Diffstat (limited to 'release/bin/blender-thumbnailer.py')
-rwxr-xr-xrelease/bin/blender-thumbnailer.py54
1 files changed, 39 insertions, 15 deletions
diff --git a/release/bin/blender-thumbnailer.py b/release/bin/blender-thumbnailer.py
index be870560110..8b93eebdeec 100755
--- a/release/bin/blender-thumbnailer.py
+++ b/release/bin/blender-thumbnailer.py
@@ -18,40 +18,65 @@
#
# ##### END GPL LICENSE BLOCK #####
+# <pep8 compliant>
+
"""
Thumbnailer runs with python 2.6 and 3.x.
To run automatically with nautilus:
gconftool --type boolean --set /desktop/gnome/thumbnailers/application@x-blender/enable true
- gconftool --type string --set /desktop/gnome/thumbnailers/application@x-blender/command "blender-thumbnailer.py %i %o"
+ gconftool --type string --set /desktop/gnome/thumbnailers/application@x-blender/command "blender-thumbnailer.py %u %o"
"""
import struct
+
+def open_wrapper_get():
+ """ wrap OS spesific read functionality here, fallback to 'open()'
+ """
+
+ def open_gio(path, mode):
+ g_file = gio.File(path).read()
+ g_file.orig_seek = g_file.seek
+
+ def new_seek(offset, whence=0):
+ return g_file.orig_seek(offset, [1, 0, 2][whence])
+
+ g_file.seek = new_seek
+ return g_file
+
+ try:
+ import gio
+ return open_gio
+ except ImportError:
+ return open
+
+
def blend_extract_thumb(path):
import os
+ open_wrapper = open_wrapper_get()
# def MAKE_ID(tag): ord(tag[0])<<24 | ord(tag[1])<<16 | ord(tag[2])<<8 | ord(tag[3])
- REND = 1145980242 # MAKE_ID(b'REND')
- TEST = 1414743380 # MAKE_ID(b'TEST')
+ REND = 1145980242 # MAKE_ID(b'REND')
+ TEST = 1414743380 # MAKE_ID(b'TEST')
- blendfile = open(path, 'rb')
+ blendfile = open_wrapper(path, 'rb')
head = blendfile.read(12)
- if head[0:2] == b'\x1f\x8b': # gzip magic
+ if head[0:2] == b'\x1f\x8b': # gzip magic
import gzip
blendfile.close()
- blendfile = gzip.open(path, 'rb')
+ blendfile = gzip.GzipFile('', 'rb', 0, open_wrapper(path, 'rb'))
head = blendfile.read(12)
if not head.startswith(b'BLENDER'):
blendfile.close()
return None, 0, 0
- is_64_bit = (head[7] == b'-')
+ is_64_bit = (head[7] == b'-'[0])
# true for PPC, false for X86
- is_big_endian = (head[8] == b'V')
+ is_big_endian = (head[8] == b'V'[0])
# blender pre 2.5 had no thumbs
if head[9:11] <= b'24':
@@ -66,23 +91,22 @@ def blend_extract_thumb(path):
if len(bhead) < sizeof_bhead:
return None, 0, 0
- code, length = struct.unpack(int_endian_pair, bhead[0:8]) # 8 == sizeof(int) * 2
+ code, length = struct.unpack(int_endian_pair, bhead[0:8]) # 8 == sizeof(int) * 2
if code == REND:
blendfile.seek(length, os.SEEK_CUR)
else:
break
-
-
+
if code != TEST:
return None, 0, 0
try:
- x, y = struct.unpack(int_endian_pair, blendfile.read(8)) # 8 == sizeof(int) * 2
+ x, y = struct.unpack(int_endian_pair, blendfile.read(8)) # 8 == sizeof(int) * 2
except struct.error:
return None, 0, 0
- length -= 8 # sizeof(int) * 2
+ length -= 8 # sizeof(int) * 2
if length != x * y * 4:
return None, 0, 0
@@ -116,13 +140,13 @@ def write_png(buf, width, height):
if __name__ == '__main__':
import sys
- if len(sys.argv) < 2:
+ if len(sys.argv) < 3:
print("Expected 2 arguments <input.blend> <output.png>")
else:
file_in = sys.argv[-2]
buf, width, height = blend_extract_thumb(file_in)
-
+
if buf:
file_out = sys.argv[-1]