blender-thumbnailer.py: Fix GVFS support not working with Python 3
also update doc string.
This commit is contained in:
parent
e3f4037075
commit
bf2f6d6161
|
@ -21,10 +21,16 @@
|
||||||
# <pep8 compliant>
|
# <pep8 compliant>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Thumbnailer runs with python 2.6 and 3.x.
|
Thumbnailer runs with python 2.7 and 3.x.
|
||||||
To run automatically with nautilus:
|
To run automatically with a file manager such as Nautilus, save this file
|
||||||
gconftool --type boolean --set /desktop/gnome/thumbnailers/application@x-blender/enable true
|
in a directory that is listed in PATH environment variable, and create
|
||||||
gconftool --type string --set /desktop/gnome/thumbnailers/application@x-blender/command "blender-thumbnailer.py %u %o"
|
blender.thumbnailer file in ${HOME}/.local/share/thumbnailers/ directory
|
||||||
|
with the following contents:
|
||||||
|
|
||||||
|
[Thumbnailer Entry]
|
||||||
|
TryExec=blender-thumbnailer.py
|
||||||
|
Exec=blender-thumbnailer.py %u %o
|
||||||
|
MimeType=application/x-blender;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
|
@ -34,21 +40,47 @@ def open_wrapper_get():
|
||||||
""" wrap OS spesific read functionality here, fallback to 'open()'
|
""" wrap OS spesific read functionality here, fallback to 'open()'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def open_gio(path, mode):
|
class GFileWrapper:
|
||||||
g_file = gio.File(path).read()
|
__slots__ = ("mode", "g_file")
|
||||||
g_file.orig_seek = g_file.seek
|
def __init__(self, url, mode='r'):
|
||||||
|
self.mode = mode # used in gzip module
|
||||||
|
self.g_file = Gio.File.parse_name(url).read(None)
|
||||||
|
|
||||||
def new_seek(offset, whence=0):
|
def read(self, size):
|
||||||
return g_file.orig_seek(offset, [1, 0, 2][whence])
|
return self.g_file.read_bytes(size, None).get_data()
|
||||||
|
|
||||||
g_file.seek = new_seek
|
def seek(self, offset, whence=0):
|
||||||
return g_file
|
self.g_file.seek(offset, [1, 0, 2][whence], None)
|
||||||
|
return self.g_file.tell()
|
||||||
|
|
||||||
|
def tell(self):
|
||||||
|
return self.g_file.tell()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.g_file.close(None)
|
||||||
|
|
||||||
|
def open_local_url(url, mode='r'):
|
||||||
|
o = urlparse(url)
|
||||||
|
if o.scheme == '':
|
||||||
|
path = o.path
|
||||||
|
elif o.scheme == 'file':
|
||||||
|
path = unquote(o.path)
|
||||||
|
else:
|
||||||
|
raise(IOError('URL scheme "%s" needs gi.repository.Gio module' % o.scheme))
|
||||||
|
return open(path, mode)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import gio
|
from gi.repository import Gio
|
||||||
return open_gio
|
return GFileWrapper
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return open
|
try:
|
||||||
|
# Python 3
|
||||||
|
from urllib.parse import urlparse, unquote
|
||||||
|
except ImportError:
|
||||||
|
# Python 2
|
||||||
|
from urlparse import urlparse
|
||||||
|
from urllib import unquote
|
||||||
|
return open_local_url
|
||||||
|
|
||||||
|
|
||||||
def blend_extract_thumb(path):
|
def blend_extract_thumb(path):
|
||||||
|
|
Loading…
Reference in New Issue