python watchdog
2015-06-22 22:16
609 查看
监视文件变更
#!/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 使用post登录网易
- web python -- WSGI接口
- python爬取网易美女图片
- Python 爬虫学习 相关类库的介绍
- Python学习 之 对内存的使用(浅拷贝和深拷贝)
- Python学习 之 爬虫
- (翻译)如何对python dict 类型按键(keys)或值(values)排序
- python bottle框架使用beaker支持session
- python 连接mysql多层结构实例
- Python学习 之 正则表达式
- Python运算符及表达式
- python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样
- Python简单对文件进行读写操作
- python 微信企业号
- python-基础教程笔记
- install python+twisted+mysqldb+django on mac
- Python套接字编程(1)——socket模块与套接字编程
- 学习《Python核心编程》做一下知识点提要,方便复习(一)
- python unicode转str方法
- Python学习手册 上传文件太大,上传2次均失败