def determine_applicable_sections( self, parse_sections: Set[ParsedSectionName], source_type: SourceType, ) -> List[SectionPlugin]: """Try to parse all given sections and return a set of names for which the parsed sections value is not None. This takes into account the supersedings and permanently "dismisses" all superseded raw sections (by setting their parsing result to None). """ applicable_sections: List[SectionPlugin] = [] for host_key, sections_parser in self._data.items(): if host_key.source_type != source_type: continue for section in agent_based_register.get_ranked_sections( sections_parser.sections, parse_sections, ): parsing_result = sections_parser.parse(section) if parsing_result is None: continue applicable_sections.append(section) self._memoized_parsed_sections[host_key + ( section.parsed_section_name, )] = parsing_result # disable superseded sections: sections_parser.disable(section.supersedes) return applicable_sections
def _get_parsed_section_with_cache_info( self, host_key: HostKey, parsed_section_name: ParsedSectionName, ) -> Tuple[Optional[ParsedSectionContent], Optional[Tuple[int, int]]]: cache_key = host_key + (parsed_section_name, ) if cache_key in self._memoized_parsed_sections: return self._memoized_parsed_sections[cache_key] try: host_sections = self._data[host_key] except KeyError: return self._memoized_parsed_sections.setdefault( cache_key, (None, None)) for section in agent_based_register.get_ranked_sections( host_sections.sections, {parsed_section_name}, ): parsed = self._get_parsing_result(host_key, section) if parsed is None: continue cache_info = host_sections.cache_info.get(section.name) return self._memoized_parsed_sections.setdefault( cache_key, (parsed, cache_info)) return self._memoized_parsed_sections.setdefault( cache_key, (None, None))
def _get_parsed_section_with_cache_info( self, host_key: HostKey, parsed_section_name: ParsedSectionName, ) -> Tuple[Optional[ParsedSectionContent], CacheInfo]: cache_key = host_key + (parsed_section_name, ) if cache_key in self._memoized_parsed_sections: return self._memoized_parsed_sections[cache_key] try: sections_parser = self._data[host_key] except KeyError: return self._memoized_parsed_sections.setdefault( cache_key, (None, None)) for section in agent_based_register.get_ranked_sections( sections_parser.sections, {parsed_section_name}, ): parsing_result = sections_parser.parse(section) if parsing_result is None: continue return self._memoized_parsed_sections.setdefault( cache_key, (parsing_result.data, parsing_result.cache_info)) return self._memoized_parsed_sections.setdefault( cache_key, (None, None))
def determine_applicable_sections( self, parse_sections: Set[ParsedSectionName], source_type: SourceType, ) -> List[SectionPlugin]: """Try to parse all given sections and return a set of names for which the parsed sections value is not None. This takes into account the supersedings and permanently "dismisses" all superseded raw sections (by setting their parsing result to None). """ applicable_sections: List[SectionPlugin] = [] for host_key, host_data in self.items(): if host_key.source_type != source_type: continue for section in agent_based_register.get_ranked_sections( host_data.sections, parse_sections, ): parsed = self._get_parsing_result(host_key, section) if parsed is None: continue applicable_sections.append(section) self._parsed_sections[host_key + (section.parsed_section_name,)] = ( parsed, host_data.cache_info.get(section.name), ) # set result of superseded ones to None: for superseded in section.supersedes: self._parsing_results[host_key + (superseded,)] = None return applicable_sections