From 05caa0a03d118a8f0fdf42bbe34ed74c8940c4a0 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 23 Jul 2016 11:08:14 +1200 Subject: script: tune auto reload - Don't respond to directory changes - Ignore hidden files I've "solved" this as well as it can be done in modd, and getting good results here just turns into a large pile of heuristics that don't work in all circumstances. Also watchdog sucks. --- mitmproxy/builtins/script.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mitmproxy/builtins/script.py b/mitmproxy/builtins/script.py index 468aa8e0..220fb9af 100644 --- a/mitmproxy/builtins/script.py +++ b/mitmproxy/builtins/script.py @@ -94,11 +94,21 @@ class ReloadHandler(watchdog.events.FileSystemEventHandler): def __init__(self, callback): self.callback = callback + def filter(self, event): + if event.is_directory: + return False + if os.path.basename(event.src_path).startswith("."): + return False + print(event.src_path) + return True + def on_modified(self, event): - self.callback() + if self.filter(event): + self.callback() def on_created(self, event): - self.callback() + if self.filter(event): + self.callback() class Script: -- cgit v1.2.3