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 ...
随机推荐
- SpringMVC从一个controller跳转到另一个controller
return "redirect:……路径……"; @RequestMapping(value = "/index", method = RequestMeth ...
- Bootstrap中水平排列的表单form-inline
<html> <head> <title>初识Bootstrap</title> <meta charset="utf-8"& ...
- 关于C++单件模式释放对象
http://blog.csdn.net/windboyzsj/article/details/2790485 最近接触的一个项目要用到单件模式,我像往常一样哒哒(敲击键盘ing)一个单件模式的典型结 ...
- 《精通移动app测试实战:技术、工具和案例》新书上市
本书是测试专家.性能测试专家.专业畅销书作者--于涌,多年实战经验的总结,涵盖主流的测试工具,包括众多的测试实例,涵盖单元测试.功能测试.性能测试.UI测试.手游测试.自动化测试.测试用例管理.持续集 ...
- Android视觉规范-间距规范与文字规范单位换算(dip、sp与px)
http://blog.csdn.net/shimiso/article/details/29826073 1.dip与px Android工程师在写页面时,margin值的单位是dip,而视觉设计师 ...
- iptables防火墙原理详解
1. netfilter与iptables Netfilter是由Rusty Russell提出的Linux 2.4内核防火墙框架,该框架既简洁又灵活,可实现安全策略应用中的许多功能,如数据包过滤.数 ...
- ORACLE 监听日志文件太大停止写监听日志引起数据库连接不上问题
生产库监听日志文件太大(达到4G多),发现oracle停止写监听日志,检查参数log_file,log_directory,log_status 均正常,数据库运行也正常. 经确认确实为监听日志过大引 ...
- Django抛错不存在(DoesNotExist)
from django.core.exceptions import ObjectDoesNotExist try: disabledusers.objects.get(sAMAccountName= ...
- Swift入门篇-字符串和字符
今天主要是介绍一下字符串的用法 ,字符串的语法和object-c语法不太一样,但是思想是一样,就是写法不太一样.如果您对.net和java语法比较熟悉的话,那您几乎没有深压力.如果您对swift 基本 ...
- Requirements of an SAP system administrator
Requirements of an SAP system administrator Have a "proper" attitude Protect and safeguard ...