Compare commits
2 commits
e71fb28295
...
d75a61b4e8
Author | SHA1 | Date | |
---|---|---|---|
|
d75a61b4e8 | ||
|
93b06d6127 |
3 changed files with 13 additions and 3 deletions
|
@ -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, (
|
||||
|
|
|
@ -143,6 +143,7 @@ class EmailClient(
|
|||
section.add_option(
|
||||
StringOption,
|
||||
"templates_path",
|
||||
default=self._defaults["templates_path"],
|
||||
comment="Path to templates directory",
|
||||
)
|
||||
|
||||
|
|
|
@ -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__)
|
||||
|
|
Loading…
Reference in a new issue