mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
PollingObserver() fixed on Linux and OS X.
This commit is contained in:
parent
201fdea6e5
commit
181c2973e6
@ -27,9 +27,7 @@ def unwatch(script):
|
|||||||
|
|
||||||
class _ScriptModificationHandler(PatternMatchingEventHandler):
|
class _ScriptModificationHandler(PatternMatchingEventHandler):
|
||||||
def __init__(self, callback, filename='*'):
|
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__(
|
super(_ScriptModificationHandler, self).__init__(
|
||||||
ignore_directories=True,
|
ignore_directories=True,
|
||||||
)
|
)
|
||||||
@ -38,7 +36,7 @@ class _ScriptModificationHandler(PatternMatchingEventHandler):
|
|||||||
|
|
||||||
def on_modified(self, event):
|
def on_modified(self, event):
|
||||||
if event.is_directory:
|
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)]
|
f for f in os.listdir(event.src_path)]
|
||||||
if len(files_in_dir) > 0:
|
if len(files_in_dir) > 0:
|
||||||
modified_filepath = max(files_in_dir, key=os.path.getmtime)
|
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):
|
if fnmatch.fnmatch(os.path.basename(modified_filepath), self.filename):
|
||||||
self.callback()
|
self.callback()
|
||||||
|
|
||||||
|
def on_created(self, event):
|
||||||
|
if fnmatch.fnmatch(os.path.basename(event.src_path), self.filename):
|
||||||
|
self.callback()
|
||||||
|
|
||||||
__all__ = ["watch", "unwatch"]
|
__all__ = ["watch", "unwatch"]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user