def load_plugin(self, pkg, force=False): """ Load a plugin @param pkg the plugin to load @param force if True no checks for deps will performed @return None or raise a PluginException """ if pkg in self.pkg_lst: raise PluginException(pkg, _("Plugin already loaded.")) if not force: # 1) Check for conflicts ret = self.check_conflicts(pkg) if ret: reasons = [] for phase, (p_name, p_op, p_ver), (c_name, c_op, c_ver) in ret: reasons.append( \ "-%d- Plugin '%s' provides %s which conflicts with " \ "%s conflict entry for plugin '%s'" % \ ( \ phase, pkg, \ Version.stringify_version(p_name, p_op, p_ver), \ Version.stringify_version(p_name, c_op, c_ver), \ c_name \ ) \ ) raise PluginException(pkg, "\n".join(reasons)) # 2) Check for needs ret = self.check_needs(pkg) if ret: reasons = [] for (n_name, n_op, n_ver) in ret: reasons.append( \ "-3- Plugin '%s' needs %s, which actually is not " \ "provided by any plugin." % \ ( \ pkg, \ Version.stringify_version(n_name, n_op, n_ver) \ ) \ ) raise PluginException(pkg, "\n".join(reasons)) self.__load_hook(pkg) # Export to cache self.add_plugin_to_cache(pkg) self.dump()
def unload_plugin(self, pkg, force=False): """ Unload a plugin @param pkg the plugin to unload @param force if False check the depends @return None or raise a PluginException """ if pkg not in self.pkg_lst: raise Exception("Plugin not loaded.") if not force: # No conflict check here. # 1) We should check need's list against pkg ret = self.check_list_needs(pkg) if ret: reasons = [] for i in ret: reasons.append( "Plugin %s requires %s" % \ (i[0], Version.stringify_version(pkg, i[1], i[2])) ) raise PluginException(pkg, "\n".join(reasons)) self.__unload_hook(pkg) self.remove_plugin_from_cache(pkg) self.dump()