首页 > 其他 > 详细

pyinotify 的简单实用

时间:2021-01-26 15:35:29      阅读:3      评论:0      收藏:0      [点我收藏+]
import os
import datetime
import pyinotify
import logging

set_ = set()
class MyEventHandler(pyinotify.ProcessEvent):

    def process_IN_CLOSE_WRITE(self, event):
        if "/tmp/pycharm_project_741" != event.pathname and not event.pathname.split(‘/tmp/pycharm_project_741/‘)[1].startswith(‘.‘):
            set_.add(event.pathname)
        print("close:  ",set_)

    def process_IN_CREATE(self, event):
        print("startswith: ", event.pathname.split(‘/tmp/pycharm_project_741/‘)[1])
        # if "/tmp/pycharm_project_741" != event.pathname and not event.pathname.split(‘/tmp/pycharm_project_741/‘)[1].startswith(‘.‘):
        #     set_.add(event.pathname)
        # print("CREATE event:", event.pathname)

    # def process_IN_MODIFY(self, event):
    #     #被修改
    #     print("MODIFY event:", event.pathname)

    def process_IN_OPEN(self, event):
        pass
        # if "/tmp/pycharm_project_741" != event.pathname and not event.pathname.split(‘/tmp/pycharm_project_741/‘)[1].startswith(‘.‘):
        #     set_.add(event.pathname)
        # print("OPEN event:", event.pathname)


def main():
    # watch manager
    wm = pyinotify.WatchManager()
    wm.add_watch(‘/tmp/pycharm_project_741/‘, pyinotify.ALL_EVENTS, rec=True)
    # /tmp是可以自己修改的监控的目录
    # event handler
    eh = MyEventHandler()

    # notifier
    notifier = pyinotify.Notifier(wm, eh)
    notifier.loop()


if __name__ == ‘__main__‘:
    main()

pyinotify 的简单实用

原文:https://www.cnblogs.com/lgw1171435560/p/14329730.html

(0)
(0)
   
举报
评论 一句话评论(0
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号