Skip to main content

Tracks changes for multiple script runs with similar results

Project description

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.md is a small description of the deltaresult repository
  • work contains the current working directory (with a hidden .git repository)
  • changes contains directories for all the runs, each containing only changed or newly added files after a run
  • last_changes is 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 .git folder and reinitializing with git 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');

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

deltaresult-0.0.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

deltaresult-0.0.1-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file deltaresult-0.0.1.tar.gz.

File metadata

  • Download URL: deltaresult-0.0.1.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for deltaresult-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7eb70294fa3ebfc071f1c7fe1869aa31292dbd1f2b8266bc9fa7bcec79db0118
MD5 80960e44e425bc74f0525cce19b402a8
BLAKE2b-256 b2c3a919a1d7dba3fdd8ede732afff254ed7b5ce3db9c4c4a65879fc4ee638ea

See more details on using hashes here.

File details

Details for the file deltaresult-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: deltaresult-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for deltaresult-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f42f197682f3167687521913f21aab99489a31cd89efe888f595b20364daea86
MD5 8dd70578720375625827c51518b82cf1
BLAKE2b-256 3fe42e41de8db7e0b19410bbbf1d593d6ab63dbdf4bc90e9855af3044731afd2

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