From 2b4af8d4756bc4eef613ec2cdf81a97d3952150b Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 13 Jun 2013 16:04:04 +0200 Subject: add support for multiple scripts and script arguments. refs #76 --- libmproxy/script.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'libmproxy/script.py') diff --git a/libmproxy/script.py b/libmproxy/script.py index 4ffac71b..4676672b 100644 --- a/libmproxy/script.py +++ b/libmproxy/script.py @@ -23,12 +23,12 @@ class Script: """ The instantiator should do something along this vein: - s = Script(path, master) + s = Script(argv, master) s.load() - s.run("start") """ - def __init__(self, path, ctx): - self.path, self.ctx = path, ctx + def __init__(self, argv, ctx): + self.argv = argv + self.ctx = ctx self.ns = None def load(self): @@ -38,17 +38,21 @@ class Script: Raises ScriptError on failure, with argument equal to an error message that may be a formatted traceback. """ - path = os.path.expanduser(self.path) + path = os.path.expanduser(self.argv[0]) if not os.path.exists(path): - raise ScriptError("No such file: %s"%self.path) + raise ScriptError("No such file: %s" % path) if not os.path.isfile(path): - raise ScriptError("Not a file: %s"%self.path) + raise ScriptError("Not a file: %s" % path) ns = {} try: execfile(path, ns, ns) + self.ns = ns + self.run("start", self.argv) except Exception, v: raise ScriptError(traceback.format_exc(v)) - self.ns = ns + + def unload(self): + return self.run("done") def run(self, name, *args, **kwargs): """ -- cgit v1.2.3