deltaresult
Do you ever develop scripts creating multiple files only to realize that you must only track differences between runs of the script itself? If so, this project might be for you.
deltaresult:
- Helps create and maintain "deltaresult repos" where the runs will happen
- Wraps around the commands to initialize the folders and track changes after each run
- Keeps track of the runs themselves via git
Basic example
Imagine having a program that always generates three files:
- A first file with always the same contents
- A second file in which the contents always change
- A third file with an unpredictable name
Standalone run
If you run this program on a directory, you would for example see the following result:
./unchanged
./changing
./unpredictable_23432
With deltaresult
Run it instead with the deltaresults wrapper and you will see this structure:
./README.md
./changes/2022-02-14_203436.080337/unchanged
./changes/2022-02-14_203436.080337/changing
./changes/2022-02-14_203436.080337/unpredictable_23432
./work/unchanged
./work/changing
./work/unpredictable_234325
./last_changes -> ./changes/2022-02-14_203436.080337
Run it a second time, and this will be in the current folder:
./README.md
./changes/2022-02-14_203436.080337/unchanged
./changes/2022-02-14_203436.080337/changing
./changes/2022-02-14_203436.080337/unpredictable_23432
./changes/2022-02-15_102709.324331/changing
./changes/2022-02-15_102709.324331/unpredictable_9872
./work/unchanged
./work/changing
./work/unpredictable_234325
./work/unpredictable_9872
./last_changes -> ./changes/2022-02-15_102709.324331
The contents are, therefore:
README.mdis a small description of the deltaresult repositoryworkcontains the current working directory (with a hidden.gitrepository)changescontains directories for all the runs, each containing only changed or newly added files after a runlast_changesis a symlink always pointing to the latest changes directory
If repositories get too big, you may want to periodically:
- Remove old result folders in
changes - (dangerous) in
./work/, removing the.gitfolder and reinitializing withgit init
Installation
deltaresult requires Python 3.x >= 3.6.
Install from PyPI:
$ pip install deltaresult
Usage
Command line
The command line can be used as-is to wrap around a program
usage: deltaresult [-h] -e EXEC [-a ARG] -d DIR [-t TITLE]
Tracks changes for multiple script runs with similar results
optional arguments:
-h, --help show this help message and exit
-e EXEC, --exec EXEC the command to execute
-a ARG, --arg ARG argument to the command to execute (can be repeated)
-d DIR, --dir DIR main directory
-t TITLE, --title TITLE
the program title
Example run calling a simple bash script:
$ deltaresult --dir=/tmp/xxx --exec=/bin/bash --arg=-c --arg="echo static>unchanged; echo \$RANDOM>changing; touch unpredictable_\$RANDOM;"
[ ] Creating new main directory "/tmp/xxx"
[ ] Creating work repository
[ ] Creating README.md
[I] Created result directory "/tmp/xxx/changes/2022-02-14_211637.064912"
[ ] Executing "['/bin/bash', '-c', 'echo static>unchanged; echo $RANDOM>changing; touch unpredictable_$RANDOM;']"...
[I] The command exited with error code 0
[ ] Copied changed file "changing" to result directory
[ ] Copied changed file "unchanged" to result directory
[ ] Copied changed file "unpredictable_32600" to result directory
$ deltaresult --dir=/tmp/xxx --exec=/bin/bash --arg=-c --arg="echo static>unchanged; echo \$RANDOM>changing; touch unpredictable_\$RANDOM;"
[I] Created result directory "/tmp/xxx/changes/2022-02-14_211657.390539"
[ ] Executing "['/bin/bash', '-c', 'echo static>unchanged; echo $RANDOM>changing; touch unpredictable_$RANDOM;']"...
[I] The command exited with error code 0
[ ] Copied changed file "changing" to result directory
[ ] Copied changed file "unpredictable_12510" to result directory
Python
Using this module with python is also straightforward:
from deltaresult import DeltaResultRepo
from random import randint
with DeltaResultRepo('/tmp/xxx', 'Example repo') as repo:
with open(repo.get_filename_in_work_directory('unchanged'), 'w') as f:
f.write('This file never changes.\n')
with open(repo.get_filename_in_work_directory('changing'), 'w') as f:
f.write('This file changes: %s.' % randint(0, 65536))
with open(repo.get_filename_in_work_directory('unpredictable_%s' % randint(0, 65536)), 'w') as f:
f.write('This file is new.\n')
with open(repo.get_filename_in_result_directory('run.log'), 'w') as f:
f.write('This is a log of the execution for the results directory.\n');
Metadata
Release files for deltaresult 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| deltaresult-0.0.1.tar.gz | 16.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deltaresult-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.2 kB
Release files / deltaresult-0.0.1.tar.gz
| Download URL | deltaresult-0.0.1.tar.gz |
|---|---|
| Size | 16.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7eb70294fa3ebfc071f1c7fe1869aa31292dbd1f2b8266bc9fa7bcec79db0118
|
|
BLAKE2b-256 checksum How to use checksums |
b2c3a919a1d7dba3fdd8ede732afff254ed7b5ce3db9c4c4a65879fc4ee638ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.3
|
Release files / deltaresult-0.0.1-py3-none-any.whl
| Download URL | deltaresult-0.0.1-py3-none-any.whl |
|---|---|
| Size | 19.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f42f197682f3167687521913f21aab99489a31cd89efe888f595b20364daea86
|
|
BLAKE2b-256 checksum How to use checksums |
3fe42e41de8db7e0b19410bbbf1d593d6ab63dbdf4bc90e9855af3044731afd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.3
|