Mercurial > enso_core
changeset 59:d3c0220c5895
Moved some code from enso.config to enso.providers, so that enso.config is nothing but constants, and made said code more robust.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 27 Feb 2008 10:50:26 -0800 |
parents | bdc82eda1e46 |
children | 09cc6fd3ddd2 |
files | enso/config.py enso/providers.py |
diffstat | 2 files changed, 23 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/enso/config.py Mon Feb 25 21:05:31 2008 -0800 +++ b/enso/config.py Wed Feb 27 10:50:26 2008 -0800 @@ -54,19 +54,6 @@ " and <command>put</command> commands control" \ " these mini-messages.</p>" -PROVIDERS = [] - -def _initDefaultProviders(): - import logging - - DEFAULT_PROVIDER_MODULES = ["enso_osx"] - - for moduleName in DEFAULT_PROVIDER_MODULES: - try: - module = __import__( moduleName ) - PROVIDERS.append( module ) - logging.info( "Added provider %s." % moduleName ) - except ImportError: - logging.info( "Skipping provider %s." % moduleName ) - -_initDefaultProviders() +# List of modules/packages that support the provider interface to +# provide platform-specific functionality to Enso. +PROVIDERS = ["enso_osx"]
--- a/enso/providers.py Mon Feb 25 21:05:31 2008 -0800 +++ b/enso/providers.py Wed Feb 27 10:50:26 2008 -0800 @@ -6,9 +6,28 @@ _interfaces = {} +_providers = [] + +def _initDefaultProviders(): + for moduleName in enso.config.PROVIDERS: + 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 ) + + _providers.append( module ) + logging.info( "Added provider %s." % moduleName ) + except ImportError: + logging.info( "Skipping provider %s." % moduleName ) + def getInterface( name ): + if not _providers: + _initDefaultProviders() if name not in _interfaces: - for provider in enso.config.PROVIDERS: + for provider in _providers: interface = provider.provideInterface( name ) if interface: logging.info( "Obtained interface '%s' from provider '%s'."