confighelper: add load_template method

This is an alternative to gettemplate that always returns a
template.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-12-23 19:43:51 -05:00
parent a4f960d40c
commit a269de5dc0
1 changed files with 12 additions and 0 deletions

View File

@ -350,6 +350,18 @@ class ConfigHelper:
return self._get_option(gettemplate_wrapper, option, default,
deprecate=deprecate)
def load_template(self,
option: str,
default: Union[SentinelClass, str] = SENTINEL,
deprecate: bool = False
) -> JinjaTemplate:
val = self.gettemplate(option, default, deprecate)
if isinstance(val, str):
template: TemplateFactory
template = self.server.lookup_component('template')
return template.create_template(val)
return val
def read_supplemental_config(self, file_name: str) -> ConfigHelper:
cfg_file_path = os.path.normpath(os.path.expanduser(file_name))
if not os.path.isfile(cfg_file_path):