我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用pyinotify.IN_DELETE。
def start(self): for f in os.listdir(self.path): name = file2mod(f) if not name: continue self._load(name) wm = pyinotify.WatchManager() wm.add_watch(self.path, pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY , rec = False) handle = EventHandler(self) self._notifier = pyinotify.TornadoAsyncNotifier( wm, self._ioloop, default_proc_fun = handle)
def __init__(self, rt): ManagerPlugin.__init__(self, rt) self.git_repo = GitRepo(directory=self.rt.paths.skills, url='https://github.com/MatthewScholefield/mycroft-light.git', branch='skills', update_freq=1) self.blacklist = self.config['blacklist'] sys.path.append(self.rt.paths.skills) GroupPlugin.__init__(self, SkillPlugin, 'mycroft.skills', '_skill') for cls in self._classes.values(): cls.rt = rt self.init_plugins() # The watch manager stores the watches and provides operations on watches wm = pyinotify.WatchManager() mask = pyinotify.IN_MODIFY | pyinotify.IN_CREATE | pyinotify.IN_DELETE | pyinotify.IN_MOVED_TO skills_dir = self.rt.paths.skills handler = EventHandler(self) notifier = pyinotify.ThreadedNotifier(wm, handler) notifier.daemon = True wdd = wm.add_watch(skills_dir, mask, rec=True) notifier.start()
def file_monitor(path='.', client=None): wm = WatchManager() mask = IN_DELETE | IN_CREATE | IN_MODIFY notifier = AsyncNotifier(wm, EventHandler(client)) wm.add_watch(path, mask, auto_add=True, rec=True) if not os.path.isfile(path): logger.debug("File %s does not exist." % path) sys.exit(3) else: logger.debug("Now starting monitor file %s." % path) global f f = open(path, 'r') st_size = os.stat(path)[6] f.seek(st_size) while True: try: notifier.process_events() if notifier.check_events(): notifier.read_events() except KeyboardInterrupt: print "keyboard Interrupt." notifier.stop() break
def run(self): self.running = True wm = pyinotify.WatchManager() notifier = pyinotify.Notifier(wm) def inotify_callback(event): if event.mask == pyinotify.IN_CLOSE_WRITE: self.populate_app(event.pathname) elif event.mask == pyinotify.IN_DELETE: with self.lock: for cmd, data in self.apps.items(): if data[2] == event.pathname: del self.apps[cmd] break for p in DESKTOP_PATHS: if os.path.exists(p): wm.add_watch(p, pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE, inotify_callback) notifier.loop()
def wait_pyinotify(self, bld): class PE(w_pyinotify.ProcessEvent): def stop(self, event): self.notif.ev = True self.notif.stop() raise ValueError("stop for delete") process_IN_DELETE = stop process_IN_CLOSE = stop process_default = stop proc = PE() wm = w_pyinotify.WatchManager() notif = w_pyinotify.Notifier(wm, proc) proc.notif = notif # well, we should add all the folders to watch here for x in self.enumerate(bld.srcnode): wm.add_watch(x, w_pyinotify.IN_DELETE | w_pyinotify.IN_CLOSE_WRITE) try: # pyinotify uses an infinite loop ... not too nice, so we have to use an exception notif.loop() except ValueError: pass if not hasattr(notif, 'ev'): raise KeyboardInterrupt
def addMonitor( self, filename, callback, args = None ): try: mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY mId = self.wm.add_watch( filename, mask, rec = True)[filename] if mId >= 0: self.callbacks[mId] = ( callback, args ) except Exception as detail: mId = 0 return mId
def addMonitor( self, filename, callback, args = None ): try: mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY mId = self.wm.add_watch( filename, mask, rec = True)[filename] if mId >= 0: self.callbacks[mId] = ( callback, args ) except Exception, detail: mId = 0 return mId
def inotify_code_changed(): """ Checks for changed code using inotify. After being called it blocks until a change event has been fired. """ class EventHandler(pyinotify.ProcessEvent): modified_code = None def process_default(self, event): if event.path.endswith('.mo'): EventHandler.modified_code = I18N_MODIFIED else: EventHandler.modified_code = FILE_MODIFIED wm = pyinotify.WatchManager() notifier = pyinotify.Notifier(wm, EventHandler()) def update_watch(sender=None, **kwargs): if sender and getattr(sender, 'handles_files', False): # No need to update watches when request serves files. # (sender is supposed to be a django.core.handlers.BaseHandler subclass) return mask = ( pyinotify.IN_MODIFY | pyinotify.IN_DELETE | pyinotify.IN_ATTRIB | pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO | pyinotify.IN_CREATE | pyinotify.IN_DELETE_SELF | pyinotify.IN_MOVE_SELF ) for path in gen_filenames(only_new=True): wm.add_watch(path, mask) # New modules may get imported when a request is processed. request_finished.connect(update_watch) # Block until an event happens. update_watch() notifier.check_events(timeout=None) notifier.read_events() notifier.process_events() notifier.stop() # If we are here the code must have changed. return EventHandler.modified_code
def inotify_code_changed(): """ Checks for changed code using inotify. After being called it blocks until a change event has been fired. """ class EventHandler(pyinotify.ProcessEvent): modified_code = None def process_default(self, event): if event.path.endswith('.mo'): EventHandler.modified_code = I18N_MODIFIED else: EventHandler.modified_code = FILE_MODIFIED wm = pyinotify.WatchManager() notifier = pyinotify.Notifier(wm, EventHandler()) def update_watch(sender=None, **kwargs): if sender and getattr(sender, 'handles_files', False): # No need to update watches when request serves files. # (sender is supposed to be a django.core.handlers.BaseHandler subclass) return mask = ( pyinotify.IN_MODIFY | pyinotify.IN_DELETE | pyinotify.IN_ATTRIB | pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO | pyinotify.IN_CREATE ) for path in gen_filenames(only_new=True): wm.add_watch(path, mask) # New modules may get imported when a request is processed. request_finished.connect(update_watch) # Block until an event happens. update_watch() notifier.check_events(timeout=None) notifier.read_events() notifier.process_events() notifier.stop() # If we are here the code must have changed. return EventHandler.modified_code