diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-05-23 13:03:06 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-05-23 13:03:06 -0400 |
commit | ac42b7261a36dbce4d212cf31feea99dd344e6b8 (patch) | |
tree | 4f2076508790760ed83d72ff2f734d69c2a77787 /src/lib/Bcfg2/Server | |
parent | 2d96ac9d2c6ebd07108d3b85745678598cf2e5ca (diff) | |
download | bcfg2-ac42b7261a36dbce4d212cf31feea99dd344e6b8.tar.gz bcfg2-ac42b7261a36dbce4d212cf31feea99dd344e6b8.tar.bz2 bcfg2-ac42b7261a36dbce4d212cf31feea99dd344e6b8.zip |
fixed inotify handling of events in watched dirs
Diffstat (limited to 'src/lib/Bcfg2/Server')
-rw-r--r-- | src/lib/Bcfg2/Server/FileMonitor/Inotify.py | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py index b87e10bd0..8dcca70c2 100644 --- a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py +++ b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py @@ -10,20 +10,12 @@ from Bcfg2.Server.FileMonitor.Pseudo import Pseudo logger = logging.getLogger(__name__) -class InotifyEvent(Event): - action_map = {pyinotify.IN_CREATE: 'created', - pyinotify.IN_DELETE: 'deleted', - pyinotify.IN_MODIFY: 'changed'} - - def __init__(self, event): - Event.__init__(self, event.wd, event.pathname, event.mask) - if event.mask in self.action_map: - self.action = self.action_map[event.mask] - - class Inotify(Pseudo, pyinotify.ProcessEvent): __priority__ = 1 mask = pyinotify.IN_CREATE | pyinotify.IN_DELETE | pyinotify.IN_MODIFY + action_map = {pyinotify.IN_CREATE: 'created', + pyinotify.IN_DELETE: 'deleted', + pyinotify.IN_MODIFY: 'changed'} def __init__(self, ignore=None, debug=False): Pseudo.__init__(self, ignore=ignore, debug=debug) @@ -34,8 +26,24 @@ class Inotify(Pseudo, pyinotify.ProcessEvent): def fileno(self): return self.wm.get_fd() - def process_default(self, event): - self.events.append(InotifyEvent(event)) + def process_default(self, ievent): + action = ievent.maskname + for amask, aname in self.action_map.items(): + if ievent.mask & amask: + action = aname + break + # FAM-style file monitors return the full path to the parent + # directory that is being watched, relative paths to anything + # contained within the directory + watch = self.wm.watches[ievent.wd] + if watch.path == ievent.pathname: + path = ievent.pathname + else: + # relative path + path = os.path.basename(ievent.pathname) + evt = Event(ievent.wd, path, action) + print "created event %s" % evt + self.events.append(evt) def AddMonitor(self, path, obj): res = self.wm.add_watch(path, self.mask, quiet=False) |