def monitor(script, src, dst):
"""
reloads the script given by argv when src files changes
"""
src = src if isinstance(src, (list, tuple)) else [src]
dst = Path(dst).expand().abspath()
src = [Path(entry).expand().abspath() for entry in src]
script = Path(script).expand().abspath()
command = '{0} {1} {2}'.format(script, ' '.join(src), dst)
event_handler = RunScriptChangeHandler(command)
observer = Observer()
click.secho('watch recursive: {0}'.format(script.dirname()), fg='blue')
observer.schedule(event_handler, script.dirname(), recursive=True)
for entry in src:
click.secho('watch recursive: {0}'.format(entry), fg='blue')
observer.schedule(event_handler, entry, recursive=True)
event_handler.run() # run always once
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
评论列表
文章目录