def __call__(self, loader, node): filename, variables = self._read_tag(loader, node) stream = self._render_template(filename, variables) stream.seek(0) try: if self.yaml_template_matcher.match(filename): sub_loader = lambda _stream: SafeLineLoader( _stream, loader.secrets) document = yaml.load(stream, Loader=sub_loader) return _add_reference(document, loader, node) else: return _add_reference(stream.read(), loader, node) except yaml.YAMLError as ex: _LOGGER.error("Unable to parse rendered YAML in %s: %s", filename, ex) raise HomeAssistantError(ex) from ex
def _include_yaml(loader: EnhancedLoader, node: hass_loader.yaml.Node) -> LoadedYAML: """Handle !include tag""" node_values = process_node(loader, node) try: return hass_loader._add_reference(load_yaml(*node_values), loader, node) except FileNotFoundError as exc: get_log().error("Unable to include file %s: %s", node_values[0], exc) raise HomeAssistantError(exc)
def _include_yaml(ldr, node): args = {} if isinstance(node.value, str): fn = node.value else: fn, args, *_ = ldr.construct_sequence(node) fname = os.path.abspath(os.path.join(os.path.dirname(ldr.name), fn)) try: return loader._add_reference(load_yaml(fname, args), ldr, node) except FileNotFoundError as exc: _LOGGER.error("Unable to include file %s: %s", fname, exc) raise HomeAssistantError(exc)
def _include_dir_named_yaml( loader: EnhancedLoader, node: hass_loader.yaml.Node ) -> LoadedYAML: """Handle !include_dir_named tag""" node_values = process_node(loader, node) mapping: OrderedDictType = OrderedDict() loc: str = os.path.join(os.path.dirname(loader.name), node_values[0]) for fname in hass_loader._find_files(loc, "*.yaml"): filename = os.path.splitext(os.path.basename(fname))[0] if os.path.basename(fname) == hass_loader.SECRET_YAML: continue mapping[filename] = load_yaml(fname, node_values[1], node_values[2]) return hass_loader._add_reference(mapping, loader, node)
def _include_dir_merge_list_yaml( loader: EnhancedLoader, node: hass_loader.yaml.Node ) -> LoadedYAML: """Handle !include_dir_merge_list tag""" node_values = process_node(loader, node) loc: str = os.path.join(os.path.dirname(loader.name), node_values[0]) merged_list: List[hass_loader.JSON_TYPE] = [] for fname in hass_loader._find_files(loc, "*.yaml"): if os.path.basename(fname) == hass_loader.SECRET_YAML: continue loaded_yaml = load_yaml(fname, node_values[1], node_values[2]) if isinstance(loaded_yaml, list): merged_list.extend(loaded_yaml) return hass_loader._add_reference(merged_list, loader, node)
def _include_yaml(loader: CustomLoader, node: hass_loader.yaml.Node) -> LoadedYAML: """Handle !include tag""" node_values = process_node(loader, node) try: return hass_loader._add_reference( load_yaml(*node_values, loader._user_id, None, loader._translations), loader, node, ) except FileNotFoundError as exc: base.log.error("Unable to include file %s: %s", node_values[0], exc) raise HomeAssistantError(exc)