aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/script
diff options
context:
space:
mode:
authorMatthewShao <me@matshao.com>2016-01-12 11:45:03 +0800
committerMatthewShao <me@matshao.com>2016-01-12 11:45:03 +0800
commite72663be081b8ef534b4ef43b90807c55d15b8fb (patch)
treec1284d3ac2b33af9f9d99b9d71bdf7d475f23bb0 /libmproxy/script
parentaea3837d4ae637af42f716acb27d7ea8394ece35 (diff)
downloadmitmproxy-e72663be081b8ef534b4ef43b90807c55d15b8fb.tar.gz
mitmproxy-e72663be081b8ef534b4ef43b90807c55d15b8fb.tar.bz2
mitmproxy-e72663be081b8ef534b4ef43b90807c55d15b8fb.zip
Fix script reloader on OS X.
Diffstat (limited to 'libmproxy/script')
-rw-r--r--libmproxy/script/reloader.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/libmproxy/script/reloader.py b/libmproxy/script/reloader.py
index 26691fa3..ad6303a6 100644
--- a/libmproxy/script/reloader.py
+++ b/libmproxy/script/reloader.py
@@ -1,4 +1,5 @@
import os
+import fnmatch
from watchdog.events import PatternMatchingEventHandler
from watchdog.observers import Observer
@@ -24,17 +25,30 @@ def unwatch(script):
class _ScriptModificationHandler(PatternMatchingEventHandler):
- def __init__(self, callback):
+ def __init__(self, callback, pattern='*.py'):
# 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,
- patterns=["*.py"]
)
self.callback = callback
+ self.pattern = pattern
def on_modified(self, event):
- self.callback()
+ super(_ScriptModificationHandler, self).on_modified(event)
+ if event.is_directory:
+ files_in_dir = [event.src_path + "/" + \
+ f for f in os.listdir(event.src_path)]
+ if len(files_in_dir) > 0:
+ modifiedFilename = max(files_in_dir, key=os.path.getmtime)
+ else:
+ return
+ else:
+ modifiedFilename = event.src_path
+
+ if fnmatch.fnmatch(os.path.basename(modifiedFilename), self.pattern):
+ self.callback()
+
+__all__ = ["watch", "unwatch"]
-__all__ = ["watch", "unwatch"] \ No newline at end of file