mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Move the observer initalization to the constructor of Script
class.Should work with both mitmproxy and mitmdump now. Change the names in PEP8 style.
This commit is contained in:
parent
3f6521f912
commit
2522ba69fa
@ -225,7 +225,6 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
if err:
|
||||
print >> sys.stderr, "Script load error:", err
|
||||
sys.exit(1)
|
||||
script.ObserveScripts(self, i)
|
||||
|
||||
if options.outfile:
|
||||
err = self.start_stream_to_path(
|
||||
|
@ -6,7 +6,6 @@ import shlex
|
||||
import sys
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import PatternMatchingEventHandler, FileModifiedEvent
|
||||
from .console import signals
|
||||
|
||||
|
||||
class ScriptError(Exception):
|
||||
@ -71,6 +70,7 @@ class Script:
|
||||
self.ctx = ScriptContext(master)
|
||||
self.ns = None
|
||||
self.load()
|
||||
observe_scripts(master, self.args[0])
|
||||
|
||||
@classmethod
|
||||
def parse_command(cls, command):
|
||||
@ -199,18 +199,19 @@ def concurrent(fn):
|
||||
|
||||
class ScriptModified(PatternMatchingEventHandler):
|
||||
|
||||
def __init__(self, FlowMaster):
|
||||
self.FlowMaster = FlowMaster
|
||||
def __init__(self, flow_master):
|
||||
self.flow_master = flow_master
|
||||
PatternMatchingEventHandler.__init__(self, ignore_directories=True, patterns=["*.py"])
|
||||
self.context = ScriptContext(self.flow_master)
|
||||
|
||||
def on_modified(self, event=FileModifiedEvent):
|
||||
self.FlowMaster.reload_scripts()
|
||||
signals.status_message.send(message="script: <{0}> reloaded.".format(event.src_path))
|
||||
self.flow_master.reload_scripts()
|
||||
self.context.log("script: <{}> reloaded.".format(event.src_path))
|
||||
|
||||
|
||||
def ObserveScripts(FlowMaster, path):
|
||||
def observe_scripts(flow_master, path):
|
||||
script_dir = os.path.dirname(path)
|
||||
event_handler = ScriptModified(FlowMaster)
|
||||
event_handler = ScriptModified(flow_master)
|
||||
observer = Observer()
|
||||
observer.schedule(event_handler, script_dir)
|
||||
observer.start()
|
||||
|
Loading…
Reference in New Issue
Block a user