Ejemplo n.º 1
0
    def __init__(self, eventTypes, pathMode, pathString, whitelist, blacklist,
                 ignoreSysFiles, ignoreDirEvents, proxy):
        """
            Set-up Monitor thread.
            
            After initialising the superclass and some instance variables
            try to create an FSEventStream. Throw an exeption if this fails.
            
            :Parameters:
                eventTypes : 
                    A list of the event types to be monitored.          
                    
                pathMode : 
                    The mode of directory monitoring: flat, recursive or following.

                pathString : string
                    A string representing a path to be monitored.
                  
                whitelist : list<string>
                    A list of files and extensions of interest.
                    
                blacklist : list<string>
                    A list of subdirectories to be excluded.

                ignoreSysFiles :
                    If true platform dependent sys files should be ignored.
                    
                monitorId :
                    Unique id for the monitor included in callbacks.
                    
                proxy :
                    A proxy to be informed of events
                    
        """
        AbstractPlatformMonitor.__init__(self, eventTypes, pathMode,
                                         pathString, whitelist, blacklist,
                                         ignoreSysFiles, ignoreDirEvents,
                                         proxy)
        self.log = logging.getLogger("fsserver." + __name__)

        recurse = False
        follow = False
        if self.pathMode == 'Follow':
            recurse = True
            follow = True
        elif self.pathMode == 'Recurse':
            recurse = True

        self.wm = MyWatchManager()
        self.notifier = pyinotify.ThreadedNotifier(
            self.wm,
            ProcessEvent(wm=self.wm,
                         cb=self.propagateEvents,
                         et=self.eTypes,
                         ignoreDirEvents=self.ignoreDirEvents))
        self.wm.addBaseWatch(self.pathsToMonitor, (pyinotify.ALL_EVENTS),
                             rec=recurse,
                             auto_add=follow)
        self.log.info('Monitor set-up on %s', str(self.pathsToMonitor))
        self.log.info('Monitoring %s events', str(self.eTypes))
Ejemplo n.º 2
0
    def __init__(self, eventTypes, pathMode, pathString, whitelist, blacklist, ignoreSysFiles, ignoreDirEvents, proxy):
        """
            Set-up Monitor thread.
            
            After initialising the superclass and some instance variables
            try to create an FSEventStream. Throw an exeption if this fails.
            
            :Parameters:
                eventTypes : 
                    A list of the event types to be monitored.          
                    
                pathMode : 
                    The mode of directory monitoring: flat, recursive or following.

                pathString : string
                    A string representing a path to be monitored.
                  
                whitelist : list<string>
                    A list of files and extensions of interest.
                    
                blacklist : list<string>
                    A list of subdirectories to be excluded.

                ignoreSysFiles :
                    If true platform dependent sys files should be ignored.
                    
                monitorId :
                    Unique id for the monitor included in callbacks.
                    
                proxy :
                    A proxy to be informed of events
                    
        """
        AbstractPlatformMonitor.__init__(
            self, eventTypes, pathMode, pathString, whitelist, blacklist, ignoreSysFiles, ignoreDirEvents, proxy
        )
        self.log = logging.getLogger("fsserver." + __name__)

        recurse = False
        follow = False
        if self.pathMode == "Follow":
            recurse = True
            follow = True
        elif self.pathMode == "Recurse":
            recurse = True

        self.wm = MyWatchManager()
        self.notifier = pyinotify.ThreadedNotifier(
            self.wm,
            ProcessEvent(wm=self.wm, cb=self.propagateEvents, et=self.eTypes, ignoreDirEvents=self.ignoreDirEvents),
        )
        self.wm.addBaseWatch(self.pathsToMonitor, (pyinotify.ALL_EVENTS), rec=recurse, auto_add=follow)
        self.log.info("Monitor set-up on %s", str(self.pathsToMonitor))
        self.log.info("Monitoring %s events", str(self.eTypes))
    def __init__(self, eventTypes, pathMode, pathString, whitelist, blacklist,
                 ignoreSysFiles, ignoreDirEvents, proxy):
        """
            Set-up Monitor thread.

            After initialising the superclass and some instance variables
            try to create an FSEventStream. Throw an exeption if this fails.

            :Parameters:
                eventTypes :
                    A list of the event types to be monitored.

                pathMode :
                    The mode of directory monitoring:
                    flat, recursive or following.

                pathString : string
                    A string representing a path to be monitored.

                whitelist : list<string>
                    A list of files and extensions of interest.

                blacklist : list<string>
                    A list of subdirectories to be excluded.

                ignoreSysFiles :
                    If true platform dependent sys files should be ignored.

                monitorId :
                    Unique id for the monitor included in callbacks.

                proxy :
                    A proxy to be informed of events
        """
        AbstractPlatformMonitor.__init__(self, eventTypes, pathMode,
                                         pathString, whitelist, blacklist,
                                         ignoreSysFiles, ignoreDirEvents,
                                         proxy)
        self.log = logging.getLogger("fsserver." + __name__)

        self.actions = {
            1: monitors.EventType.Create,  # Created
            2: monitors.EventType.Delete,  # Deleted
            3: monitors.EventType.Modify,  # Updated
            4: monitors.EventType.Modify,  # Renamed to something
            5: monitors.EventType.Modify  # Renamed from something
        }

        self.recurse = not (self.pathMode == "Flat")

        self.event = threading.Event()
        self.log.info('Monitor set-up on %s', str(self.pathsToMonitor))
        self.log.info('Monitoring %s events', str(self.eTypes))
    def __init__(self, eventTypes, pathMode, pathString, whitelist, blacklist,
                 ignoreSysFiles, ignoreDirEvents, proxy):
        """
            Set-up Monitor thread.

            After initialising the superclass and some instance variables
            try to create an FSEventStream. Throw an exeption if this fails.

            :Parameters:
                eventTypes :
                    A list of the event types to be monitored.

                pathMode :
                    The mode of directory monitoring:
                    flat, recursive or following.

                pathString : string
                    A string representing a path to be monitored.

                whitelist : list<string>
                    A list of files and extensions of interest.

                blacklist : list<string>
                    A list of subdirectories to be excluded.

                ignoreSysFiles :
                    If true platform dependent sys files should be ignored.

                monitorId :
                    Unique id for the monitor included in callbacks.

                proxy :
                    A proxy to be informed of events
        """
        AbstractPlatformMonitor.__init__(
            self, eventTypes, pathMode, pathString, whitelist, blacklist,
            ignoreSysFiles, ignoreDirEvents, proxy)
        self.log = logging.getLogger("fsserver." + __name__)

        self.actions = {
            1: monitors.EventType.Create,  # Created
            2: monitors.EventType.Delete,  # Deleted
            3: monitors.EventType.Modify,  # Updated
            4: monitors.EventType.Modify,  # Renamed to something
            5: monitors.EventType.Modify  # Renamed from something
        }

        self.recurse = not (self.pathMode == "Flat")

        self.event = threading.Event()
        self.log.info('Monitor set-up on %s', str(self.pathsToMonitor))
        self.log.info('Monitoring %s events', str(self.eTypes))
