zoukankan      html  css  js  c++  java
  • pyinotify 的简单实用

    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()
    
    
  • 相关阅读:
    二十七、正则表达式补充
    二十六、python中json学习
    二十五、python中pickle序列学习(仅python语言中有)
    MongoDB系列
    产品经理思考
    摩拜数据产品
    龙珠直播之swot
    ahp层次分析法软件
    用户画像之门店用户类型的体系
    汽车后市场SWOT分析
  • 原文地址:https://www.cnblogs.com/lgw1171435560/p/14329730.html
Copyright © 2011-2022 走看看