~hdlorean-watcher/hdlorean/watcher

« back to all changes in this revision

Viewing changes to src/hdloreand/watcher/Watcher.py

  • Committer: Jorge Quintas Rodriguez
  • Date: 2008-04-09 11:01:16 UTC
  • Revision ID: jotum@jotum-laptop-20080409110116-iuwyio8xv2f50xru
fixed addition to watched. TODO fix remove

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
        __snapshotManager = None
66
66
        #ugly thing
67
67
        __lastPath = ''
 
68
        #flag indicating the status of the notifier running/stopped
 
69
        __isRunning = False
68
70
        #__srLock = None
69
71
        #__bniLock = None
70
72
 
93
95
                self.backupNewItems(self.__watched)
94
96
                self.__pyinotifyHandler = PyinotifyHandler(self,self.__watched,self.__pblacklist,self.__whitelist,self.__reBlacklist,parents)
95
97
                self.__log.info('Succesfully initialized')
96
 
                try:
97
 
                        self.__pyinotifyHandler.startNotifier()
98
 
                except GlobalExceptions.NotifierRunning:
99
 
                        self.__log.warning('Notifier already running')
100
 
                self.__log.info('Started')
 
98
                if(self.__CFM.getEveryChange()):
 
99
                        try:
 
100
                                self.__pyinotifyHandler.startNotifier()
 
101
                        except GlobalExceptions.NotifierRunning:
 
102
                                self.__log.warning('Notifier already running')
 
103
                        self.__log.info('Started')
 
104
                        self.__isRunning = True
101
105
                #Creates the file with the env vars for the cron
102
106
                self.__cronHandler = CH.CronHandler(self)
103
107
                # Insert the task in the crontab if needed
280
284
                else:
281
285
                        result = result + [current]
282
286
                return result
283
 
 
284
 
 
 
287
        
285
288
        ##@brief Explore the dirtree finding files and dirs
286
289
        #
287
290
        # First, we obtain the content of the current directory, and for each directory, we use
380
383
                                self.__journal.insert(timestamp,sender,item,item,'0')
381
384
                #self.__srLock.release()
382
385
 
383
 
 
 
386
        
384
387
        ##@brief process changes in attributes
385
388
        #
386
389
        # @author Jorge
459
462
                self.__whitelist = self.__CFM.getWhiteList()
460
463
                self.__reBlacklist = self.__CFM.getPReBlackList()
461
464
                self.__watched = newWatched
 
465
                self.__log.debug('to add in watched '+ repr(toAddInWatched))
 
466
                self.__log.debug('to remove from watched' + repr(toRemoveFromWatched))
 
467
                print 'to remove from watched' + repr(toRemoveFromWatched)
 
468
                #self.__log.info()
462
469
                self.__pyinotifyHandler.updateWatched(self.__pblacklist,self.__whitelist,self.__reBlacklist,toAddInWatched,toRemoveFromWatched,toAddInParents,toRemoveFromParents)
 
470
                #start and stop notifier
 
471
                if(self.__CFM.getEveryChange()):
 
472
                        if not self.__isRunning:
 
473
                                #self.__pyinotifyHandler.start()
 
474
                                #self.__pyinotifyHandler.update(True)
 
475
                                self.__isRunning = True
 
476
                else:
 
477
                        if self.__isRunning:
 
478
                                #self.__pyinotifyHandler.stop()
 
479
                                #self.__pyinotifyHandler.update(False)
 
480
                                self.__isRunning = False
463
481
                # Make the first snapshot of all the items that have been added
464
482
                self.backupNewItems(toAddInWatched)
465
483
 
474
492
                        return True
475
493
                elif path in self.__pblacklist:
476
494
                        return True
477
 
                elif path.startswith(os.getenv("HOME")+"/.hdlorean"):
 
495
                elif path.startswith(os.getenv("HOME")+"/.hdlorean"): 
478
496
                        return True
479
497
                for item in self.__reBlacklist:
480
498
                        #check if an item of the pattern blacklist is a substring of the path of the event
481
 
                        if path.startswith(item+'/'):
 
499
                        if item != '' and path.startswith(item+'/'):
482
500
                                return True
483
501
                return blacklisted
484
502
 
485
503
 
486
 
        ### @brief Checks if there is any backup of the items received and, if necesary
 
504
        ## @brief Checks if there is any backup of the items received and, if necesary
487
505
        # insert the path in the journal so its first backup become acomplished.
488
506
        #
489
507
        # This function just calls the real one in a thread.