Watchdog is pretty awesome at letting you take recursive snapshots of a particular directory. It even lets you compare snapshots with a function called DirectorySnapshotDiff.
My program watches as a directory evolves in real-time, and thus has been made to consume the output of this function. This is very reasonable.
Let's say I take snapshots s1, s2...
of the file system at arbitrary times. We compare the last snapshot with the latest one to create difference objects.
d1 d2 # detected differences (my app eats these up)
s1 -> s2 -> s3 # evolving states (snapshots taken) of the file system.
t=0 -------------------> time
Omnomnomnom. That's great.
But, the first time I run my app, I need to know the current state. I want to pretend that there was a null state s0
, which transitions into s1
; thus I can diff format. i.e.
d0 # I want to create this 'bootstrapping' difference set
(s0) -> s1 # Assume s0 is the empty snapshot: it reports everything is an addition
How do I do that?
The motivation behind this is: I love functional programming. Instead of writing code to consume snapshots AND snapshot diffs (both considerable work) I like to keep reuse high and code minimal.
For versions of python >= 2.6 watchdog uses it's OrderedSet.
Modify fatuhoku's paths function as follows;
@property
def paths(self):
if sys.version_info >= (2, 6, 0):
return watchdog.utils.bricks.OrderedSet()
return set()