INotify Address: Access
#-*-coding:utf-8-*-import OS import pyinotify from functions import * Watch_path = ' #监控目录 if not watch_path:w
Log (' Error ', "the Watch_path setting must be set.") Sys.exit () else:if os.path.exists (Watch_path): Wlog (' WATCH status ', ' Found WATCH. '% (path:path=%s)) E Lse:wlog (' Error ', ' The Watch path not exists, watching stop now:path=%s. '% (Watch_path)) Sys.exit () class Onioh Andler (pyinotify. processevent): Def process_in_create (Self, event): Wlog (' Action ', ' CREATE file:%s '% Os.path.join (event.path,event.
Name) def process_in_delete (Self, event): Wlog (' Action ', ' DELETE file:%s '% Os.path.join (event.path,event.name)) def process_in_modify (self, event): Wlog (' Action ', "MODIFY file:%s"% Os.path.join (event.path,event.name)) def au To_compile (Path = '. '): WM = Pyinotify. Watchmanager () mask = pyinotify. In_create | Pyinotify. In_delete | Pyinotify. In_modify notifier = pyinotify. Threadednotifier (WM, Oniohandler ()) notifier. Start () wm.add_watch (path, Mask,rec = True,auto_add = True) wlog (' Start watch ', ' Start monitoring%s '% path) while True:try:notifier.process_events () if Notifier.check_events (): Notifier.read_events () except
KeyboardInterrupt:notifier.stop () break if __name__ = = "__main__": Auto_compile (Watch_path)