From 30552f9f46038a3ce7990b1b7a267c14ee2f3fac Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 9 Feb 2011 02:09:30 +0000 Subject: patch [#25972] blender-thumbnailer.py: GVFS support from Shinsuke Irie (irie) with some minor edits. Shinsuke's description from the tracker: --- I have implemented GVFS framework support of blender-thumbnailer.py which allows some file managers like Nautilus and Thunar to show thumbnails in trash or network directories. If Python's gio module is available, the thumbnailer uses it to access to filesystems mounted via GVFS. This change shouldn't affect desktop environments other than GNOME and XFCE. A function gvfs_open() in this patch is defined to solve a stupid incompatibility between Python file object and GIO Seekable object. On Ubuntu 10.10, I confirmed thumbnails can be generated for file://, trash://, sftp://, and smb://. --- release/bin/blender-thumbnailer.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/release/bin/blender-thumbnailer.py b/release/bin/blender-thumbnailer.py index abd85cd3bec..8b93eebdeec 100755 --- a/release/bin/blender-thumbnailer.py +++ b/release/bin/blender-thumbnailer.py @@ -24,27 +24,49 @@ 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') - blendfile = open(path, 'rb') + blendfile = open_wrapper(path, 'rb') head = blendfile.read(12) 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'): -- cgit v1.2.3