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 ...
随机推荐
- 深入理解c++构造函数, 复制构造函数和赋值函数重载(operator=)
注 以下代码编译及运行环境均为 Xcode 6.4, LLVM 6.1 with GNU++11 support, Mac OS X 10.10.2 调用时机 看例子 // // main.cpp / ...
- 秀才提笔忘了字:javascript使用requestAnimationFrame实现动画
requestAnimationFrame优于setTimeout/setInterval的地方在于它是由浏览器专门为动画提供的API,在运行时浏览器会自动优化方法的调用,并且如果页面不是激活状态下的 ...
- paip.微信菜单直接跳转url和获取openid流程总结
paip.微信菜单直接跳转url和获取openid流程总结 #------不能直接跳转,贝儿提示不安全的链接.. #-------使用auth跳转. //todox 直接转到.. direct ...
- Leetcode 119 Pascal's Triangle II 数论递推
杨辉三角,这次要输出第rowIndex行 用滚动数组t进行递推 t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1]; class Solution { public: ...
- WPF面板布局介绍Grid、StackPanel、DockPanel、WrapPanel
回顾 上一篇,我们介绍了基本控件及控件的重要属性和用法,我们本篇详细介绍WPF中的几种布局容器及每种布局容器的使用场景,当 然这些都是本人在实际项目中的使用经验,可能还存在错误之处,还请大家指出. 本 ...
- shell变量注意事项
概念:变量赋值,变量替换,变量引用,命令替换 variable=22 echo variable 可以在同一行设置多个变量.例如 va1=good va2=chif va3=beijing #需 ...
- 利用python自动清除Android工程中的多余资源
我们直接在公司项目中使用,效果良好! 分享出脚本代码,希望对Android研发的同学有帮助. 提示,初学python,开发环境是Sublime Text 2,直接Ctrl+B的,其他环境下没调试过.应 ...
- IOS越狱开发之——进程通讯
Mac OS下的IPC方式种类很多,大约有下面几种. 1. Mach API 2. CFMessagePort 3. Distributed Objects (DO) 4. Apple events ...
- Android的Activity屏幕切换动画(一)-左右滑动切换
(国内知名Android开发论坛eoe开发者社区推荐:http://www.eoeandroid.com/) Android的Activity屏幕切换动画(一)-左右滑动切换 在Android开发过程 ...
- Codeforces Round #177 (Div. 1) 题解【ABCD】
Codeforces Round #177 (Div. 1) A. Polo the Penguin and Strings 题意 让你构造一个长度为n的串,且里面恰好包含k个不同字符,让你构造的字符 ...