From 0a2e485926b6bbeb866da107260030c7cbffa291 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Jul 2010 11:46:25 +0000 Subject: move the thumbnailer to bin/ --- bin/blender-thumbnailer.py | 131 +++++++++++++++++++++++++++++ release/freedesktop/blender-thumbnailer.py | 131 ----------------------------- source/creator/CMakeLists.txt | 2 +- 3 files changed, 132 insertions(+), 132 deletions(-) create mode 100755 bin/blender-thumbnailer.py delete mode 100755 release/freedesktop/blender-thumbnailer.py diff --git a/bin/blender-thumbnailer.py b/bin/blender-thumbnailer.py new file mode 100755 index 00000000000..27d6259d172 --- /dev/null +++ b/bin/blender-thumbnailer.py @@ -0,0 +1,131 @@ +#!/usr/bin/python + +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +""" +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" +""" + +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') + + blendfile = open(path, 'rb') + + head = blendfile.read(12) + + if head[0:2] == b'\x1f\x8b': # gzip magic + import gzip + blendfile.close() + blendfile = gzip.open(path, 'rb') + head = blendfile.read(12) + + if not head.startswith(b'BLENDER'): + blendfile.close() + return None, 0, 0 + + is_64_bit = (head[7] == b'-') + + # true for PPC, false for X86 + is_big_endian = (head[8] == b'V') + + # blender pre 2.5 had no thumbs + if head[9:11] <= b'24': + return None, 0, 0 + + sizeof_bhead = 24 if is_64_bit else 20 + int_endian_pair = '>ii' if is_big_endian else ' ") + else: + file_in = sys.argv[-2] + + buf, width, height = blend_extract_thumb(file_in) + + if buf: + file_out = sys.argv[-1] + + f = open(file_out, "wb") + f.write(write_png(buf, width, height)) + f.close() diff --git a/release/freedesktop/blender-thumbnailer.py b/release/freedesktop/blender-thumbnailer.py deleted file mode 100755 index 27d6259d172..00000000000 --- a/release/freedesktop/blender-thumbnailer.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/python - -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENSE BLOCK ##### - -""" -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" -""" - -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') - - blendfile = open(path, 'rb') - - head = blendfile.read(12) - - if head[0:2] == b'\x1f\x8b': # gzip magic - import gzip - blendfile.close() - blendfile = gzip.open(path, 'rb') - head = blendfile.read(12) - - if not head.startswith(b'BLENDER'): - blendfile.close() - return None, 0, 0 - - is_64_bit = (head[7] == b'-') - - # true for PPC, false for X86 - is_big_endian = (head[8] == b'V') - - # blender pre 2.5 had no thumbs - if head[9:11] <= b'24': - return None, 0, 0 - - sizeof_bhead = 24 if is_64_bit else 20 - int_endian_pair = '>ii' if is_big_endian else ' ") - else: - file_in = sys.argv[-2] - - buf, width, height = blend_extract_thumb(file_in) - - if buf: - file_out = sys.argv[-1] - - f = open(file_out, "wb") - f.write(write_png(buf, width, height)) - f.close() diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 3f62f4267a9..12bb371de63 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -200,7 +200,7 @@ IF(WITH_INSTALL) DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps ) INSTALL( - PROGRAMS ${CMAKE_SOURCE_DIR}/release/freedesktop/blender-thumbnailer.py + PROGRAMS ${CMAKE_SOURCE_DIR}/bin/blender-thumbnailer.py DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) INSTALL( -- cgit v1.2.3