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