Example #1
0
def _load_library_extensions():
    """
    Locate all setuptools entry points by the name 'delgado_handlers'
    and initialize them.
    Any third-party library may register an entry point by adding the
    following to their setup.py::

        entry_points = {
            'delgado_handlers': [
                'plugin_name = mylib.mymodule:Handler_Class',
            ],
        },

    `plugin_name` will be used to load it as a sub command.
    """
    group = 'delgado_handlers'
    entry_points = pkg_resources.iter_entry_points(group=group)
    plugins = []
    for ep in entry_points:
        try:
            logger.debug('loading %s' % ep.name)
            plugin = ep.load()
            plugin._delgado_name_ = ep.name
            plugins.append(plugin)
        except Exception as error:
            logger.error("Error initializing plugin %s: %s" % (ep, error))
    return plugins
Example #2
0
 def run(self):
     conn = self.connection()
     raw_data = conn.recv(1024)
     try:
         if not raw_data:
             raise Reconnect
         data = loader(raw_data)
         logger.info("Running command: %s" % data)
         call(data)
     except (InvalidFormat, Forbidden) as error:
         logger.error(str(error))
         raise Reconnect
     finally:
         conn.close()
         logger.debug('connection closed')