mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #3861 (calibre locks zip file when plugin not found)
This commit is contained in:
parent
712e082dc4
commit
90414033ca
@ -3,6 +3,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, shutil, traceback, functools, sys, re
|
import os, shutil, traceback, functools, sys, re
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
from calibre.customize import Plugin, FileTypePlugin, MetadataReaderPlugin, \
|
from calibre.customize import Plugin, FileTypePlugin, MetadataReaderPlugin, \
|
||||||
MetadataWriterPlugin
|
MetadataWriterPlugin
|
||||||
@ -51,25 +52,25 @@ def load_plugin(path_to_zip_file):
|
|||||||
#print 'Loading plugin from', path_to_zip_file
|
#print 'Loading plugin from', path_to_zip_file
|
||||||
if not os.access(path_to_zip_file, os.R_OK):
|
if not os.access(path_to_zip_file, os.R_OK):
|
||||||
raise PluginNotFound
|
raise PluginNotFound
|
||||||
zf = ZipFile(path_to_zip_file)
|
with closing(ZipFile(path_to_zip_file)) as zf:
|
||||||
for name in zf.namelist():
|
for name in zf.namelist():
|
||||||
if name.lower().endswith('plugin.py'):
|
if name.lower().endswith('plugin.py'):
|
||||||
locals = {}
|
locals = {}
|
||||||
raw = zf.read(name)
|
raw = zf.read(name)
|
||||||
match = re.search(r'coding[:=]\s*([-\w.]+)', raw[:300])
|
match = re.search(r'coding[:=]\s*([-\w.]+)', raw[:300])
|
||||||
encoding = 'utf-8'
|
encoding = 'utf-8'
|
||||||
if match is not None:
|
if match is not None:
|
||||||
encoding = match.group(1)
|
encoding = match.group(1)
|
||||||
raw = raw.decode(encoding)
|
raw = raw.decode(encoding)
|
||||||
raw = re.sub('\r\n', '\n', raw)
|
raw = re.sub('\r\n', '\n', raw)
|
||||||
exec raw in locals
|
exec raw in locals
|
||||||
for x in locals.values():
|
for x in locals.values():
|
||||||
if isinstance(x, type) and issubclass(x, Plugin):
|
if isinstance(x, type) and issubclass(x, Plugin):
|
||||||
if x.minimum_calibre_version > version or \
|
if x.minimum_calibre_version > version or \
|
||||||
platform not in x.supported_platforms:
|
platform not in x.supported_platforms:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
raise InvalidPlugin(_('No valid plugin found in ')+path_to_zip_file)
|
raise InvalidPlugin(_('No valid plugin found in ')+path_to_zip_file)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user