def registerPlugin(self, plugin): """Registers a plugin.""" plugin_types = { 'presence': IPresencePlugin, 'chat': IChatPlugin, 'population': IPopulationPlugin, 'base_plugin': BaseInterface, } # Everything is, at least, a base plugin. valid_types = ['baseplugin'] # Loop through the types of plugins and check for implentation of each. claimed_compliances = list(implementedBy(type(plugin))) # Can we use this as a map instead? for t, interface in plugin_types.iteritems(): if interface in claimed_compliances: try: verifyObject(interface, plugin) # If the above succeeded, then `plugin` implementes `interface`. self.plugins[t].append(plugin) self.plugins[t].sort() valid_types.append(t) except DoesNotImplement: log.error('Plugin %s claims to be a %s, but is not!', plugin.name, t) plugin.setup(self) log.info('registered plugin %s as %s', plugin.name, valid_types)
def registerPlugin(self, plugin): """Registers a plugin.""" plugin_types = { 'presence': IPresencePlugin, 'chat': IChatPlugin, 'population': IPopulationPlugin, 'base_plugin': IPlugin, } # Everything is, at least, a base plugin. valid_types = ['baseplugin'] # Loop through the types of plugins and check for implentation of each. for t, interface in plugin_types.iteritems(): try: verified_plugin = verify_plugin(interface, plugin) # If the above succeeded, then `plugin` implementes `interface`. self.plugins[t].append(verified_plugin) self.plugins[t].sort() valid_types.append(t) except DoesNotImplement: # This means this plugin does not declare to be a `t`. pass except PluginException: log.error('Plugin %s claims to be a %s, but is not!', plugin.name, t) plugin.setup(self) log.info('registered plugin %s as %s', plugin.name, valid_types)
def _hamper_send(self, func, comm, message, encode, tag, vars, kwvars): if type(message) == str: log.warning('Warning, passing message as ascii instead of unicode ' 'will cause problems. The message is: {0}' .format(message)) format_kwargs = {} format_kwargs.update(kwvars) format_kwargs.update(comm) try: message = message.format(*vars, **format_kwargs) except (ValueError, KeyError, IndexError) as e: log.error('Could not format message: {e}'.format(e=e)) if encode: message = message.encode('utf8') if comm['pm']: func(comm['user'], message) else: func(comm['channel'], message) (self.factory.sent_messages .setdefault(comm['channel'], deque(maxlen=100)) .append({ 'comm': comm, 'message': message, 'tag': tag, }))
def registerPlugin(self, plugin): """Registers a plugin.""" plugin_types = { 'presence': IPresencePlugin, 'chat': IChatPlugin, 'population': IPopulationPlugin, 'base_plugin': IPlugin, } # Everything is, at least, a base plugin. valid_types = ['baseplugin'] # Loop through the types of plugins and check for implentation of each. for t, interface in plugin_types.iteritems(): try: verified_plugin = verify_plugin(interface, plugin) # If the above succeeded, then `plugin` implementes `interface`. self.plugins[t].append(verified_plugin) self.plugins[t].sort() valid_types.append(t) except DoesNotImplement: # This means this plugin does not declare to be a `t`. pass except PluginException: log.error('Plugin "%s" claims to be a %s, but is not!', plugin.name, t) plugin.setup(self) log.info('registered plugin %s as %s', plugin.name, valid_types)
def dependencies_satisfied(self, plugin): """ Checks whether a plugin's dependencies are satisfied. Logs an error if there is an unsatisfied dependencies Returns: Bool """ for depends in plugin.dependencies: if depends not in self.config['plugins']: log.error("{0} depends on {1}, but {1} wasn't in the " "config file. To use {0}, install {1} and add " "it to the config.".format(plugin.name, depends)) return False return True