bugfix [#25742] blender-thumbnailer.py doesn't work with python 3.1

This commit is contained in:
Campbell Barton 2011-01-20 21:02:42 +00:00
parent dc2431c491
commit 039bb7812f

@ -27,18 +27,19 @@ To run automatically with nautilus:
import struct
def blend_extract_thumb(path):
import os
# 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')
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')
@ -48,10 +49,10 @@ def blend_extract_thumb(path):
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 +67,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
@ -122,7 +122,7 @@ if __name__ == '__main__':
file_in = sys.argv[-2]
buf, width, height = blend_extract_thumb(file_in)
if buf:
file_out = sys.argv[-1]