Mercurial > enso_core
view enso/providers.py @ 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 |
line wrap: on
line source
# TODO: Add documentation for this module. import logging import enso.config _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 _providers: interface = provider.provideInterface( name ) if interface: logging.info( "Obtained interface '%s' from provider '%s'." % (name, provider.__name__) ) _interfaces[name] = interface break if name in _interfaces: return _interfaces[name] else: raise ProviderNotFoundError( name ) class ProviderNotFoundError( Exception ): pass