# -*- coding: utf-8 -*- import logging __author__ = "Nicolas Richart" __copyright__ = "Copyright (C) 2016, EPFL (Ecole Polytechnique Fédérale " \ "de Lausanne) - SCITAS (Scientific IT and Application " \ "Support)" __credits__ = ["Nicolas Richart"] __license__ = "BSD" __version__ = "0.1" __maintainer__ = "Nicolas Richart" __email__ = "nicolas.richart@epfl.ch" _logger = logging.getLogger(__name__) __repo_backends = {} def _register_backend(name, backends): __repo_backends[name] = backends def _get_class(_type, backend): if not backend or backend not in __repo_backends: _logger.error("{0} not a known backend".format(backend)) raise TypeError("{0} not a known backend".format(backend)) if _type not in __repo_backends[backend]: _logger.error(("{0} is not a known type for the " + "backend {1}").format(_type, backend)) raise TypeError(("{0} is not a known type for the " + "backend {1}").format(_type, backend)) module_info = __repo_backends[backend][_type] _logger.debug("Importing module {0}".format(module_info['module'])) module = __import__('getmystuph.' + module_info['module'], globals(), locals(), [module_info['class']], 0) _class = getattr(module, module_info['class']) return _class