def unload_plugin(plugin_name): """for testing purposes""" _unregister_module_extensions(plugin_name) if hasattr(picard.plugins, plugin_name): delattr(picard.plugins, plugin_name) key = _PLUGIN_MODULE_PREFIX + plugin_name if key in sys.modules: del sys.modules[key]
def _remove_plugin(self, plugin_name, with_update=False): self._remove_plugin_files(plugin_name, with_update) _unregister_module_extensions(plugin_name) self.plugins = [ p for p in self.plugins if p.module_name != plugin_name ]
def _load_plugin_from_directory(self, name, plugindir): module_file = None (zip_importer, module_name, manifest_data) = zip_import(os.path.join(plugindir, name + '.zip')) if zip_importer: name = module_name if not zip_importer.find_module(name): error = _("Failed loading zipped plugin %r") % name self.plugin_error(name, error) return None module_pathname = zip_importer.get_filename(name) else: try: info = imp.find_module(name, [plugindir]) module_file = info[0] module_pathname = info[1] except ImportError: error = _("Failed loading plugin %r") % name self.plugin_error(name, error) return None plugin = None try: existing_plugin, existing_plugin_index = self._get_plugin_index_by_name( name) if existing_plugin: log.warning( "Module %r conflict: unregistering previously" " loaded %r version %s from %r", existing_plugin.module_name, existing_plugin.name, existing_plugin.version, existing_plugin.file) _unregister_module_extensions(name) full_module_name = _PLUGIN_MODULE_PREFIX + name if zip_importer: plugin_module = zip_importer.load_module(full_module_name) else: plugin_module = imp.load_module(full_module_name, *info) plugin = PluginWrapper(plugin_module, plugindir, file=module_pathname, manifest_data=manifest_data) compatible_versions = _compatible_api_versions(plugin.api_versions) if compatible_versions: log.debug( "Loading plugin %r version %s, compatible with API: %s", plugin.name, plugin.version, ", ".join([ version_to_string(v, short=True) for v in sorted(compatible_versions) ])) plugin.compatible = True setattr(picard.plugins, name, plugin_module) if existing_plugin: self.plugins[existing_plugin_index] = plugin else: self.plugins.append(plugin) else: error = _("Plugin '%s' from '%s' is not compatible with this " "version of Picard.") % (plugin.name, plugin.file) self.plugin_error(plugin.name, error, log_func=log.warning) except VersionError as e: error = _("Plugin %r has an invalid API version string : %s") % ( name, e) self.plugin_error(name, error) except BaseException: error = _("Plugin %r : %s") % (name, traceback.format_exc()) self.plugin_error(name, error) if module_file is not None: module_file.close() return plugin
def _remove_plugin(self, plugin_name, with_update=False): self._remove_plugin_files(plugin_name, with_update) _unregister_module_extensions(plugin_name) self.plugins = [p for p in self.plugins if p.module_name != plugin_name]
def _load_plugin_from_directory(self, name, plugindir): module_file = None (zip_importer, module_name, manifest_data) = zip_import(os.path.join(plugindir, name + '.zip')) if zip_importer: name = module_name if not zip_importer.find_module(name): error = _("Failed loading zipped plugin %r") % name self.plugin_error(name, error) return None module_pathname = zip_importer.get_filename(name) else: try: info = imp.find_module(name, [plugindir]) module_file = info[0] module_pathname = info[1] except ImportError: error = _("Failed loading plugin %r") % name self.plugin_error(name, error) return None plugin = None try: existing_plugin, existing_plugin_index = self._get_plugin_index_by_name(name) if existing_plugin: log.warning("Module %r conflict: unregistering previously" " loaded %r version %s from %r", existing_plugin.module_name, existing_plugin.name, existing_plugin.version, existing_plugin.file) _unregister_module_extensions(name) full_module_name = _PLUGIN_MODULE_PREFIX + name if zip_importer: plugin_module = zip_importer.load_module(full_module_name) else: plugin_module = imp.load_module(full_module_name, *info) plugin = PluginWrapper(plugin_module, plugindir, file=module_pathname, manifest_data=manifest_data) compatible_versions = _compatible_api_versions(plugin.api_versions) if compatible_versions: log.debug("Loading plugin %r version %s, compatible with API: %s", plugin.name, plugin.version, ", ".join([version_to_string(v, short=True) for v in sorted(compatible_versions)])) plugin.compatible = True setattr(picard.plugins, name, plugin_module) if existing_plugin: self.plugins[existing_plugin_index] = plugin else: self.plugins.append(plugin) else: error = _("Plugin '%s' from '%s' is not compatible with this " "version of Picard.") % (plugin.name, plugin.file) self.plugin_error(plugin.name, error, log_func=log.warning) except VersionError as e: error = _("Plugin %r has an invalid API version string : %s") % (name, e) self.plugin_error(name, error) except BaseException: error = _("Plugin %r : %s") % (name, traceback.format_exc()) self.plugin_error(name, error) if module_file is not None: module_file.close() return plugin