Commit 7ae2d402 authored by Jerome Berthier's avatar Jerome Berthier Committed by ntome

weboob.tools.backend: add CONFIG inheritance to AbstractModule

Currently when using AbstractModule you need to copy/paste the
whole module CONFIG if you have to add or modify only one Value.

This patch allows an AbstractModule to override one or more
Value from its parent config, avoiding a lot of copy/paste.

Note that if you need to remove one Value, you still need to
copy/paste the whole CONFIG definition.
parent 7e2f5daf
......@@ -490,7 +490,11 @@ class AbstractModule(Module):
allow to simplify code with a fake inheritance: weboob will install (if needed) and
load a PARENT module and build our AbstractModule on top of this class.
PARENT is a mandatory attribute of any AbstractModule
PARENT is a mandatory attribute of any AbstractModule.
By default an AbstractModule inherits its parent backends CONFIG.
To add backend values, use ADDITIONAL_CONFIG.
To remove backend values, you must override CONFIG definition.
Note that you must pass a valid weboob instance as first argument of the constructor.
"""
......@@ -506,4 +510,10 @@ class AbstractModule(Module):
raise ModuleInstallError('The module %s depends on %s module but %s\'s installation failed with: %s' % (name, cls.PARENT, cls.PARENT, err))
cls.__bases__ = tuple([parent] + list(cls.iter_caps()))
# fake backend config inheritance, override existing Values
# do not use CONFIG to allow the children to overwrite completely the parent CONFIG.
if getattr(cls, 'ADDITIONAL_CONFIG', None):
cls.CONFIG = BackendConfig(*(list(parent.CONFIG.values()) + list(cls.ADDITIONAL_CONFIG.values())))
return object.__new__(cls)
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