def _load_tree_from_file(self, filepath: Path) -> StructuredDataNode: try: tree = _filter_tree(StructuredDataStore.load_file(filepath)) except FileNotFoundError: raise LoadStructuredDataError() if tree is None or tree.is_empty(): # load_file may return an empty tree raise LoadStructuredDataError() return tree
def get_tree(timestamp: Optional[str]) -> StructuredDataNode: if timestamp is None: return StructuredDataNode() if timestamp in tree_lookup: return tree_lookup[timestamp] if timestamp == latest_timestamp: inventory_tree = load_filtered_inventory_tree(hostname) if inventory_tree is None: raise LoadStructuredDataError() tree_lookup[timestamp] = inventory_tree else: inventory_archive_path = Path(inventory_archive_dir, timestamp) tree_lookup[timestamp] = _filter_tree( StructuredDataStore.load_file(inventory_archive_path)) return tree_lookup[timestamp]