summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-05-21 09:02:30 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-05-21 09:02:37 -0400
commitd78e0cc91947a06ae7687cb54f805787fb00d28f (patch)
tree2555001e52cada4f0dd3bb68163b178874eacddd /src/lib/Bcfg2/Server
parent661c5db322987b14178568325c71957451a3306e (diff)
downloadbcfg2-d78e0cc91947a06ae7687cb54f805787fb00d28f.tar.gz
bcfg2-d78e0cc91947a06ae7687cb54f805787fb00d28f.tar.bz2
bcfg2-d78e0cc91947a06ae7687cb54f805787fb00d28f.zip
fixed bug in pseudo fm, deduplicated code
Diffstat (limited to 'src/lib/Bcfg2/Server')
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/Inotify.py19
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/Pseudo.py17
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/__init__.py6
3 files changed, 16 insertions, 26 deletions
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
index 9743d868d..b87e10bd0 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
@@ -5,7 +5,8 @@ import stat
import logging
import operator
import pyinotify
-from Bcfg2.Server.FileMonitor import FileMonitor, Event
+from Bcfg2.Server.FileMonitor import Event
+from Bcfg2.Server.FileMonitor.Pseudo import Pseudo
logger = logging.getLogger(__name__)
@@ -20,12 +21,12 @@ class InotifyEvent(Event):
self.action = self.action_map[event.mask]
-class Inotify(FileMonitor, pyinotify.ProcessEvent):
+class Inotify(Pseudo, pyinotify.ProcessEvent):
__priority__ = 1
mask = pyinotify.IN_CREATE | pyinotify.IN_DELETE | pyinotify.IN_MODIFY
def __init__(self, ignore=None, debug=False):
- FileMonitor.__init__(self, ignore=ignore, debug=debug)
+ Pseudo.__init__(self, ignore=ignore, debug=debug)
self.wm = pyinotify.WatchManager()
self.notifier = pyinotify.ThreadedNotifier(self.wm, self)
self.notifier.start()
@@ -47,14 +48,10 @@ class Inotify(FileMonitor, pyinotify.ProcessEvent):
wd = watch.wd
else:
wd = res[path]
- self.handles[wd] = obj
- self.events.append(Event(wd, path, "exists"))
-
- mode = os.stat(path)[stat.ST_MODE]
- if stat.S_ISDIR(mode):
- for wname in os.listdir(path):
- self.events.append(Event(wd, wname, "exists"))
- return wd
+
+ # inotify doesn't produce initial 'exists' events, so we
+ # inherit from Pseudo to produce those
+ return Pseudo.AddMonitor(self, path, obj, handleID=wd)
def shutdown(self):
self.notifier.stop()
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Pseudo.py b/src/lib/Bcfg2/Server/FileMonitor/Pseudo.py
index 4c2d90250..baff871d0 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/Pseudo.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/Pseudo.py
@@ -10,21 +10,18 @@ logger = logging.getLogger(__name__)
class Pseudo(FileMonitor):
__priority__ = 99
- def AddMonitor(self, path, obj):
+ def AddMonitor(self, path, obj, handleID=None):
"""add a monitor to path, installing a callback to obj.HandleEvent"""
- handleID = len(list(self.handles.keys()))
+ if handleID is None:
+ handleID = len(list(self.handles.keys()))
mode = os.stat(path)[stat.ST_MODE]
- handle = Event(handleID, path, 'exists')
+ self.events.append(Event(handleID, path, 'exists'))
if stat.S_ISDIR(mode):
dirList = os.listdir(path)
- self.pending_events.append(handle)
for includedFile in dirList:
- self.pending_events.append(Event(handleID,
- includedFile,
- 'exists'))
- self.pending_events.append(Event(handleID, path, 'endExist'))
- else:
- self.pending_events.append(Event(handleID, path, 'exists'))
+ self.events.append(Event(handleID, includedFile, 'exists'))
+ self.events.append(Event(handleID, path, 'endExist'))
+
if obj != None:
self.handles[handleID] = obj
return handleID
diff --git a/src/lib/Bcfg2/Server/FileMonitor/__init__.py b/src/lib/Bcfg2/Server/FileMonitor/__init__.py
index 40c3253b9..7b61c5bb9 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/__init__.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/__init__.py
@@ -41,11 +41,7 @@ class FileMonitor(object):
return "%s: %s" % (__name__, self.__class__.__name__)
def __repr__(self):
- if self.pending():
- events = "has"
- else:
- events = "no"
- return "%s (%s events, fd %s)" % (str(self), events, self.fileno)
+ return "%s (%s events, fd %s)" % (str(self), len(events), self.fileno)
def should_ignore(self, event):
for pattern in self.ignore: