Find nodes of the given kind from a directory tree structure. Parameters ---------- tree : dict Directory tree. kind : int Kind to find. Returns ------- nodes : list List of matching nodes.
(tree, kind)
| 9 | |
| 10 | |
| 11 | def dir_tree_find(tree, kind): |
| 12 | """Find nodes of the given kind from a directory tree structure. |
| 13 | |
| 14 | Parameters |
| 15 | ---------- |
| 16 | tree : dict |
| 17 | Directory tree. |
| 18 | kind : int |
| 19 | Kind to find. |
| 20 | |
| 21 | Returns |
| 22 | ------- |
| 23 | nodes : list |
| 24 | List of matching nodes. |
| 25 | """ |
| 26 | nodes = [] |
| 27 | |
| 28 | if isinstance(tree, list): |
| 29 | for t in tree: |
| 30 | nodes += dir_tree_find(t, kind) |
| 31 | else: |
| 32 | # Am I desirable myself? |
| 33 | if tree["block"] == kind: |
| 34 | nodes.append(tree) |
| 35 | |
| 36 | # Search the subtrees |
| 37 | for child in tree["children"]: |
| 38 | nodes += dir_tree_find(child, kind) |
| 39 | return nodes |
| 40 | |
| 41 | |
| 42 | @verbose |
no test coverage detected