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
# '/' is used to separate pathname components inside zip archives
229
head, tail = '', name
231
head, tail = name.rsplit('/',1)
233
# we don't need looking in subdirectories
236
base, suffix = osutils.splitext(tail)
237
if suffix not in valid_suffixes:
240
if base == '__init__':
251
if getattr(plugins, plugin_name, None):
252
mutter('Plugin name %s already loaded', plugin_name)
256
plugin = ziobj.load_module(plugin_name)
257
setattr(plugins, plugin_name, plugin)
258
mutter('Load plugin %s from zip %r', plugin_name, zip_name)
259
except zipimport.ZipImportError, e:
260
mutter('Unable to load plugin %r from %r: %s',
261
plugin_name, zip_name, str(e))
263
except KeyboardInterrupt:
266
## import pdb; pdb.set_trace()
267
warning('Unable to load plugin %r from %r'
269
log_exception_quietly()