diff options
Diffstat (limited to 'src/lib/Bcfg2/Server/FileMonitor')
-rw-r--r-- | src/lib/Bcfg2/Server/FileMonitor/Gamin.py | 24 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/FileMonitor/Inotify.py | 4 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Gamin.py b/src/lib/Bcfg2/Server/FileMonitor/Gamin.py index 60f80c9c3..8a72fc0eb 100644 --- a/src/lib/Bcfg2/Server/FileMonitor/Gamin.py +++ b/src/lib/Bcfg2/Server/FileMonitor/Gamin.py @@ -9,6 +9,7 @@ from Bcfg2.Server.FileMonitor import Event, FileMonitor logger = logging.getLogger(__name__) + class GaminEvent(Event): """ This class provides an event analogous to @@ -23,13 +24,22 @@ class GaminEvent(Event): if code in self.action_map: self.action = self.action_map[code] + class Gamin(FileMonitor): __priority__ = 10 def __init__(self, ignore=None, debug=False): FileMonitor.__init__(self, ignore=ignore, debug=debug) - self.mon = WatchMonitor() + self.mon = None self.counter = 0 + self.add_q = [] + + def start(self): + FileMonitor.start(self) + self.mon = WatchMonitor() + for monitor in self.add_q: + self.AddMonitor(*monitor) + self.add_q = [] def fileno(self): return self.mon.get_fd() @@ -38,10 +48,16 @@ class Gamin(FileMonitor): """queue up the event for later handling""" self.events.append(GaminEvent(request_id, path, action)) - def AddMonitor(self, path, obj): + def AddMonitor(self, path, obj, handle=None): """Add a monitor to path, installing a callback to obj.""" - handle = self.counter - self.counter += 1 + if handle is None: + handle = self.counter + self.counter += 1 + + if not self.started: + self.add_q.append((path, obj, handle)) + return handle + mode = os.stat(path)[stat.ST_MODE] # Flush queued gamin events diff --git a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py index 60e26587e..6a8fd0201 100644 --- a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py +++ b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py @@ -3,7 +3,6 @@ import os import sys import logging -import operator import pyinotify from Bcfg2.Compat import reduce from Bcfg2.Server.FileMonitor import Event @@ -11,6 +10,7 @@ from Bcfg2.Server.FileMonitor.Pseudo import Pseudo logger = logging.getLogger(__name__) + class Inotify(Pseudo, pyinotify.ProcessEvent): __priority__ = 1 action_map = {pyinotify.IN_CREATE: 'created', @@ -22,6 +22,7 @@ class Inotify(Pseudo, pyinotify.ProcessEvent): def __init__(self, ignore=None, debug=False): Pseudo.__init__(self, ignore=ignore, debug=debug) + pyinotify.ProcessEvent(self) self.event_filter = dict() self.watches_by_path = dict() # these are created in start() after the server is done forking @@ -53,7 +54,6 @@ class Inotify(Pseudo, pyinotify.ProcessEvent): try: watch = self.wm.watches[ievent.wd] except KeyError: - err = sys.exc_info()[1] logger.error("Error handling event for %s: Watch %s not found" % (ievent.pathname, ievent.wd)) return |