监视文件变更

#!/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. 图解AngularJS Wijmo5和LightSwitch

    Visual Studio 2013 中的 LightSwitch 有新增功能,包括更好的团队开发支持以及在构建 HTML 客户端桌面和 Office 365 应用程序方面的改进.本文结合最新发布的W ...

  2. Oracle 查询用户和删除用户

    ------------------------------- 一.查询用户命令: select username from dba_users; 示例: 二.删除用户命名: drop user 用户 ...

  3. SAP大数据为"海上F1"提供技术支持

    “海上F1”的2014极限帆船赛在青岛开赛,这场大赛是技术与体育高度融合的盛会.比赛中,每一个船员将使用各种高新技术,应尽所能,战胜对手.很多人之所以喜欢这样的比赛,是因为帆船比赛是世界上最复杂的一项 ...

  4. InstallShield 2012 Spring优惠升级到最新版本(2015.4.30之前)

    InstallShield 2012 Spring即将EOF,所以仍在使用InstallShield 2012 Spring的用户请注意下面内容: InstallShield 2012 Spring升 ...

  5. NAS服务器局域网内IPad、手机、电视盒子等联网播放

    为把各个移动硬盘和不同电脑的数据进行统一管理,入手了一台希捷 Seagate Business 无内置硬盘 商业级 2盘位 云存储网路存储,经过卖家指点和不断摸索,终于能用了,主要步骤如下: 1. 系 ...

  6. java微信开发API第一步 服务器接入

    I如何接入服务器,下面就为大家进行介绍 一.说明 * 本示例根据微信开发文档:http://mp.weixin.qq.com/wiki/home/index.html最新版(4/3/2016 5:34 ...

  7. Android webView打不开网页的解决办法

    在我们开发过程中,有可能会遇到webview有些网页打不开的问题.这可能是设置的不对,下面就是解决办法. 进行如下设置吧,大多数情况都能解决! displayWebview.getSettings() ...

  8. Java关键字--static

    在Java中,将关键字static分为三部分进行讨论,分别为Java静态变量.Java静态方法.Java静态类 Java Static Variables Java instance variable ...

  9. hibernateTemplate.find或hibernateTemplate.save()执行操作没有反应,但是有sql语句

    今天使用ssh框架搭建的项目,进行查询和保存操作,使用的是 public Collection<T> getAllEntry() { return this.hibernateTempla ...

  10. bash的循环中无法保存变量

    在bash中,如果循环在一个子shell中运行,那么在循环中对循环外面的变量的更改将在循环退出后不可见.像下面的例子: #!/bin/sh python run.py | while read lin ...