Python中使用Inotify监控文件实例
2015-02-14 00:00
916 查看
Inotify地址:访问
# -*- coding:utf-8 -*- import os import pyinotify from functions import * WATCH_PATH = '' #监控目录 if not WATCH_PATH: wlog('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.' % (WATCH_PATH)) else: wlog('Error','The watch path NOT exists, watching stop now: path=%s.' % (WATCH_PATH)) sys.exit() class OnIOHandler(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 auto_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)
相关文章推荐
- Python中使用Inotify监控文件实例
- 使用Python监控文件内容变化代码实例
- 使用Inotify 监控Linux 文件系统事件
- 使用 inotify 监控文件系统的活动
- 使用 inotify 监控文件系统的活动
- 使用inotify-tools监控网站文件变动情况
- 使用 inotify 监控文件系统的活动
- C 使用 Inotify 监控目录和文件
- 使用inotify-tools监控Linux下网站文件变动情况
- 使用 inotify 监控文件系统的活动
- Python中使用ConfigParser解析ini配置文件实例
- 使用 inotify 监控 Linux 文件系统事件
- linux下使用inotify实时监控文件变更,做完整性检查
- Linux下使用inotify监控文件动作
- 使用 inotify 监控 Linux 文件系统事件
- 如何监控Linux文件系统事件:inotify使用指南(1)
- 使用inotify-tools监控Linux下网站文件变动情况
- 使用 inotify 监控文件系统的活动
- python使用正则搜索字符串或文件中的浮点数代码实例
- linux下使用inotify监控文件变化