# TODO: Add documentation for this module.

import logging
import atexit

import enso.config

_plugins = []

def install( eventManager ):
    eventManager.registerResponder( _init, "init" )
    atexit.register( _shutdown )

def _init():
    for moduleName in enso.config.PLUGINS:
        try:
            # Import the module; most of this code was taken from the
            # Python Library Reference documentation for __import__().
            module = __import__( moduleName, {}, {}, [], 0 )
            components = moduleName.split( "." )
            for component in components[1:]:
                module = getattr( module, component )

            module.load()
            _plugins.append( (module, moduleName) )
        except:
            logging.warn( "Error while loading plugin '%s'." % moduleName )
            raise
        logging.info( "Loaded plugin '%s'." % moduleName )

def _shutdown():
    for module, moduleName in _plugins:
        try:
            module.unload()
        except:
            logging.warn( "Error while unloading plugin '%s'." % moduleName )
            raise
        logging.info( "Unloaded plugin '%s'." % moduleName )
    _plugins[:] = []

# TODO: Add documentation for this module.

import logging

import enso.config

def install( eventManager ):
    eventManager.registerResponder( _init, "init" )

def _init():
    for moduleName in enso.config.PLUGINS:
        try:
            # Import the module; most of this code was taken from the
            # Python Library Reference documentation for __import__().
            module = __import__( moduleName, {}, {}, [], 0 )
            components = moduleName.split( "." )
            for component in components[1:]:
                module = getattr( module, component )

            module.load()
        except:
            logging.warn( "Error while loading plugin '%s'." % moduleName )
            raise
        logging.info( "Loaded plugin '%s'." % moduleName )

Change to plugin interface: unload() is no longer part of the protocol, and any unloading a plugin needs to do can just be done by registering an atexit handler.