Commit 3855e244 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[sources] Turn classmethod into standard method

No need for a class method and easier to get proper logger including source's
name.

--HG--
branch : 3.25
parent 0cf35ffde0e4
...@@ -132,8 +132,7 @@ class AbstractSource(object): ...@@ -132,8 +132,7 @@ class AbstractSource(object):
"""method called to restore a backup of source's data""" """method called to restore a backup of source's data"""
pass pass
@classmethod def _check_config_dict(self, eid, confdict, raise_on_error=True):
def _check_config_dict(cls, eid, confdict, raise_on_error=True):
"""Check configuration of source entity and return config dict properly """Check configuration of source entity and return config dict properly
typed with defaults set. typed with defaults set.
...@@ -141,7 +140,7 @@ class AbstractSource(object): ...@@ -141,7 +140,7 @@ class AbstractSource(object):
raised if some error is encountered, else the problem will be ignored. raised if some error is encountered, else the problem will be ignored.
""" """
processed = {} processed = {}
for optname, optdict in cls.options: for optname, optdict in self.options:
value = confdict.pop(optname, optdict.get('default')) value = confdict.pop(optname, optdict.get('default'))
if value is configuration.REQUIRED: if value is configuration.REQUIRED:
if not raise_on_error: if not raise_on_error:
...@@ -171,18 +170,16 @@ class AbstractSource(object): ...@@ -171,18 +170,16 @@ class AbstractSource(object):
msgargs = ', '.join(confdict) msgargs = ', '.join(confdict)
raise ValidationError(eid, {role_name('config', 'subject'): msg}, msgargs) raise ValidationError(eid, {role_name('config', 'subject'): msg}, msgargs)
else: else:
logger = getLogger('cubicweb.sources') self.warning('unknown options %s', ', '.join(confdict))
logger.warning('unknown options %s', ', '.join(confdict))
# add options to processed, they may be necessary during migration # add options to processed, they may be necessary during migration
processed.update(confdict) processed.update(confdict)
return processed return processed
@classmethod def check_config(self, source_entity):
def check_config(cls, source_entity):
"""Check configuration of source entity, raise ValidationError if some """Check configuration of source entity, raise ValidationError if some
errors are detected. errors are detected.
""" """
return cls._check_config_dict(source_entity.eid, source_entity.dictconfig) return self._check_config_dict(source_entity.eid, source_entity.dictconfig)
def check_urls(self, source_entity): def check_urls(self, source_entity):
"""Check URL of source entity: `urls` is a string that may contain one """Check URL of source entity: `urls` is a string that may contain one
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment