def run_plugins (self): ''' Run Plugins This is the main function responsible for executing the plugins that have been identified for this message. -- @return None ''' if not self.plugins: logger.warning('No plugins matched for this message.') return # Check with the ACL system what the status is of # the user that has sent the message can_send = self.check_acl() # Load the plugins from the configuration that # should not have ACL rules applied to them config.read( os.path.join(os.path.dirname(__file__), '../settings.ini')) acl_free_plugins = [x.strip() \ for x in config.get('advanced', 'no_acl_plugins', '').split(',')] for plugin in self.plugins: # Check that we are allowed to run this plugin. It # should either be bypassed from the ACL system # using settings.ini, or the user is allowed # to run plugins if not plugin['name'] in acl_free_plugins and not can_send: continue # Getting here, we should run this plugin. # Do it! try: logger.info('Running plugin: {plugin} for message {message_id}'.format( plugin = plugin['name'], message_id = self.response['message_id'])) logger.debug('Loading plugin: {plugin}'.format( plugin = plugin['name'])) # Find and Load the plugin from the file plugin_on_disk = PluginLoader.find_plugin(plugin['name']) loaded_plugin = PluginLoader.load_plugin(plugin_on_disk) # If we got None from the load, error out if not loaded_plugin: logger.critical('Loading plugin {name} returned nothing.'.format( name = plugin['name'])) continue # Run the plugins run() method plugin_output = loaded_plugin.run(self.response) except Exception, e: logger.error('Plugin {plugin} failed with: {error}: {trace}'.format( plugin = plugin['name'], error = str(e), trace = traceback.print_exc())) continue # If we should be replying to the message, # do it. if loaded_plugin.should_reply(): # Check what the reply type should be. Plugins # that don't specify one will default to text reply_type = 'text' if hasattr(loaded_plugin, 'reply_type'): reply_type = loaded_plugin.reply_type() Telegram.send_message(self.sender_information, reply_type, plugin_output) # GC the loaded_plugin loaded_plugin = None
def run_plugins(self): ''' Run Plugins This is the main function responsible for executing the plugins that have been identified for this message. -- @return None ''' if not self.plugins: logger.warning('No plugins matched for this message.') return # Check with the ACL system what the status is of # the user that has sent the message can_send = self.check_acl() # Load the plugins from the configuration that # should not have ACL rules applied to them config.read(os.path.join(os.path.dirname(__file__), '../settings.ini')) acl_free_plugins = [x.strip() \ for x in config.get('advanced', 'no_acl_plugins', '').split(',')] for plugin in self.plugins: # Check that we are allowed to run this plugin. It # should either be bypassed from the ACL system # using settings.ini, or the user is allowed # to run plugins if not plugin['name'] in acl_free_plugins and not can_send: continue # Getting here, we should run this plugin. # Do it! try: logger.info( 'Running plugin: {plugin} for message {message_id}'.format( plugin=plugin['name'], message_id=self.response['message_id'])) logger.debug( 'Loading plugin: {plugin}'.format(plugin=plugin['name'])) # Find and Load the plugin from the file plugin_on_disk = PluginLoader.find_plugin(plugin['name']) loaded_plugin = PluginLoader.load_plugin(plugin_on_disk) # If we got None from the load, error out if not loaded_plugin: logger.critical( 'Loading plugin {name} returned nothing.'.format( name=plugin['name'])) continue # Run the plugins run() method plugin_output = loaded_plugin.run(self.response) except Exception, e: logger.error( 'Plugin {plugin} failed with: {error}: {trace}'.format( plugin=plugin['name'], error=str(e), trace=traceback.print_exc())) continue # If we should be replying to the message, # do it. if loaded_plugin.should_reply(): # Check what the reply type should be. Plugins # that don't specify one will default to text reply_type = 'text' if hasattr(loaded_plugin, 'reply_type'): reply_type = loaded_plugin.reply_type() Telegram.send_message(self.sender_information, reply_type, plugin_output) # GC the loaded_plugin loaded_plugin = None