Compare commits

..

2 commits

Author SHA1 Message Date
Benjamin Renard
d75a61b4e8
Email: fix handling templates_path default value 2023-03-13 19:13:52 +01:00
Benjamin Renard
93b06d6127
ConfigurableObject: add set_default() / set_defaults() methods 2023-03-13 19:12:47 +01:00
3 changed files with 13 additions and 3 deletions

View file

@ -1156,6 +1156,16 @@ class ConfigurableObject:
return default if default is not None else self._defaults.get(option)
def set_default(self, option, default_value):
"""Set option default value"""
assert option in self._defaults, f"Unkown option {option}"
self._defaults[option] = default_value
def set_defaults(self, **default_values):
"""Set options default value"""
for option, default_value in default_values.items():
self.set_default(option, default_value)
def configure(self, comment=None, **kwargs):
"""Configure options on registered mylib.Config object"""
assert self._config, (

View file

@ -143,6 +143,7 @@ class EmailClient(
section.add_option(
StringOption,
"templates_path",
default=self._defaults["templates_path"],
comment="Path to templates directory",
)

View file

@ -18,12 +18,11 @@ def main(argv=None): # pylint: disable=too-many-locals,too-many-statements
config = Config(__doc__, __name__.replace(".", "_"))
email_client = EmailClient(config=config)
email_client.configure()
config.set_default(
"email",
email_client.set_default(
"templates_path",
os.path.join(os.path.dirname(os.path.realpath(__file__)), "email_templates"),
)
email_client.configure()
# Options parser
parser = config.get_arguments_parser(description=__doc__)