Ejemplo n.º 5
0
    def __init__(self, eventTypes, pathMode, pathString, whitelist, blacklist, ignoreSysFiles, ignoreDirEvents, proxy):
        """
            Set-up Monitor thread.
            
            After initialising the superclass and some instance variables
            try to create an FSEventStream. Throw an exeption if this fails.
            
            :Parameters:
                eventTypes : 
                    A list of the event types to be monitored.          
                    
                pathMode : 
                    The mode of directory monitoring: flat, recursive or following.

                pathString : string
                    A string representing a path to be monitored.
                  
                whitelist : list<string>
                    A list of files and extensions of interest.
                    
                blacklist : list<string>
                    A list of subdirectories to be excluded.

                ignoreSysFiles :
                    If true platform dependent sys files should be ignored.
                    
                monitorId :
                    Unique id for the monitor included in callbacks.
                    
                proxy :
                    A proxy to be informed of events
                    
        """
        AbstractPlatformMonitor.__init__(self, eventTypes, pathMode, pathString, whitelist, blacklist, ignoreSysFiles, ignoreDirEvents, proxy)
        self.log = logging.getLogger("fsserver."+__name__)
        
        #: an FSEvents.FSEventStream StreamRef object reference.
        self.streamRef = None
        #: FSEvents.CFRunLoop object reference.
        self.runLoopRef = None
        self.clientInfo = str(uuid.uuid1())
        #
        # Without using the mutable array, ie using the Python list directly, 
        # the code works but throws up a couple of horrible warnings:
        # "Oject of class OC_PythonArray autoreleased with no pool in place 
        #     - just leaking"
        # With the array there are still warnings about the strings whether 
        # Python native strings are used or NSStrings.
        #
        # All of these warnings are eliminated by using a pool for the lifetime 
        # of the NSMutableArray.
        #
        pool = NSAutoreleasePool.alloc().init()
        pathsToMonitor = NSMutableArray.alloc().init()
        ms = NSString.stringWithString_(self.pathsToMonitor)
        pathsToMonitor.insertObject_atIndex_(ms, 0)

        self.directory = fsDirectory.Directory(pathString=self.pathsToMonitor, 
                                            whitelist=self.whitelist,
                                            pathMode=self.pathMode)

        self.streamRef = FSEvents.FSEventStreamCreate(FSEvents.kCFAllocatorDefault,
                                self.callback,
                                self.clientInfo,
                                pathsToMonitor,
                                FSEvents.kFSEventStreamEventIdSinceNow,
                                1,
                                FSEvents.kFSEventStreamCreateFlagWatchRoot)
 
        #
        # Release the pool now that the NSMutableArray has been used.
        #
        del pool
             
        if self.streamRef == None:
            raise Exception('Failed to create FSEvent Stream')
            
        self.log.info('Monitor set-up on %s', str(self.pathsToMonitor))
        self.log.info('Monitoring %s events', str(self.eTypes))