python watchdog
监视文件变更
#!/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的更多相关文章
- 使用七牛云存储----大家自己的图床[python]
##写博客什么的总得贴图吧,图床选来选去还是七牛吧.嗯,就是你了 [OSchaina 源码] 结合FastStone Capture 简直爽歪歪. FastStone Capture 自动保存图片到文 ...
- HyperLedger Cello学习笔记
HyperLedger Cello学习笔记 转载请注明出处:HyperLedger Cello学习笔记 概述 Hyperledger Cello是Hyperledger下的一个子项目,其主要功能如下: ...
- python中文件变化监控-watchdog
在python中文件监控主要有两个库,一个是pyinotify ( https://github.com/seb-m/pyinotify/wiki ),一个是watchdog(http://pytho ...
- Python监控文件变化:watchdog
Python监控文件变化有两种库:pyinotify和watchdog.pyinotify依赖于Linux平台的inotify,后者则对不同平台的的事件都进行了封装.也就是说,watchdog跨平台. ...
- Python 配置文件加载且自动更新(watchdog)
安装依赖:pip install watchdog #!/usr/bin/env python3 # -*- coding: utf-8 -*- import logging import os im ...
- Python 资源大全中文版
Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-python 是 vinta 发起维护的 Python 资源列 ...
- Windows API Hooking in Python
catalogue . 相关基础知识 . Deviare API Hook Overview . 使用ctypes调用Windows API . pydbg . winappdbg . dll inj ...
- python os.path
os.path 提供了一些处理文件路径的函数. os.path.abspath(path) 返回绝对路径, 在大多数平台上, os.path.abspath(path) == os.path.norm ...
- [转载]Python 资源大全
原文链接:Python 资源大全 环境管理 管理 Python 版本和环境的工具 p – 非常简单的交互式 python 版本管理工具. pyenv – 简单的 Python 版本管理工具. Vex ...
随机推荐
- 搭建wamp环境,数据库基础知识
服务器管理软件php Apache.net IISjava Tomcat 服务器管理软件起到的作用:管理服务器工作,具体的工作如下:1.静态页面用户将请求发送到服务器,服务器中的服务器管理软件将请求发 ...
- iOS开发——高级技术&蓝牙服务
蓝牙服务 蓝牙 随着蓝牙低功耗技术BLE(Bluetooth Low Energy)的发展,蓝牙技术正在一步步成熟,如今的大部分移动设备都配备有蓝牙4.0,相比之前的蓝牙技术耗电量大大降低.从iOS的 ...
- hdu 2191 多重背包 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
http://acm.hdu.edu.cn/showproblem.php?pid=2191 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...
- MongoDB学习笔记——索引管理
索引 索引能够提升查询的效率.没有索引,MongoDB必须扫描集合中的所有文档,才能找到匹配查询语句的文档. 索引是一种特殊的数据结构,将一小块数据集保存为容易遍历的形式.索引能够存储某种特殊字段或字 ...
- Java中Atomic包的实现原理及应用
1. 同步问题的提出 假设我们使用一个双核处理器执行A和B两个线程,核1执行A线程,而核2执行B线程,这两个线程现在都要对名为obj的对象的成员变量i进行加1操作,假设i的初始值为0,理论上两个线程运 ...
- Node.js的颠覆者:PHP的Swoole扩展
最近2年Node.js很火,异步与协程是网络开发方面热门的话题.在追求新技术的同时,也应该反思下这里面存在的陷阱.Node.js确实是一门有趣好玩有个性的语言和技术,动态性,全异步回调的方 ...
- 取代奶瓶Minidwep-gtk破解WPA 全攻略
取代奶瓶Minidwep-gtk 破 WPA 全攻略 目录 1. CDlinux 下使用 minidwepgtk 获取握手包并使用自带的字典破解 2. 自带的字典破解不出密码时使用 U 盘外挂字典继 ...
- android实现qq邮箱多个图标效果
前几天,蛋疼的技术主管非要实现类似装一个qq邮箱,然后能够使用qq邮箱日历的那么一个东西.相当于一个应用生成两个图标,可是不同的是点击不同的图标能够进入不同的应用,例如以下图的效果. 这效果百度了一天 ...
- SK-Learn使用NMF(非负矩阵分解)和LDA(隐含狄利克雷分布)进行话题抽取
英文链接:http://scikit-learn.org/stable/auto_examples/applications/topics_extraction_with_nmf_lda.html 这 ...
- 关于MYSQL中like 检索汉字问题。
mysql中like’中国‘查询不出来结果 如果 like‘zg’就看查询出来结果. 查询了半天是由于mysql中编码的原因 解决办法: 进入mysql 输入命令:show variables lik ...