监视文件变更

#!/usr/bin/python
# -*- coding:UTF-8 -*- import time
from watchdog.observers import Observer
from watchdog.events import RegexMatchingEventHandler class MyHandler(RegexMatchingEventHandler): def __init__(self, regex_list=[r".*"]):
super(MyHandler, self).__init__(regex_list) def on_created(self, event):
if event.is_directory:
pass
else:
print(event.event_type, event.src_path) def on_deleted(self, event):
if event.is_directory:
pass
else:
print(event.event_type, event.src_path) def on_modified(self, event):
if event.is_directory:
pass
else:
print(event.event_type, event.src_path) def on_moved(self, event):
print("move", event.src_path, event.dest_path) if __name__ == "__main__":
reges = [r".*\.c", r".*\.h", r".*\.cpp"]
event_handler = MyHandler(reges)
observer = Observer()
observer.schedule(event_handler, ".", recursive=True)
observer.start() try:
print("start my watch")
while True:
time.sleep(100)
except KeyboardInterrupt:
observer.stop()
observer.join()

读取配置文件

# -*- coding: utf-8

from configparser import ConfigParser

def get_config(section_name="env", conf_file="ssh-config.ini"):
'''
:param section_name:
:param conf_file:
:return dictornary: eg.
[env]
user = root
password = root123 return {"user":"root", "password":"root123"}
'''
config = ConfigParser()
config.read_file(open(conf_file))
return dict(config.items(section_name)) for k, v in get_config().items():
print(k, ":", v)

python watchdog的更多相关文章

  1. 使用七牛云存储----大家自己的图床[python]

    ##写博客什么的总得贴图吧,图床选来选去还是七牛吧.嗯,就是你了 [OSchaina 源码] 结合FastStone Capture 简直爽歪歪. FastStone Capture 自动保存图片到文 ...

  2. HyperLedger Cello学习笔记

    HyperLedger Cello学习笔记 转载请注明出处:HyperLedger Cello学习笔记 概述 Hyperledger Cello是Hyperledger下的一个子项目,其主要功能如下: ...

  3. python中文件变化监控-watchdog

    在python中文件监控主要有两个库,一个是pyinotify ( https://github.com/seb-m/pyinotify/wiki ),一个是watchdog(http://pytho ...

  4. Python监控文件变化:watchdog

    Python监控文件变化有两种库:pyinotify和watchdog.pyinotify依赖于Linux平台的inotify,后者则对不同平台的的事件都进行了封装.也就是说,watchdog跨平台. ...

  5. Python 配置文件加载且自动更新(watchdog)

    安装依赖:pip install watchdog #!/usr/bin/env python3 # -*- coding: utf-8 -*- import logging import os im ...

  6. Python 资源大全中文版

    Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-python 是 vinta 发起维护的 Python 资源列 ...

  7. Windows API Hooking in Python

    catalogue . 相关基础知识 . Deviare API Hook Overview . 使用ctypes调用Windows API . pydbg . winappdbg . dll inj ...

  8. python os.path

    os.path 提供了一些处理文件路径的函数. os.path.abspath(path) 返回绝对路径, 在大多数平台上, os.path.abspath(path) == os.path.norm ...

  9. [转载]Python 资源大全

    原文链接:Python 资源大全 环境管理 管理 Python 版本和环境的工具 p – 非常简单的交互式 python 版本管理工具. pyenv – 简单的 Python 版本管理工具. Vex  ...

随机推荐

  1. SpringMVC从一个controller跳转到另一个controller

    return "redirect:……路径……"; @RequestMapping(value = "/index", method = RequestMeth ...

  2. 插件~使用ECharts动态在地图上标识点~动态添加和删除标识点

    之前写过一个Echarts的文章,没有基础的同学可以先看这<上一篇>,对于一个地图和说,我们在初始化之后,你可能被在地图上标识出一些点,当然这根据你的业务去标识,而如果每次更新数据都加载全 ...

  3. SourceTree - 正在检查源... When cloning a repository, "Checking Source" spins forever

    I am trying to clone a repository, my OpenSSH is set up correctly and I can do everything fine in Gi ...

  4. cygintl-8.dll 是cygwin的哪个包?|Windows查看man手册的方法-cygwin

    答案是: 是 Release\gettext\libintl8\libintl8-0.18.1.1-2.tar.bz2 应该是gettext 项目的一部分吧. 下载地址 可以直接从 cygwin的镜像 ...

  5. CentOS7安装mysql数据库

    安装完Centos7,迫不急待的想安装mysql数据库,却没想到走了很多弯路,后来经过查资料,才知道了在Centos7中用MariaDB代替了mysql数据库. 准确来说,本文的标题有点误导的意思,本 ...

  6. DRAM 内存介绍(二)

    参考资料:http://www.anandtech.com/show/3851/everything-you-always-wanted-to-know-about-sdram-memory-but- ...

  7. RPC 135端口

  8. 一次完整的HTTP事务分析

    在浏览器中输入一个地址,按下回车之后,到用户看到页面之前,发生了什么? https://www.processon.com/view/link/56c6679ce4b0f0c4285e69c0

  9. 菜鸟学JS(四)——javascript为按钮注册回车事件(设置默认按钮)

    不得不说,在JS方面,自己真的是个不折不扣的菜鸟.对于JS以及一些JS框架如JQuery等JS框架,自己也只是处在简单应用的阶段,当然自己也在不断的学习当中,希望将来能跟大家分享更多JS方面的心得.今 ...

  10. c语言二叉树

    Department of Computing and Information SystemsCOMP10002 Foundations of AlgorithmsSemester 2, 2014As ...