Commits

Michael Grünewald committed 89b8ea3

support for tracebacks

Comments (0)

Files changed (1)

 import operator
 import pprint
 import sys
+import traceback
 import xmlrpclib
 
 
     parser.add_argument(
         '-p', '--print', action='store_true',
         help="just print, don't pretty-print")
+    parser.add_argument(
+        '--traceback', action='store_true',
+        help="print tracebacks for exceptions"
+    )
     args = parser.parse_args()
 
-    proxy = xmlrpclib.ServerProxy(args.url)
-    arguments = [literal_or_string(param) for param in args.params]
     try:
+        proxy = xmlrpclib.ServerProxy(args.url)
+        arguments = [literal_or_string(param) for param in args.params]
         result = operator.attrgetter(args.method)(proxy)(*arguments)
     except xmlrpclib.Fault as fault:
         print("Fault {0.faultCode:d}: {0.faultString:s}".format(fault),
         print("-- interrupted --", file=sys.stderr)
         return 1
     except Exception as exc:
-        print("Exception: {:s}".format(exc), file=sys.stderr)
+        if args.traceback:
+            traceback.print_exc()
+        else:
+            print(*traceback.format_exception_only(type(exc), exc),
+                  sep="", end="", file=sys.stderr)
         return 1
     else:
         if args.print: