Skip to content

capturegraph.data.save.commit #

Commit - Save modified data back to a CaptureTarget#

Traverses a CaptureTarget (or Dict/List of modified data), checks for SaveOverWith and SaveIfMissing markers, and writes the values to disk in the correct locations based on the manifest.

Example
import capturegraph.data as cg

# Load and modify
target = cg.CaptureTarget("./MyCapture")
target.surveys[0].location = cg.SaveOverWith(
    cg.Location(latitude=42.0, longitude=-76.0, altitude=100.0)
)

# Commit all changes to disk
cg.commit(target)

commit(target) #

Commit all SaveOverWith and SaveIfMissing markers to disk.

Traverses the target data structure, finds all save markers, and writes the values to the appropriate file locations based on the manifest.

Parameters:

Name Type Description Default
target Union[CaptureTarget, Dict]

A CaptureTarget or Dict with _path and _manifest attributes

required

Returns:

Type Description
int

Number of files saved

Example
import capturegraph.data as cg

target = cg.CaptureTarget("./MyCapture")
target.surveys[0].location = cg.SaveOverWith(new_location)
cg.commit(target)  # Writes location.json → returns 1
Source code in capturegraph-lib/capturegraph/data/save/commit.py
def commit(target: Union[CaptureTarget, Dict]) -> int:
    """Commit all SaveOverWith and SaveIfMissing markers to disk.

    Traverses the target data structure, finds all save markers, and
    writes the values to the appropriate file locations based on the
    manifest.

    Args:
        target: A CaptureTarget or Dict with _path and _manifest attributes

    Returns:
        Number of files saved

    Example:
        ```python
        import capturegraph.data as cg

        target = cg.CaptureTarget("./MyCapture")
        target.surveys[0].location = cg.SaveOverWith(new_location)
        cg.commit(target)  # Writes location.json → returns 1
        ```
    """
    # Get path and manifest from target
    path = object.__getattribute__(target, "_path")
    manifest = object.__getattribute__(target, "_manifest")

    return _commit_directory(target, path, manifest)