监视文件变更

#!/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. PHP 开发社区微信服务号实战图解

    本博文就月初刚上线的微信服务号,图文进行总结分享给大家. 去年年底,我所在的团队讨论要开发微信号,话题由此拉开: 原来有一个3年前注册的微信号,但是后台操作无法从“订阅号”变更为“服务号”,随即找腾讯 ...

  2. android-sdks/build-tools/17.0.0/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

    fedora 23:dnf install zlib.i686 libstdc++.i686

  3. js不是从上到下执行的吗?

    如果说js是从上到下解释执行的, 那么,按道理应该会执行错误前面的代码. 如: [代码一] //输出1,2,到3报错 console.log("一") console.log(&q ...

  4. js时间函数

    时间 new Date() 获取时间,可以理解为是系统默认的函数. 从小括号里面获取系统时间日期,相当于在调用系统默认的函数. 年 getFullYear() 注意,有Full. 月 getMonth ...

  5. ASP.net知识点

    2 .列举ASP.NET 页面之间传递值的几种方式. 答: (1)QueryString是一种非常简单的传值方式,他可以将传送的值显示在浏览器的地址栏中. 如果是传递一个或多个安全性要求不高或是结构简 ...

  6. Atitit.软件开发提升稳定性总结

    Atitit.软件开发提升稳定性总结 #----影响稳定性几个类别 3 1. 资源和内存泄漏溢出 3 2. 数据库/文件死锁 3 3. 类库冲突 3 4. 热更新热部署(业务可用性 3 5. 程序崩溃 ...

  7. xib与nib的区别

    xib和nib都是Interface Builder的图形界面设计文档,nib这个名字来自于NeXTSTEP系统,在NeXTSTEP被Apple收购之前,一直使用nib作为Interface Buil ...

  8. IOS设计模式浅析之工厂方法模式(Factory Method)

    概述 在软件系统中,经常面临着“某个对象”的创建工作,由于需求的变化,这个对象的具体实现经常面临着剧烈的变化,但是它却拥有比较稳定的接口. 如何隔离出这个易变对象的变化,使得系统中“其它依赖该对象的对 ...

  9. 重新签名IPA ( iPhone )

    提示:暂时不能用了,企业证书滥用 ios 企业证书 ipa 重新签名发布 1. 应用场景 当前有一个 未用企业证书签名的 ipa 文件,默认是不可以直接安装到设备上的:我们需要用企业版证书签名: 当前 ...

  10. Android组件Spinner使用

    Spinner组件是Android当中非常常用的一种用于下拉选择的组件. 本blog当中主要解决的几个问题: 如何在XML中初始化Spinner选项 如何使用代码的方式初始化Spinner选项 一个A ...