Beispiel #1
0
    def AddMonitor(self, path, obj, handleID=None):
        if handleID is None:
            handleID = len(list(self.handles.keys()))
        self.events.append(Event(handleID, path, 'exists'))
        if os.path.isdir(path):
            dirlist = os.listdir(path)
            for fname in dirlist:
                self.events.append(Event(handleID, fname, 'exists'))
            self.events.append(Event(handleID, path, 'endExist'))

        if obj is not None:
            self.handles[handleID] = obj
        return handleID
Beispiel #2
0
    def AddMonitor(self, path, obj, handleID=None):
        """add a monitor to path, installing a callback to obj.HandleEvent"""
        if handleID is None:
            handleID = len(list(self.handles.keys()))
        self.events.append(Event(handleID, path, 'exists'))
        if os.path.isdir(path):
            dirlist = os.listdir(path)
            for fname in dirlist:
                self.events.append(Event(handleID, fname, 'exists'))
            self.events.append(Event(handleID, path, 'endExist'))

        if obj != None:
            self.handles[handleID] = obj
        return handleID
Beispiel #3
0
    def AddMonitor(self, path, obj, handleID=None):
        """add a monitor to path, installing a callback to obj.HandleEvent"""
        if handleID is None:
            handleID = len(list(self.handles.keys()))
        mode = os.stat(path)[stat.ST_MODE]
        self.events.append(Event(handleID, path, 'exists'))
        if stat.S_ISDIR(mode):
            dirList = os.listdir(path)
            for includedFile in dirList:
                self.events.append(Event(handleID, includedFile, 'exists'))
            self.events.append(Event(handleID, path, 'endExist'))

        if obj != None:
            self.handles[handleID] = obj
        return handleID
Beispiel #4
0
    def process_default(self, ievent):
        """ Process all inotify events received.  This process a
        :class:`pyinotify._Event` object, creates a
        :class:`Bcfg2.Server.FileMonitor.Event` object from it, and
        adds that event to :attr:`events`.

        :param ievent: Event to be processed
        :type ievent: pyinotify._Event
        """
        action = ievent.maskname
        for amask, aname in self.action_map.items():
            if ievent.mask & amask:
                action = aname
                break
        else:
            # event action is not in the mask, and thus is not
            # something we care about
            self.debug_log("Ignoring event %s for %s" % (action,
                                                         ievent.pathname))
            return

        try:
            watch = self.watchmgr.watches[ievent.wd]
        except KeyError:
            self.logger.error("Error handling event %s for %s: "
                              "Watch %s not found" %
                              (action, ievent.pathname, ievent.wd))
            return
        # FAM-style file monitors return the full path to the parent
        # directory that is being watched, relative paths to anything
        # contained within the directory. since we can't use inotify
        # to watch files directly, we have to sort of guess at whether
        # this watch was actually added on a file (and thus is in
        # self.event_filter because we're filtering out other events
        # on the directory) or was added directly on a directory.
        if (watch.path == ievent.pathname or ievent.wd in self.event_filter):
            path = ievent.pathname
        else:
            # relative path
            path = os.path.basename(ievent.pathname)
        # figure out the handleID.  start with the path of the event;
        # that should catch events on files that are watched directly.
        # (we have to watch the directory that a file is in, so this
        # lets us handle events on different files in the same
        # directory -- and thus under the same watch -- with different
        # objects.)  If the path to the event doesn't have a handler,
        # use the path of the watch itself.
        handleID = ievent.pathname
        if handleID not in self.handles:
            handleID = watch.path
        evt = Event(handleID, path, action)

        if (ievent.wd not in self.event_filter or
            ievent.pathname in self.event_filter[ievent.wd]):
            self.events.append(evt)
Beispiel #5
0
    def process_default(self, ievent):
        action = ievent.maskname
        for amask, aname in self.action_map.items():
            if ievent.mask & amask:
                action = aname
                break
        try:
            watch = self.watchmgr.watches[ievent.wd]
        except KeyError:
            LOGGER.error("Error handling event for %s: Watch %s not found" %
                         (ievent.pathname, ievent.wd))
            return
        # FAM-style file monitors return the full path to the parent
        # directory that is being watched, relative paths to anything
        # contained within the directory. since we can't use inotify
        # to watch files directly, we have to sort of guess at whether
        # this watch was actually added on a file (and thus is in
        # self.event_filter because we're filtering out other events
        # on the directory) or was added directly on a directory.
        if (watch.path == ievent.pathname or ievent.wd in self.event_filter):
            path = ievent.pathname
        else:
            # relative path
            path = os.path.basename(ievent.pathname)
        # figure out the handleID.  start with the path of the event;
        # that should catch events on files that are watched directly.
        # (we have to watch the directory that a file is in, so this
        # lets us handle events on different files in the same
        # directory -- and thus under the same watch -- with different
        # objects.)  If the path to the event doesn't have a handler,
        # use the path of the watch itself.
        handleID = ievent.pathname
        if handleID not in self.handles:
            handleID = watch.path
        evt = Event(handleID, path, action)

        if (ievent.wd not in self.event_filter
                or ievent.pathname in self.event_filter[ievent.wd]):
            self.events.append(evt)
Beispiel #6
0
 def __init__(self, request_id, filename, code):
     Event.__init__(self, request_id, filename, code)
     if code in self.action_map:
         self.action = self.action_map[code]
Beispiel #7
0
 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]
Beispiel #8
0
 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]