Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

recurse-tree-process-0.0.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

recurse_tree_process-0.0.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

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

Hashes for recurse-tree-process-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bf0101826e277c764ce53574af2a3f5d24b051aa38a88cacd81de5f251d75b01
MD5 adab4baf869be1577cc05d4f3559263e
BLAKE2b-256 6e8f6cffe74a770e4f6edf8b7fd40c68593209016d78b6d62067fc902973ac08

See more details on using hashes here.

File details

Details for the file recurse_tree_process-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for recurse_tree_process-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f1da5cee197642a341331f0f94bdbbc513a6bb8b5917902a9375ff20bf0eac5b
MD5 d3a90240ed915074a1a804df43264319
BLAKE2b-256 2b17acc04c19167b3ae192a62c9a132ba67382ba8541a0dee8c957cfb55fccc5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page