A functional util for generic recursive tree processing
Project description
A Functional util for recursive tree processing
Usage
from tree_utils.fs_recursion import RecursionStrategy, ProcessingFunctions, fs_tree_recursion, TreeNodeFunctions, get_children_paths
from tree_utils.tree_recursion import ProcessingFunctions, RecursionStrategy, TreeNodeFunctions
def example_extract_file_paths(root_dir_path: str, options={}, mode=RecursionStrategy.ANY):
tree_node_functions: TreeNodeFunctions = TreeNodeFunctions()
def process_file(path: str):
logging.debug(f"Processing file: {path}")
print(path)
# Return the path as the desired content extracted from the node
return path
def process_dir(dir_path: str, children_paths: list[str], children_processing_results: list[str]):
# The paths we returned in 'process_file' are collected and passed to the 'process_dir' function as the children_processing_results
logging.debug(f"Processing dir: {dir_path}")
return children_processing_results
tree_node_functions.is_leaf = os.path.isfile
tree_node_functions.is_node = os.path.isdir
tree_node_functions.get_children_ids = get_children_paths
tree_node_functions.process_leaf = process_file
tree_node_functions.process_node = process_dir
return fs_tree_recursion(root_dir_path, tree_node_functions, options, mode=mode)
example_extract_file_paths('/some/path')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file recurse-tree-process-0.0.2.tar.gz
.
File metadata
- Download URL: recurse-tree-process-0.0.2.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf0101826e277c764ce53574af2a3f5d24b051aa38a88cacd81de5f251d75b01 |
|
MD5 | adab4baf869be1577cc05d4f3559263e |
|
BLAKE2b-256 | 6e8f6cffe74a770e4f6edf8b7fd40c68593209016d78b6d62067fc902973ac08 |
File details
Details for the file recurse_tree_process-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: recurse_tree_process-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1da5cee197642a341331f0f94bdbbc513a6bb8b5917902a9375ff20bf0eac5b |
|
MD5 | d3a90240ed915074a1a804df43264319 |
|
BLAKE2b-256 | 2b17acc04c19167b3ae192a62c9a132ba67382ba8541a0dee8c957cfb55fccc5 |