|
|
|
@ -49,6 +49,7 @@ class Interfaces(object):
|
|
|
|
|
|
|
|
|
|
def __init__(self, options): |
|
|
|
|
self._interfaces = [] |
|
|
|
|
self._priority_list = {} |
|
|
|
|
self._options = options |
|
|
|
|
self.options() |
|
|
|
|
return |
|
|
|
@ -61,9 +62,17 @@ class Interfaces(object):
|
|
|
|
|
try: |
|
|
|
|
_log.debug('Importing module %s', import_name) |
|
|
|
|
module = __import__(import_name, fromlist=[import_name]) |
|
|
|
|
|
|
|
|
|
interface_name = module.Interface.NAMESPACE |
|
|
|
|
priority = module.Interface.PRIORITY |
|
|
|
|
|
|
|
|
|
module.Interface.options(self._options) |
|
|
|
|
|
|
|
|
|
self._interfaces.append(interface_name) |
|
|
|
|
if priority in self._priority_list: |
|
|
|
|
self._priority_list[priority].append(interface_name) |
|
|
|
|
else: |
|
|
|
|
self._priority_list[priority] = [interface_name] |
|
|
|
|
except ImportError, exc: |
|
|
|
|
_log.debug('Cannot import module %s', import_name) |
|
|
|
|
_log.debug(str(exc)) |
|
|
|
@ -80,8 +89,10 @@ class Interfaces(object):
|
|
|
|
|
else: |
|
|
|
|
# So we pick the one in the top of the list ('cause we know it's |
|
|
|
|
# importable and the user didn't chose anything.) |
|
|
|
|
# [we could be mean and use random.choice(self._interfaces)] |
|
|
|
|
import_name = self._interfaces[0] |
|
|
|
|
_log.debug('Priority list: ' + str(self._priority_list)) |
|
|
|
|
priority = sorted(self._priority_list.keys(), reverse=True) |
|
|
|
|
top_priority = priority[0] |
|
|
|
|
import_name = self._priority_list[top_priority][0] |
|
|
|
|
|
|
|
|
|
_log.debug('Loading interface %s', import_name) |
|
|
|
|
module_name = _import_name(import_name) |
|
|
|
|