diff options
Diffstat (limited to 'libmproxy/script.py')
-rw-r--r-- | libmproxy/script.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/libmproxy/script.py b/libmproxy/script.py index 95fd5be2..623f2b92 100644 --- a/libmproxy/script.py +++ b/libmproxy/script.py @@ -8,12 +8,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): @@ -23,17 +23,23 @@ 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) except Exception, v: raise ScriptError(traceback.format_exc(v)) self.ns = ns + r = self.run("start", self.argv) + if not r[0] and r[1]: + raise ScriptError(r[1][1]) + + def unload(self): + return self.run("done") def run(self, name, *args, **kwargs): """ |