
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[:] = []


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.
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.

git-svn-id: b6fd099cd3d97ba56ca68c4d1ea7aaa6a131ba03@17 8b7adc99-b347-0410-ae0a-d9e86c8d69b5

  
  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[:] = []
- 
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.
## Code Before:

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[:] = []

## Instruction:
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.
## Code After:

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 )
