From 7ae2d40207db5d42097262f6b3732b3fee0c06e7 Mon Sep 17 00:00:00 2001 From: Jerome Berthier Date: Fri, 16 Aug 2019 14:26:41 +0200 Subject: [PATCH] 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. --- weboob/tools/backend.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/weboob/tools/backend.py b/weboob/tools/backend.py index 3e421f5425..63dbef18ca 100644 --- a/weboob/tools/backend.py +++ b/weboob/tools/backend.py @@ -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 @@ def __new__(cls, weboob, name, config=None, storage=None, logger=None, nofail=Fa 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) -- GitLab