def findall(self, name, fuzzy=True): """ Locate all nodes withing the tree starting from this node. Inputs: name[str]: The name to search for within the tree. fuzzy[bool]: When True (the default) a "fuzzy" search is performed, meaning that the provide name must be in the node name. If this is set to False the names must match exact. """ if HAVE_ANYTREE: filter_ = lambda n: (fuzzy and name in n.name) or (not fuzzy and n.name == name) return [node for node in anytree.PreOrderIter(self, filter_=filter_)] else: msg = "The 'findall' method requires the 'anytree' python package. This can " \ "be installed via your python package manager (e.g., pip install anytree --user)." message.mooseError(msg)
def find(self, name, fuzzy=True): """ Locate first occurrence of a node by name starting from this node. Inputs: name[str]: The name to search for within the tree. fuzzy[bool]: When True (the default) a "fuzzy" search is performed, meaning that the provide name must be in the node name. If this is set to False the names must match exact. """ if HAVE_ANYTREE: for node in anytree.PreOrderIter(self): if (fuzzy and name in node.fullpath) or (not fuzzy and name == node.fullpath): return node else: msg = "The 'find' method requires the 'anytree' python package. This can " \ "be installed via your python package manager (e.g., pip install anytree --user)." message.mooseError(msg)
def hit_load(filename): """ Read and parse a hit file (MOOSE input file format). Inputs: filenae[str]: The filename to open and parse. Returns a HitNode object, which is the root of the tree. HitNode objects are custom versions of the anytree.Node objects. """ if os.path.exists(filename): with open(filename, 'r') as fid: content = fid.read() else: message.mooseError("Unable to load the hit file ", filename) hit_node = hit.parse(filename, content) root = HitNode(hitnode=hit_node) hit_parse(root, hit_node, filename) return root