#FileMonitor [English Version][english_version]
FileMonitor是一个开放的文件监控接口,目的是让开发者提高开发效率。 提供方便的接口来对发送的文件变动进行处理
通过如下代码,可以初步通过Python创建对应的引擎,注册函数和注册监控路径 main.py
from FileMonitor import start_watch, create_engine, add_routers
import os
app = create_engine()
add_routers(app, "handler")
watch_path = os.path.join(os.path.abspath('.'), 'monitor')
start_watch(app, watch_path)
handler.py
import subprocess
import sys
from FileMonitor import created, start, deleted
@created(r'py', once=True)
def pys(src_path):
pass
# print(pys.__re_path__)
print(pys.__method__)
# print("test:", src_path)
@start(r'.*py', once=True, )
def sl(src_path):
print("sl:", src_path)
command = ['python3', src_path]
print('Start process %s...' % ' '.join(command))
process = subprocess.Popen(command, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
@deleted(src_path, once=True, escape=True, process=process)
def fk(src_path):
print('Kill process [%s]...' % fk.__data__['process'].pid)
fk.__data__['process'].kill()
fk.__data__['process'].wait()
print('Process ended with code %s.' % fk.__data__['process'].returncode)
process = None
print("fk:", src_path)
sl.__app__.register_callback(fk)
如果有什么问题或者建议都可以在这个Issue和我讨论