watch.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:nom 作者: frnsys 项目源码 文件源码
def watch_note(note, handle_func):
    """watch a single note for changes,
    call `handle_func` on change"""
    ob = Observer()
    handler = FileSystemEventHandler()
    note_filename = path.basename(note)
    server = MarkdownServer()
    server.start()

    def handle_event(event):
        _, filename = path.split(event.src_path)
        if note_filename == filename or \
                path.normpath(event.src_path) == path.normpath(util.assets_dir(note)):
            print('compiling...')
            handle_func(note)
            server.update_clients()
            print('done')
    handler.on_any_event = handle_event

    print('watching "{0}"...'.format(note_filename))
    ob.schedule(handler, path.dirname(note), recursive=True)
    ob.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print('stopping...')
        ob.stop()
    server.shutdown()
    ob.join()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号