do not cry if an object in not support to be filled by a backend
This commit is contained in:
parent
9d693bd982
commit
8550c17cf7
4 changed files with 15 additions and 39 deletions
|
|
@ -27,7 +27,7 @@ from weboob.tools.misc import to_unicode
|
||||||
from weboob.tools.ordereddict import OrderedDict
|
from weboob.tools.ordereddict import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['UserError', 'FieldNotFound', 'ObjectNotSupported', 'NotAvailable',
|
__all__ = ['UserError', 'FieldNotFound', 'NotAvailable',
|
||||||
'NotLoaded', 'IBaseCap', 'Field', 'IntField', 'DecimalField',
|
'NotLoaded', 'IBaseCap', 'Field', 'IntField', 'DecimalField',
|
||||||
'FloatField', 'StringField', 'BytesField', 'DateField',
|
'FloatField', 'StringField', 'BytesField', 'DateField',
|
||||||
'DeltaField', 'empty', 'CapBaseObject']
|
'DeltaField', 'empty', 'CapBaseObject']
|
||||||
|
|
@ -51,12 +51,6 @@ class UserError(Exception):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class ObjectNotSupported(Exception):
|
|
||||||
"""
|
|
||||||
This object is not supported.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class FieldNotFound(Exception):
|
class FieldNotFound(Exception):
|
||||||
"""
|
"""
|
||||||
A field isn't found.
|
A field isn't found.
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ from weboob.capabilities.base import NotAvailable, NotLoaded, ConversionWarning
|
||||||
from weboob.core import Weboob, CallErrors
|
from weboob.core import Weboob, CallErrors
|
||||||
from weboob.core.backendscfg import BackendsConfig
|
from weboob.core.backendscfg import BackendsConfig
|
||||||
from weboob.tools.config.iconfig import ConfigError
|
from weboob.tools.config.iconfig import ConfigError
|
||||||
from weboob.tools.backend import ObjectNotAvailable
|
|
||||||
from weboob.tools.log import createColoredFormatter, getLogger
|
from weboob.tools.log import createColoredFormatter, getLogger
|
||||||
from weboob.tools.misc import to_unicode
|
from weboob.tools.misc import to_unicode
|
||||||
|
|
||||||
|
|
@ -236,13 +235,7 @@ class BaseApplication(object):
|
||||||
|
|
||||||
def _do_complete_obj(self, backend, fields, obj):
|
def _do_complete_obj(self, backend, fields, obj):
|
||||||
if fields is None or len(fields) > 0:
|
if fields is None or len(fields) > 0:
|
||||||
try:
|
backend.fillobj(obj, fields)
|
||||||
backend.fillobj(obj, fields)
|
|
||||||
except ObjectNotAvailable, e:
|
|
||||||
logging.warning(u'Could not retrieve required fields (%s): %s' % (','.join(fields), e))
|
|
||||||
for field in fields:
|
|
||||||
if getattr(obj, field) is NotLoaded:
|
|
||||||
setattr(obj, field, NotAvailable)
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _do_complete_iter(self, backend, count, fields, res):
|
def _do_complete_iter(self, backend, count, fields, res):
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ from optparse import OptionGroup, OptionParser, IndentedHelpFormatter
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from weboob.capabilities.base import FieldNotFound, CapBaseObject, ObjectNotSupported, UserError
|
from weboob.capabilities.base import FieldNotFound, CapBaseObject, UserError
|
||||||
from weboob.core import CallErrors
|
from weboob.core import CallErrors
|
||||||
from weboob.tools.application.formatters.iformatter import MandatoryFieldsNotFound
|
from weboob.tools.application.formatters.iformatter import MandatoryFieldsNotFound
|
||||||
from weboob.tools.misc import to_unicode
|
from weboob.tools.misc import to_unicode
|
||||||
|
|
@ -206,22 +206,13 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
try:
|
try:
|
||||||
backend = self.weboob.get_backend(obj.backend)
|
backend = self.weboob.get_backend(obj.backend)
|
||||||
return backend.fillobj(obj, fields)
|
return backend.fillobj(obj, fields)
|
||||||
except ObjectNotSupported:
|
|
||||||
pass
|
|
||||||
except UserError, e:
|
except UserError, e:
|
||||||
self.bcall_error_handler(backend, e, '')
|
self.bcall_error_handler(backend, e, '')
|
||||||
|
|
||||||
_id, backend_name = self.parse_id(_id)
|
_id, backend_name = self.parse_id(_id)
|
||||||
backend_names = (backend_name,) if backend_name is not None else self.enabled_backends
|
backend_names = (backend_name,) if backend_name is not None else self.enabled_backends
|
||||||
for backend, obj in self.do(method, _id, backends=backend_names):
|
for backend, obj in self.do(method, _id, backends=backend_names, fields=fields):
|
||||||
if obj:
|
if obj:
|
||||||
try:
|
|
||||||
backend.fillobj(obj, fields)
|
|
||||||
except ObjectNotSupported:
|
|
||||||
pass
|
|
||||||
except UserError, e:
|
|
||||||
self.bcall_error_handler(backend, e, '')
|
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def get_object_list(self, method=None):
|
def get_object_list(self, method=None):
|
||||||
|
|
@ -291,7 +282,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
backends = kwargs.pop('backends', None)
|
backends = kwargs.pop('backends', None)
|
||||||
kwargs['backends'] = self.enabled_backends if backends is None else backends
|
kwargs['backends'] = self.enabled_backends if backends is None else backends
|
||||||
kwargs['condition'] = self.condition
|
kwargs['condition'] = self.condition
|
||||||
fields = self.selected_fields
|
fields = kwargs.pop('fields', self.selected_fields)
|
||||||
if '$direct' in fields:
|
if '$direct' in fields:
|
||||||
fields = []
|
fields = []
|
||||||
elif '$full' in fields:
|
elif '$full' in fields:
|
||||||
|
|
|
||||||
|
|
@ -22,20 +22,14 @@ import os
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
from weboob.capabilities.base import CapBaseObject, FieldNotFound, ObjectNotSupported, \
|
from weboob.capabilities.base import CapBaseObject, FieldNotFound, \
|
||||||
IBaseCap, NotLoaded
|
IBaseCap, NotLoaded, NotAvailable
|
||||||
from weboob.tools.misc import iter_fields
|
from weboob.tools.misc import iter_fields
|
||||||
from weboob.tools.log import getLogger
|
from weboob.tools.log import getLogger
|
||||||
from weboob.tools.value import ValuesDict
|
from weboob.tools.value import ValuesDict
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['ObjectNotAvailable', 'BackendStorage', 'BackendConfig', 'BaseBackend']
|
__all__ = ['BackendStorage', 'BackendConfig', 'BaseBackend']
|
||||||
|
|
||||||
|
|
||||||
class ObjectNotAvailable(Exception):
|
|
||||||
"""
|
|
||||||
Raised when an object is not available.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class BackendStorage(object):
|
class BackendStorage(object):
|
||||||
|
|
@ -361,9 +355,6 @@ class BaseBackend(object):
|
||||||
:type fields: :class:`list`
|
:type fields: :class:`list`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if type(obj) not in self.OBJECTS:
|
|
||||||
raise ObjectNotSupported('The object of type %s is not supported by the backend %s' % (type(obj).__name__, self))
|
|
||||||
|
|
||||||
def not_loaded(v):
|
def not_loaded(v):
|
||||||
return (v is NotLoaded or isinstance(v, CapBaseObject) and not v.__iscomplete__())
|
return (v is NotLoaded or isinstance(v, CapBaseObject) and not v.__iscomplete__())
|
||||||
|
|
||||||
|
|
@ -402,3 +393,10 @@ class BaseBackend(object):
|
||||||
if isinstance(obj, key):
|
if isinstance(obj, key):
|
||||||
self.logger.debug(u'Fill %r with fields: %s' % (obj, missing_fields))
|
self.logger.debug(u'Fill %r with fields: %s' % (obj, missing_fields))
|
||||||
return value(self, obj, missing_fields) or obj
|
return value(self, obj, missing_fields) or obj
|
||||||
|
|
||||||
|
# Object is not supported by backend. Do not notice it to avoid flooding user.
|
||||||
|
# That's not so bad.
|
||||||
|
for field in missing_fields:
|
||||||
|
setattr(obj, field, NotAvailable)
|
||||||
|
|
||||||
|
return obj
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue