changeset 20:8dd18f864351

pydershell now exits with a nonzero return code if the script it calls throws an exception.
author Atul Varma <varmaa@toolness.com>
date Mon, 07 Sep 2009 12:59:13 -0700
parents 057260102960
children 1950b0b5bcd8
files pydershell/pydershell.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pydershell/pydershell.py	Mon Sep 07 12:57:20 2009 -0700
+++ b/pydershell/pydershell.py	Mon Sep 07 12:59:13 2009 -0700
@@ -295,11 +295,13 @@
             return jsvalue
 
     def run_script(self, filename):
+        retval = -1
         contents = open(filename).read()
         cx = self.cx
         try:
             cx.evaluate_script(self.root.wrapped_jsobject, contents,
                                filename, 1)
+            retval = 0
         except pydermonkey.error, e:
             print format_stack(self.js_stack)
             print e.args[1]
@@ -307,6 +309,7 @@
             print "An internal error occurred."
             traceback.print_tb(e.exc_info[2])
             print e.exc_info[1]
+        return retval
 
 if __name__ == '__main__':
     sandbox = JSSandbox()
@@ -323,7 +326,7 @@
         print string
     sandbox.root['print'] = jsprint
 
-    sandbox.run_script('test.js')
+    retval = sandbox.run_script('test.js')
 
     sandbox.finish()
     del sandbox
@@ -332,3 +335,5 @@
     gc.collect()
     if pydermonkey.get_debug_info()['runtime_count']:
         print "WARNING: JS runtime was not destroyed."
+
+    sys.exit(retval)