监视文件变更

#!/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. C#与数据库访问技术总结(十)之添加&删除

    说明:上一篇文章写了更新数据,接下来就是添加和删除数据了. 添加记录 从程序员的角度看,向数据库中添加新的记录与更改现有记录没有任何区别. 为SQL INSERT命令或者存储过程创建一个Command ...

  2. Apple移动设备处理器指令集 armv6、armv7、armv7s及arm64

    Arm处理器,因为其低功耗和小尺寸而闻名,几乎所有的手机处理器都基于arm,其在嵌入式系统中的应用非常广泛,它的性能在同等功耗产品中也很出色. Armv6.armv7.armv7s.arm64都是ar ...

  3. JAVA学习绘图颜色及其笔画属性设置字体显示文字

    package com.graphics; import java.awt.*; import java.awt.geom.Rectangle2D; import java.util.Date; im ...

  4. 每天一个linux命令(6):rmdir 命令

    今天学习一下linux中命令: rmdir命令.rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.)删 ...

  5. INFO - InstallShield中的InstallScript工程Setup.exe /s的使用细节

    在InstallShield的各种工程类型中,Basic MSI工程Build出的安装包基于Windows Installer标准,所以默认就支持静默安装(至于如何静默安装,请自行补充相关知识).而对 ...

  6. linux云主机怎么安装WDCP

    linux云主机 教你成功安装WDCP的2个方法(第一个不成功就试第2个) 工具/原料   Xshell 云服务器 方法/步骤   1 先用Xshell连接你的服务器 2 输入一下代码    wget ...

  7. 在github上写博客

    在github上混了几个月,收获颇多.作为一个开源的坚定信仰者,深深觉得每一个码农都应该参与到开源社区中,github提供了一个平台,让你为开源项目提交代码变得异常简单和直接.以前由于工作异常繁忙和繁 ...

  8. ubuntu下安装多版本Python

    今天一不小心又把ubuntu系统给完坏了,因为我把python3卸载了,然后就...好了,不废话了,接下来就说一下如何在ubuntu下管理python的多个版本.我这里使用的是一个叫pyenv的Pyt ...

  9. 通过Typings为Visual Studio Code增强智能提示功能

    缘起 最近在学习Node.js及ThinkJS这个框架,用vscode作为开发环境.默认情况下vscode对ThinkJS的代码提示并不好,所以研究了一下,原来可以同通过Typings来让vscode ...

  10. Three Sources of a Solid Object-Oriented Design

    pingback :http://java.sys-con.com/node/84633?page=0,1 Object-oriented design is like an alloy consis ...