From a269de5dc0b6c9614d4554b67fe91b31931ff7ec Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 23 Dec 2021 19:43:51 -0500 Subject: [PATCH] confighelper: add load_template method This is an alternative to gettemplate that always returns a template. Signed-off-by: Eric Callahan --- moonraker/confighelper.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index efc23f8..a80e5f8 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -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):