joh/when-changed — pull request #21 by cwaldbieser (2014-09-05 00:52:10+00:00)
Title: Added argument parsing with `argparse` if available; extra args to refine notification

Added argument parsing with `argparse` if available; extra args to refine notification.

When using argparse, there is only one syntax. If you do not supply a command with '-c', the program prints the file name to STDOUT.
If you do supply a command, it can either be the last option and end with '--' OR if can simply be placed at the end of the command line. E.g. the following are equivalent:

$ ./when-changed -r -c ls -l %f -- /path/to/dir1 /path/to/dir2
$ ./when-changed -r /path/to/dir1 /path/to/dir2 -c ls -l %f

Added options to *only* notify on mods or renames (rather than both). You can choose to run the command *only* on file renames or *only* on file modifications.

I am using the `--renames-only` flag in a script I am writing to monitor a file system with a very specific permission structure. The file system makes use of the setGid bit to force the owning group for new files and folders. This works great, until a `mv` command or equivalent causes a file to change folders. I track the renamed files and process them in short batches via a second script that updates permissions. In this case, I am only really interested in when a file is moved-- not when its contents have been changed.

If `argparse` is not available, fall back to the original command line processing. (`argparse` is available for Python v2.6 via PyPi, or you can just copy `argparse.py` out of the tarball and put it in the same directory as this script).