Skip to main content

pfdo

https://github.com/FNNDSC/pfdo/actions/workflows/ci.yml/badge.svg https://img.shields.io/pypi/v/pfdo.svg https://img.shields.io/badge/python-3.11%2B-blue.svg

Walk a directory tree with pftree and do something in every directory: the base class of the pfdo family.

Overview

pfdo is the base class of a family of tools (pfdo_run, pfdo_med2image, pfdo_mgz2image and others) that each do one thing per directory of an input tree and write their results to the same place in an output tree. It is a pftree.Pftree whose three callbacks, read, analyze and save, are meant to be overridden, plus one convenience the family shares: --analyzeFileIndex, the choice of which of a directory’s files the analyze step gets.

On its own, pfdo walks a tree, applies pftree’s filters, and with --test runs its demonstration callbacks: read lists each directory’s files, analyze selects by index and prefixes every name with analyzed-, save touches those names in the output directory.

Installation

pip install pfdo

Python 3.11 or newer; depends on pftree.

Command line

pfdo --inputDir /data --outputDir /tmp/out --fileFilter jpg --test --json
pfdo --inputDir /data --outputDir /tmp/out --dirFilter 100307 --analyzeFileIndex m --test
pfdo --man

pfdo --man prints the full manual, --synopsis its first page, --help the quick reference. All of pftree’s options apply (--fileFilter, --dirFilter and their logic, --maxDepth, --outputLeafDir, --threads, --relativeDir, --followLinks, --overwrite, --json, --printElapsedTime); pfdo adds:

--analyzeFileIndex <a|f|l|m|N>

Which of a directory’s files the analyze step receives: a all (default), f first, l last, m middle, or an integer index that wraps in either direction (-1 is the last file, len the first again).

--test

Run the demonstration callbacks. An output file that already exists stops that directory unless --overwrite is given.

Library

from pathlib import Path
from pftree.models import DirNode, StageResult
from pfdo import Pfdo, PfdoOptions

class Counter(Pfdo):
    processAlways = True

    def inputAnalyze_callback(self, node: DirNode, read: StageResult) -> StageResult:
        chosen = self.filesToAnalyze(node)
        return StageResult(status=True, files=chosen, payload={"count": len(chosen)})

    def outputSave_callback(self, node: DirNode, analyze: StageResult) -> StageResult:
        node.outputPath.mkdir(parents=True, exist_ok=True)
        (node.outputPath / "count.txt").write_text(f"{analyze.payload['count']}\n")
        return StageResult(status=True, files=["count.txt"])

result = Counter(PfdoOptions(inputDir=Path("/data"), outputDir=Path("/out"), threads=4)).run()

PfdoOptions is pftree.TreeOptions plus analyzeFileIndex and testRun; PfdoOptions.fromDict(vars(args)) builds it from an argparse Namespace and ignores keys it does not know. A subclass sets processAlways = True so run() always runs the callbacks; it calls self.filesToAnalyze(node) to honour --analyzeFileIndex. run() returns pftree’s RunResult (status, tree, process, runTime).

For its command line, a package built on pfdo composes pfdo.__main__’s parts: parserSelf_build() and pftree’s parserCore_build() / parserIO_build() for the parser, synopsis(command=...) or the CLI_* and ARGS_SYNOPSIS_* texts for the manual, and pftree.manual.Manual with manual_print to render it.

Changes in 6.0

  • Built on pftree 4; pfmisc and pudb are no longer dependencies.

  • The callbacks are inputRead_callback, inputAnalyze_callback and outputSave_callback, taking a DirNode and returning a StageResult, not tuples and dicts.

  • --analyzeFileIndex m picks the true middle file (index len // 2); 5.x picked one past it for odd-length lists.

  • An existing output file fails that directory and the run continues; 5.x stopped the loop and left the directory half written.

  • --test maps to testRun; pftree’s own --test <seconds> is not exposed.

  • main(argv) honours argv; --version, --man and --synopsis exit 0.

  • Packaging is pyproject.toml only, published from CI on a v* tag.

Metadata

Release files for pfdo 6.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pfdo 6.0.0
File Size Uploaded Provenance Actions
pfdo-6.0.0.tar.gz 17.4 kB With provenance Details for pfdo-6.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pfdo 6.0.0
File Interpreter ABI Platform Actions
pfdo-6.0.0-py3-none-any.whl Python 3 none any Details for pfdo-6.0.0-py3-none-any.whl

Total release size: 33.5 kB

Release files / pfdo-6.0.0.tar.gz

Download URL pfdo-6.0.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
159f93bcf810109872c607c995b03b214d35b58a4bccd9c57c3cede198c6764d
BLAKE2b-256 checksum
How to use checksums
b4a5beccfc8deef2efaea3a3712c26ccd03d36b0dc10d0ea677a7650a124d3c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / pfdo-6.0.0-py3-none-any.whl

Download URL pfdo-6.0.0-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5e78356a73237909a903dd392abd566eaf95fe2143c41a45b108252684472b8
BLAKE2b-256 checksum
How to use checksums
81898f0edc4e8ade069f9ef04b83d0556cd2c477d23aa049ba43633dee4f4721
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Security for pfdo 6.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pfdo-6.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page