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()
Question
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.
La solution
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()
Autres conseils
I've come up with a solution by making a class that mimics watchdog.utils.dirsnapshot.DirectorySnapshot
, returning empty values where appropriate.
class EmptyDirectorySnapshot(object):
"""
For use as the zeroth snapshot in a chain of DirectorySnapshotDiffs
"""
@property
def stat_snapshot(self):
return {}
def stat_info(self, path):
return None
@property
def paths(self):
return set()
The two properties stat_snapshot
and paths
, as well as the method stat_info
given above are used in the diffing function. This works fairly well and yields intended results. Hurrah.