From 6ec4573ccd6f67234b81a8aa9a6dc1ca024a21d6 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Fri, 15 May 2009 01:36:46 +0000 Subject: Fix fam tracebacks for Ticket #650 Signed-off-by: Sol Jerome git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5234 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/FileMonitor.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/lib/Server/FileMonitor.py') diff --git a/src/lib/Server/FileMonitor.py b/src/lib/Server/FileMonitor.py index b8947f8f1..30e6d4d82 100644 --- a/src/lib/Server/FileMonitor.py +++ b/src/lib/Server/FileMonitor.py @@ -1,5 +1,7 @@ +import logging +import os +import stat from time import sleep, time -import logging, os, stat logger = logging.getLogger('Bcfg2.Server.FileMonitor') @@ -26,11 +28,20 @@ class Event(object): class GaminEvent(Event): - '''This class provides an event analogous to python-fam events based on gamin sources''' + ''' + This class provides an event analogous to + python-fam events based on gamin sources + ''' def __init__(self, request_id, filename, code): Event.__init__(self, request_id, filename, code) - action_map = {GAMCreated: 'created', GAMExists: 'exists', GAMChanged: 'changed', - GAMDeleted: 'deleted', GAMEndExist: 'endExist', GAMMoved: 'moved'} + action_map = {} + if 'fam' not in available and 'gamin' not in available: + pass + else: + # Only works if Gamin or Fam is present + action_map = {GAMCreated: 'created', GAMExists: 'exists', + GAMChanged: 'changed', GAMDeleted: 'deleted', + GAMEndExist: 'endExist', GAMMoved: 'moved'} if code in action_map: self.action = action_map[code] @@ -89,7 +100,10 @@ class FileMonitor(object): sleep(0.5) class Fam(FileMonitor): - '''The fam object is a set of callbacks for file alteration events (FAM support)''' + ''' + The fam object is a set of callbacks for + file alteration events (FAM support) + ''' def __init__(self, debug=False): FileMonitor.__init__(self, debug) @@ -116,7 +130,10 @@ class Fam(FileMonitor): return self.fm.nextEvent() class Gamin(FileMonitor): - '''The fam object is a set of callbacks for file alteration events (Gamin support)''' + ''' + The fam object is a set of callbacks for + file alteration events (Gamin support) + ''' def __init__(self, debug=False): FileMonitor.__init__(self, debug) self.mon = WatchMonitor() @@ -150,7 +167,10 @@ class Gamin(FileMonitor): return self.events.pop() class Pseudo(FileMonitor): - '''The fam object is a set of callbacks for file alteration events (FAM support)''' + ''' + The fam object is a set of callbacks for + file alteration events (static monitor support) + ''' def __init__(self, debug=False): FileMonitor.__init__(self, debug=False) @@ -179,7 +199,7 @@ class Pseudo(FileMonitor): self.handles[handleID] = obj return handleID - + available = {} try: from gamin import WatchMonitor, GAMCreated, GAMExists, GAMEndExist, GAMChanged, GAMDeleted, GAMMoved @@ -191,7 +211,7 @@ try: import _fam available['fam'] = Fam except ImportError: - pass + print("Gamin or Fam not found. Loading Pseudo FileMonitor.") available['pseudo'] = Pseudo for fdrv in ['gamin', 'fam', 'pseudo']: -- cgit v1.2.3-1-g7c22