ability to check caps of a backend against a string (not only a class)
This commit is contained in:
parent
05b9bbdb2e
commit
7b0c91275f
3 changed files with 11 additions and 3 deletions
|
|
@ -78,7 +78,8 @@ class Backend(object):
|
||||||
|
|
||||||
def has_caps(self, *caps):
|
def has_caps(self, *caps):
|
||||||
for c in caps:
|
for c in caps:
|
||||||
if issubclass(self.klass, c):
|
if (isinstance(c, (unicode,str)) and c in [cap.__name__ for cap in self.iter_caps()]) or \
|
||||||
|
(type(c) == type and issubclass(self.klass, c)):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
if caps is not None:
|
if caps is not None:
|
||||||
if not isinstance(caps, (list, tuple, set)):
|
if not isinstance(caps, (list, tuple, set)):
|
||||||
caps = (caps,)
|
caps = (caps,)
|
||||||
caps = iter(cap.__name__ for cap in caps)
|
caps = [(cap if isinstance(cap, (str,unicode)) else cap.__name__) for cap in caps]
|
||||||
weboobcfg.command_backends(*caps)
|
weboobcfg.command_backends(*caps)
|
||||||
logging.error(u'You can configure backends using the "weboob-config add" command:\nweboob-config add <name> [options..]')
|
logging.error(u'You can configure backends using the "weboob-config add" command:\nweboob-config add <name> [options..]')
|
||||||
with open('/dev/null', 'w') as devnull:
|
with open('/dev/null', 'w') as devnull:
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import os
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
from logging import debug
|
from logging import debug
|
||||||
|
|
||||||
|
from weboob.capabilities.cap import ICap
|
||||||
|
|
||||||
__all__ = ['BaseBackend', 'ObjectNotSupported']
|
__all__ = ['BaseBackend', 'ObjectNotSupported']
|
||||||
|
|
||||||
|
|
@ -170,9 +171,15 @@ class BaseBackend(object):
|
||||||
|
|
||||||
return self.BROWSER(*args, **kwargs)
|
return self.BROWSER(*args, **kwargs)
|
||||||
|
|
||||||
|
def iter_caps(self):
|
||||||
|
for cap in self.__class__.__bases__:
|
||||||
|
if issubclass(cap, ICap) and cap != ICap:
|
||||||
|
yield cap
|
||||||
|
|
||||||
def has_caps(self, *caps):
|
def has_caps(self, *caps):
|
||||||
for c in caps:
|
for c in caps:
|
||||||
if isinstance(self, c):
|
if (isinstance(c, (unicode,str)) and c in [cap.__name__ for cap in self.iter_caps()]) or \
|
||||||
|
isinstance(self, c):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue