Generate, Compare and Analyse Directory Merkle Trees
Project description
dmerk
dmerk (pronounced dee-merk) is a program that creates a merkle tree for your directories.
This can be useful in many situations. For example, to detect which files were modified, or to compare two backups for duplicate files. Think hash digest / checksum verification, but instead of comparing just a pair of hash digests, we are comparing two trees of digests.
Table of Contents
Installation
pip install dmerk
Shell Autocomplete
dmerk uses argcomplete to support shell autocompletion. In order to enable this, you need to,
# zsh/bash shell(s)
activate-global-python-argcomplete
# fish shell
register-python-argcomplete --shell fish dmerk | source
Usage / Quickstart
TUI (Terminal User Interface)
Launch the TUI for a more interactive experience:
dmerk tui
The TUI is built with Textual and provides a powerful interface for all dmerk functionality. It's especially useful for the compare operation, allowing you to quickly navigate and compare different submerkles at various hierarchical levels of two merkle trees, which is more cumbersome with the CLI alone.
Generate
Generate a merkle tree for a directory:
dmerk generate /path/to/directory
Options:
-p, --print: Print the merkle output to stdout-f FILENAME, --filename FILENAME: Provide a custom filename or file path for saving--fail-on-error: Immediately fail upon encountering errors (such as broken symlinks)--no-save: If specified, the generated merkle tree will not be saved to file (not recommended as generating merkle trees is computationally expensive)
Compare
Compare two directory merkle trees and return the diffs and matches:
dmerk compare -p1 PATH1 -p2 PATH2 [-sp1 SUBPATH1] [-sp2 SUBPATH2]
The paths PATH1 and PATH2 are required and can be either:
- Paths to directories to compare
- Paths to
.dmerkfiles created using the generate command
Options:
--no-save: If specified, the generated merkle trees will not be saved to file (only applies when comparing directories)
Examples:
dmerk compare -p1=/home/raghuram/Documents -p2=/media/raghuram/BACKUP_DRIVE/Documents
dmerk compare -p1=Documents_e6eaccb4.dmerk -p2=Documents_b2a7cef7.dmerk
When using .dmerk files, you can optionally provide subpaths to compare specific subdirectories:
dmerk compare \
-p1=Documents_e6eaccb4.dmerk \
-p2=Documents_b2a7cef7.dmerk \
-sp1=Receipts/Rent \
-sp2=Receipts/Rent
This is particularly useful because the compare operation performs a "shallow comparison" that only shows diffs/matches among immediate children.
Features and Limitations
Current Support
- Primary testing on Linux; Windows and macOS support coming soon™
- Handles regular files, directories, and symlinks to regular files/directories
- Processes hidden files and directories
- Uses MD5 as the digest algorithm for speed (configurable options planned)
Requirements
- Read permission for files
- Read and execute permissions for directories
- File and directory names must be valid UTF-8 byte sequences
- For support of non-UTF-8 filenames, please upvote this issue
Limitations
- Does not support special files (character/block devices, sockets, pipes)
- Symlinks to special files will cause exceptions
- Directory digests are currently based only on file contents, not filenames or metadata (permissions, owner, timestamps, etc.)
- If you need directory digests that include metadata, please open a new issue explaining your use case
Development
Contributing
If you want to report bugs, request features, or contribute improvements, please file an issue on GitHub. I appreciate your interest in this project and will respond as soon as possible 😁.
Setup
# Clone and set up the repository
git clone https://github.com/krishraghuram/dmerk.git
cd dmerk
python3 -m venv venv
source venv/bin/activate
# Install development dependencies
pip install -e .[dev]
# Verify installation
dmerk --help
Textual Development Tools
The TUI is built with Textual. You can use Textual's development tools:
# Run in dev mode with access to logs and console
textual run --dev dmerk.tui
For more information, see the Textual DevTools documentation.
Code Quality
We maintain code quality through automated checks that run as Git hooks:
- Pre-commit: lint, format, and type checking
- Pre-push: unit tests
You can also run these checks manually:
# Run individual checks
nox --session lint
nox --session format
nox --session mypy
nox --session test
Build and Publish
python -m build
python -m pip install --force-reinstall ../dmerk/dist/dmerk-0.1.0-py3-none-any.whl
python -m twine upload dist/*
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dmerk-0.3.0.tar.gz.
File metadata
- Download URL: dmerk-0.3.0.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5feeaa325cbab8dab6b4a270db0fb57d90cc40960b93fc25ed0a19663819c54f
|
|
| MD5 |
e511d9aab5a60aab581ee2ac675b688c
|
|
| BLAKE2b-256 |
d34ad5ab3f913b2fd13d37f9d3ceb47af6af0f13f1ea8927682b593768100094
|
File details
Details for the file dmerk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: dmerk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6343d7d9148258dc82e63e4fbb1f513632a332b87cfce241a248a6783dcbce5
|
|
| MD5 |
30689114d160f5687d6a3049b455c1ec
|
|
| BLAKE2b-256 |
f6b9f32847a18e6f803bde3a73a70dec37e69e5ad855e202f5089b67de98ca85
|