do not cry if an object in not support to be filled by a backend

This commit is contained in:
Romain Bignon 2013-01-30 11:34:28 +01:00
commit 8550c17cf7
4 changed files with 15 additions and 39 deletions

View file

@ -27,7 +27,7 @@ from weboob.tools.misc import to_unicode
from weboob.tools.ordereddict import OrderedDict
__all__ = ['UserError', 'FieldNotFound', 'ObjectNotSupported', 'NotAvailable',
__all__ = ['UserError', 'FieldNotFound', 'NotAvailable',
'NotLoaded', 'IBaseCap', 'Field', 'IntField', 'DecimalField',
'FloatField', 'StringField', 'BytesField', 'DateField',
'DeltaField', 'empty', 'CapBaseObject']
@ -51,12 +51,6 @@ class UserError(Exception):
"""
class ObjectNotSupported(Exception):
"""
This object is not supported.
"""
class FieldNotFound(Exception):
"""
A field isn't found.

View file

@ -30,7 +30,6 @@ from weboob.capabilities.base import NotAvailable, NotLoaded, ConversionWarning
from weboob.core import Weboob, CallErrors
from weboob.core.backendscfg import BackendsConfig
from weboob.tools.config.iconfig import ConfigError
from weboob.tools.backend import ObjectNotAvailable
from weboob.tools.log import createColoredFormatter, getLogger
from weboob.tools.misc import to_unicode
@ -236,13 +235,7 @@ class BaseApplication(object):
def _do_complete_obj(self, backend, fields, obj):
if fields is None or len(fields) > 0:
try:
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)
backend.fillobj(obj, fields)
return obj
def _do_complete_iter(self, backend, count, fields, res):

View file

@ -26,7 +26,7 @@ from optparse import OptionGroup, OptionParser, IndentedHelpFormatter
import os
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.tools.application.formatters.iformatter import MandatoryFieldsNotFound
from weboob.tools.misc import to_unicode
@ -206,22 +206,13 @@ class ReplApplication(Cmd, ConsoleApplication):
try:
backend = self.weboob.get_backend(obj.backend)
return backend.fillobj(obj, fields)
except ObjectNotSupported:
pass
except UserError, e:
self.bcall_error_handler(backend, e, '')
_id, backend_name = self.parse_id(_id)
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:
try:
backend.fillobj(obj, fields)
except ObjectNotSupported:
pass
except UserError, e:
self.bcall_error_handler(backend, e, '')
return obj
def get_object_list(self, method=None):
@ -291,7 +282,7 @@ class ReplApplication(Cmd, ConsoleApplication):
backends = kwargs.pop('backends', None)
kwargs['backends'] = self.enabled_backends if backends is None else backends
kwargs['condition'] = self.condition
fields = self.selected_fields
fields = kwargs.pop('fields', self.selected_fields)
if '$direct' in fields:
fields = []
elif '$full' in fields:

View file

@ -22,20 +22,14 @@ import os
from threading import RLock
from copy import copy
from weboob.capabilities.base import CapBaseObject, FieldNotFound, ObjectNotSupported, \
IBaseCap, NotLoaded
from weboob.capabilities.base import CapBaseObject, FieldNotFound, \
IBaseCap, NotLoaded, NotAvailable
from weboob.tools.misc import iter_fields
from weboob.tools.log import getLogger
from weboob.tools.value import ValuesDict
__all__ = ['ObjectNotAvailable', 'BackendStorage', 'BackendConfig', 'BaseBackend']
class ObjectNotAvailable(Exception):
"""
Raised when an object is not available.
"""
__all__ = ['BackendStorage', 'BackendConfig', 'BaseBackend']
class BackendStorage(object):
@ -361,9 +355,6 @@ class BaseBackend(object):
: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):
return (v is NotLoaded or isinstance(v, CapBaseObject) and not v.__iscomplete__())
@ -402,3 +393,10 @@ class BaseBackend(object):
if isinstance(obj, key):
self.logger.debug(u'Fill %r with fields: %s' % (obj, missing_fields))
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