From 181c2973e6d1d27cb58c7622991b6c3f7f41c22c Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 12 Jan 2016 22:24:18 +0800 Subject: [PATCH] PollingObserver() fixed on Linux and OS X. --- libmproxy/script/reloader.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libmproxy/script/reloader.py b/libmproxy/script/reloader.py index f824d838a..6f3c69ed1 100644 --- a/libmproxy/script/reloader.py +++ b/libmproxy/script/reloader.py @@ -27,9 +27,7 @@ def unwatch(script): class _ScriptModificationHandler(PatternMatchingEventHandler): def __init__(self, callback, filename='*'): - # We could enumerate all relevant *.py files (as werkzeug does it), - # but our case looks like it isn't as simple as enumerating sys.modules. - # This should be good enough for now. + super(_ScriptModificationHandler, self).__init__( ignore_directories=True, ) @@ -38,7 +36,7 @@ class _ScriptModificationHandler(PatternMatchingEventHandler): def on_modified(self, event): if event.is_directory: - files_in_dir = [event.src_path + "/" + \ + files_in_dir = [event.src_path + "/" + f for f in os.listdir(event.src_path)] if len(files_in_dir) > 0: modified_filepath = max(files_in_dir, key=os.path.getmtime) @@ -50,5 +48,9 @@ class _ScriptModificationHandler(PatternMatchingEventHandler): if fnmatch.fnmatch(os.path.basename(modified_filepath), self.filename): self.callback() + def on_created(self, event): + if fnmatch.fnmatch(os.path.basename(event.src_path), self.filename): + self.callback() + __all__ = ["watch", "unwatch"]