add ui.print_exc(), make all traceback printing central.
authorVadim Gelfer <vadim.gelfer@gmail.com>
Mon, 22 May 2006 08:47:53 -0700
changeset 2335 f0680b2d1d64
parent 2334 737deea2442c
child 2336 f77edcffb837
add ui.print_exc(), make all traceback printing central.
mercurial/commands.py
mercurial/localrepo.py
mercurial/ui.py
--- a/mercurial/commands.py	Sun May 21 23:39:25 2006 -0700
+++ b/mercurial/commands.py	Mon May 22 08:47:53 2006 -0700
@@ -3299,10 +3299,8 @@
             external.append(mod)
         except Exception, inst:
             u.warn(_("*** failed to import extension %s: %s\n") % (x[0], inst))
-            if u.traceback:
-                traceback.print_exc()
+            if u.print_exc():
                 return 1
-            continue
 
     for x in external:
         uisetup = getattr(x, 'uisetup', None)
@@ -3398,8 +3396,7 @@
             # enter the debugger when we hit an exception
             if options['debugger']:
                 pdb.post_mortem(sys.exc_info()[2])
-            if u.traceback:
-                traceback.print_exc()
+            u.print_exc()
             raise
     except ParseError, inst:
         if inst.args[0]:
--- a/mercurial/localrepo.py	Sun May 21 23:39:25 2006 -0700
+++ b/mercurial/localrepo.py	Mon May 22 08:47:53 2006 -0700
@@ -12,7 +12,7 @@
 from demandload import *
 demandload(globals(), "appendfile changegroup")
 demandload(globals(), "re lock transaction tempfile stat mdiff errno ui")
-demandload(globals(), "revlog traceback")
+demandload(globals(), "revlog")
 
 class localrepository(object):
     def __del__(self):
@@ -125,8 +125,7 @@
                                    '%s\n') % (hname, exc))
                 if throw:
                     raise
-                if self.ui.traceback:
-                    traceback.print_exc()
+                self.ui.print_exc()
                 return True
             if r:
                 if throw:
--- a/mercurial/ui.py	Sun May 21 23:39:25 2006 -0700
+++ b/mercurial/ui.py	Mon May 22 08:47:53 2006 -0700
@@ -9,7 +9,7 @@
 from i18n import gettext as _
 from demandload import *
 demandload(globals(), "errno getpass os re smtplib socket sys tempfile")
-demandload(globals(), "templater util")
+demandload(globals(), "templater traceback util")
 
 class ui(object):
     def __init__(self, verbose=False, debug=False, quiet=False,
@@ -335,3 +335,11 @@
         else:
             mail = sendmail(self, method)
         return mail
+
+    def print_exc(self):
+        '''print exception traceback if traceback printing enabled.
+        only to call in exception handler. returns true if traceback
+        printed.'''
+        if self.traceback:
+            traceback.print_exc()
+        return self.traceback