Skip to main content

Filesystem state snapshots with diff comparison

Project description

philiprehberger-dir-snapshot

Tests PyPI version License

Filesystem state snapshots with diff comparison.

Installation

pip install philiprehberger-dir-snapshot

Usage

Take a Snapshot

from philiprehberger_dir_snapshot import snapshot

snap = snapshot("./src")
print(f"Found {len(snap.files)} files")

Compare Snapshots

before = snapshot("./src")
# ... make changes ...
after = snapshot("./src")

diff = before.diff(after)
print(diff.summary())

for f in diff.added:
    print(f"+ {f.path}")
for f in diff.removed:
    print(f"- {f.path}")
for f in diff.modified:
    print(f"~ {f.path}")

Save and Load

# Save to JSON
before.to_json("snapshot.json")

# Load later
from philiprehberger_dir_snapshot import Snapshot
restored = Snapshot.from_json("snapshot.json")

Options

# Include only Python files
snap = snapshot("./src", include=["*.py"])

# Exclude build artifacts
snap = snapshot(".", exclude=["__pycache__", "*.pyc", ".git"])

# Use faster hashing (or disable with "none")
snap = snapshot(".", hash_mode="md5")

API

Function / Class Description
snapshot(path, hash_mode="mtime", include=None, exclude=None) Create a directory snapshot
Snapshot.diff(other) Compare two snapshots, returns SnapshotDiff
Snapshot.to_json(path) / Snapshot.from_json(path) Serialize/deserialize
FileEntry File metadata — .path, .size, .mtime, .hash
SnapshotDiff.has_changes True if any files were added, removed, or modified
SnapshotDiff.added / .removed / .modified / .unchanged Lists of file paths
SnapshotDiff.summary() Human-readable diff summary

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_dir_snapshot-0.2.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_dir_snapshot-0.2.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_dir_snapshot-0.2.2.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_dir_snapshot-0.2.2.tar.gz
Algorithm Hash digest
SHA256 11334053af0963e20a8c813b9b98e12506f3a3198374bc4a84c7da18437c66a2
MD5 4237ee60c90da5ef32f01ece26570257
BLAKE2b-256 ba4db21e3584e1ff9ed4799f9014b093978719793d4acc51eef5e3f796f9799b

See more details on using hashes here.

File details

Details for the file philiprehberger_dir_snapshot-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_dir_snapshot-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3b4dde1a5721cff66a31b878e9ae9a68ca8589c324423b30c732223c8e370b11
MD5 ffa741ae562f9e30838f0bb849bb409e
BLAKE2b-256 ff4b17acc920a0728fe572100f28e92e46b165dc48dbb65f9e9dd1ef60d97e27

See more details on using hashes here.

Supported by

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