Enable "|" command to run a oneshot script on a single flow.
This commit is contained in:
parent
cfc6e8777e
commit
e337682d8e
|
@ -194,7 +194,7 @@ class ConnectionItem(WWrap):
|
|||
elif key == "|":
|
||||
self.master.path_prompt(
|
||||
"Send flow to script: ", self.state.last_script,
|
||||
self.master.run_script, self.flow
|
||||
self.master.run_script_once, self.flow
|
||||
)
|
||||
return key
|
||||
|
||||
|
@ -551,7 +551,7 @@ class ConnectionView(WWrap):
|
|||
elif key == "|":
|
||||
self.master.path_prompt(
|
||||
"Send flow to script: ", self.state.last_script,
|
||||
self.master.run_script, self.flow
|
||||
self.master.run_script_once, self.flow
|
||||
)
|
||||
elif key == "z":
|
||||
if self.state.view_flow_mode == VIEW_FLOW_RESPONSE:
|
||||
|
@ -989,6 +989,21 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
|
||||
self.debug = options.debug
|
||||
|
||||
def run_script_once(self, path, f):
|
||||
ret = self.get_script(path)
|
||||
if ret[0]:
|
||||
self.statusbar.message(ret[0])
|
||||
s = ret[1]
|
||||
|
||||
if f.request:
|
||||
s.run("request", f)
|
||||
if f.response:
|
||||
s.run("response", f)
|
||||
if f.error:
|
||||
s.run("error", f)
|
||||
self.refresh_connection(f)
|
||||
self.state.last_script = path
|
||||
|
||||
def set_script(self, path):
|
||||
if not path:
|
||||
return
|
||||
|
|
|
@ -443,20 +443,30 @@ class FlowMaster(controller.Master):
|
|||
"""
|
||||
pass
|
||||
|
||||
def load_script(self, path):
|
||||
def get_script(self, path):
|
||||
"""
|
||||
Loads a script. Returns an error description if something went
|
||||
wrong.
|
||||
Returns an (error, script) tuple.
|
||||
"""
|
||||
s = script.Script(path, self)
|
||||
try:
|
||||
s.load()
|
||||
except script.ScriptError, v:
|
||||
return v.args[0]
|
||||
return (v.args[0], None)
|
||||
ret = s.run("start")
|
||||
if not ret[0] and ret[1]:
|
||||
return "Error in script start:\n\n" + ret[1][1]
|
||||
self.script = s
|
||||
return ("Error in script start:\n\n" + ret[1][1], None)
|
||||
return (None, s)
|
||||
|
||||
def load_script(self, path):
|
||||
"""
|
||||
Loads a script. Returns an error description if something went
|
||||
wrong.
|
||||
"""
|
||||
r = self.get_script(path)
|
||||
if r[0]:
|
||||
return r[0]
|
||||
else:
|
||||
self.script = r[1]
|
||||
|
||||
def set_stickycookie(self, txt):
|
||||
if txt:
|
||||
|
|
|
@ -130,14 +130,6 @@ class uServerPlaybackState(libpry.AutoTree):
|
|||
|
||||
|
||||
class uFlow(libpry.AutoTree):
|
||||
def test_run_script(self):
|
||||
f = tutils.tflow()
|
||||
f.response = tutils.tresp()
|
||||
f.request = f.response.request
|
||||
se = f.run_script("scripts/a")
|
||||
assert "DEBUG" == se.strip()
|
||||
assert f.request.host == "TESTOK"
|
||||
|
||||
def test_match(self):
|
||||
f = tutils.tflow()
|
||||
f.response = tutils.tresp()
|
||||
|
|
Loading…
Reference in New Issue