183
184
## import pdb; pdb.set_trace()
184
185
warning('Unable to load plugin %r from %r' % (name, d))
185
186
log_exception_quietly()
189
def load_from_zips(zips):
190
"""Load bzr plugins from zip archives with zipimport.
191
It's similar to load_from_dirs but plugins searched inside archives.
196
valid_suffixes = ('.py', '.pyc', '.pyo') # only python modules/packages
198
for zip_name in zips:
199
if '.zip' not in zip_name:
202
ziobj = zipimport.zipimporter(zip_name)
203
except zipimport.ZipImportError:
206
mutter('Looking for plugins in %r', zip_name)
208
# use zipfile to get list of files/dirs inside zip
209
z = zipfile.ZipFile(ziobj.archive)
210
namelist = z.namelist()
214
prefix = ziobj.prefix.replace('\\','/')
216
namelist = [name[ix:]
218
if name.startswith(prefix)]
220
mutter('Names in archive: %r', namelist)
222
for name in namelist:
223
if not name or name.endswith('/'):
226
head, tail = os.path.split(name)
228
# we don't need looking in subdirectories
231
base, suffix = os.path.splitext(tail)
232
if suffix not in valid_suffixes:
235
if base == '__init__':
246
if getattr(plugins, plugin_name, None):
247
mutter('Plugin name %s already loaded', plugin_name)
251
plugin = ziobj.load_module(plugin_name)
252
setattr(plugins, plugin_name, plugin)
253
mutter('Load plugin %s from zip %r', plugin_name, zip_name)
254
except zipimport.ZipImportError, e:
255
mutter('Unable to load plugin %r from %r: %s',
256
plugin_name, zip_name, str(e))
258
except KeyboardInterrupt:
261
## import pdb; pdb.set_trace()
262
warning('Unable to load plugin %r from %r'
264
log_exception_quietly()