Ejemplo n.º 1
0
    def _update(self):
        newObservedFolders = set(self.directories)
        if self.eventStreamRef is not None:
            if newObservedFolders == self.observedFolders:
                return
            FSEventStreamStop(self.eventStreamRef)
            FSEventStreamUnscheduleFromRunLoop(self.eventStreamRef,
                                               CFRunLoopGetCurrent(),
                                               kCFRunLoopDefaultMode)
            FSEventStreamInvalidate(self.eventStreamRef)

        self.observedFolders = newObservedFolders
        if not newObservedFolders:
            self.eventStreamRef = None
            return

        self.eventStreamRef = FSEventStreamCreate(None,
                                                  self._fsEventCallback,
                                                  None,
                                                  list(newObservedFolders),
                                                  kFSEventStreamEventIdSinceNow,
                                                  self.latency,
                                                  kFSEventStreamCreateFlagNone)
        FSEventStreamScheduleWithRunLoop(self.eventStreamRef,
                                         CFRunLoopGetCurrent(),
                                         kCFRunLoopDefaultMode)
        FSEventStreamStart(self.eventStreamRef)
Ejemplo n.º 2
0
    def __remove_dir(self, path):
        """override of FSMonitor.__remove_dir()"""
        if path in self.monitored_paths.keys():
            streamRef = self.monitored_paths[path].fsmonitor_ref
            # Stop, unschedule, invalidate and release the stream refs.
            FSEventStreamStop(streamRef)
            # We don't use FSEventStreamUnscheduleFromRunLoop prior to
            # invalidating the stream, because invalidating the stream
            # automatically unschedules the stream from all run loops.
            FSEventStreamInvalidate(streamRef)
            FSEventStreamRelease(streamRef)

            del self.monitored_paths[path]
Ejemplo n.º 3
0
 def run(self):
     pool = AppKit.NSAutoreleasePool.alloc().init()
     self._run_loop = CFRunLoopGetCurrent()
     FSEventStreamScheduleWithRunLoop(self._stream_ref, self._run_loop,
                                      kCFRunLoopDefaultMode)
     if not FSEventStreamStart(self._stream_ref):
         FSEventStreamInvalidate(self._stream_ref)
         FSEventStreamRelease(self._stream_ref)
         raise IOError('FSEvents. Could not start stream.')
     CFRunLoopRun()
     FSEventStreamStop(self._stream_ref)
     FSEventStreamInvalidate(self._stream_ref)
     FSEventStreamRelease(self._stream_ref)
     del pool
     self._queue.put(None)