Fix #3861 (calibre locks zip file when plugin not found)

This commit is contained in:
Kovid Goyal 2009-10-25 09:08:58 -06:00
parent 712e082dc4
commit 90414033ca

View File

@ -3,6 +3,7 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os, shutil, traceback, functools, sys, re
from contextlib import closing
from calibre.customize import Plugin, FileTypePlugin, MetadataReaderPlugin, \
MetadataWriterPlugin
@ -51,25 +52,25 @@ def load_plugin(path_to_zip_file):
#print 'Loading plugin from', path_to_zip_file
if not os.access(path_to_zip_file, os.R_OK):
raise PluginNotFound
zf = ZipFile(path_to_zip_file)
for name in zf.namelist():
if name.lower().endswith('plugin.py'):
locals = {}
raw = zf.read(name)
match = re.search(r'coding[:=]\s*([-\w.]+)', raw[:300])
encoding = 'utf-8'
if match is not None:
encoding = match.group(1)
raw = raw.decode(encoding)
raw = re.sub('\r\n', '\n', raw)
exec raw in locals
for x in locals.values():
if isinstance(x, type) and issubclass(x, Plugin):
if x.minimum_calibre_version > version or \
platform not in x.supported_platforms:
continue
with closing(ZipFile(path_to_zip_file)) as zf:
for name in zf.namelist():
if name.lower().endswith('plugin.py'):
locals = {}
raw = zf.read(name)
match = re.search(r'coding[:=]\s*([-\w.]+)', raw[:300])
encoding = 'utf-8'
if match is not None:
encoding = match.group(1)
raw = raw.decode(encoding)
raw = re.sub('\r\n', '\n', raw)
exec raw in locals
for x in locals.values():
if isinstance(x, type) and issubclass(x, Plugin):
if x.minimum_calibre_version > version or \
platform not in x.supported_platforms:
continue
return x
return x
raise InvalidPlugin(_('No valid plugin found in ')+path_to_zip_file)