diff options
author | Matthew Shao <me@matshao.com> | 2016-01-12 22:24:18 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2016-01-12 22:24:18 +0800 |
commit | 181c2973e6d1d27cb58c7622991b6c3f7f41c22c (patch) | |
tree | 189331e8dd6f6446f4d1cf1e8ad0278e8a5c6c52 /libmproxy/script/reloader.py | |
parent | 201fdea6e51624e104273eba760b7c5e02848c89 (diff) | |
download | mitmproxy-181c2973e6d1d27cb58c7622991b6c3f7f41c22c.tar.gz mitmproxy-181c2973e6d1d27cb58c7622991b6c3f7f41c22c.tar.bz2 mitmproxy-181c2973e6d1d27cb58c7622991b6c3f7f41c22c.zip |
PollingObserver() fixed on Linux and OS X.
Diffstat (limited to 'libmproxy/script/reloader.py')
-rw-r--r-- | libmproxy/script/reloader.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libmproxy/script/reloader.py b/libmproxy/script/reloader.py index f824d838..6f3c69ed 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"] |