comparison mercurial/ui.py @ 9851:9e7b2c49d25d

Make it possible to debug failed hook imports via use of --traceback Prior to this change, if a Python hook module failed to load (e.g. due to an import error or path problem), it was impossible to figure out why the error occurred, because the ImportErrors that got raised were caught but never displayed. If run with --traceback or ui.traceback=True, hg now prints tracebacks of both of the ImportError instances that get raised before it bails.
author Bryan O'Sullivan <bos@serpentine.com>
date Thu, 12 Nov 2009 14:05:52 -0800
parents 951730b2b8ba
children 38170eeed18c 500d09be7ace
comparison
equal deleted inserted replaced
9850:004bf1d6e6af 9851:9e7b2c49d25d
13 '0': False, 'no': False, 'false': False, 'off': False} 13 '0': False, 'no': False, 'false': False, 'off': False}
14 14
15 class ui(object): 15 class ui(object):
16 def __init__(self, src=None): 16 def __init__(self, src=None):
17 self._buffers = [] 17 self._buffers = []
18 self.quiet = self.verbose = self.debugflag = self._traceback = False 18 self.quiet = self.verbose = self.debugflag = self.tracebackflag = False
19 self._reportuntrusted = True 19 self._reportuntrusted = True
20 self._ocfg = config.config() # overlay 20 self._ocfg = config.config() # overlay
21 self._tcfg = config.config() # trusted 21 self._tcfg = config.config() # trusted
22 self._ucfg = config.config() # untrusted 22 self._ucfg = config.config() # untrusted
23 self._trustusers = set() 23 self._trustusers = set()
99 self.verbose = self.debugflag or self.configbool('ui', 'verbose') 99 self.verbose = self.debugflag or self.configbool('ui', 'verbose')
100 self.quiet = not self.debugflag and self.configbool('ui', 'quiet') 100 self.quiet = not self.debugflag and self.configbool('ui', 'quiet')
101 if self.verbose and self.quiet: 101 if self.verbose and self.quiet:
102 self.quiet = self.verbose = False 102 self.quiet = self.verbose = False
103 self._reportuntrusted = self.configbool("ui", "report_untrusted", True) 103 self._reportuntrusted = self.configbool("ui", "report_untrusted", True)
104 self._traceback = self.configbool('ui', 'traceback', False) 104 self.tracebackflag = self.configbool('ui', 'traceback', False)
105 105
106 # update trust information 106 # update trust information
107 self._trustusers.update(self.configlist('trusted', 'users')) 107 self._trustusers.update(self.configlist('trusted', 'users'))
108 self._trustgroups.update(self.configlist('trusted', 'groups')) 108 self._trustgroups.update(self.configlist('trusted', 'groups'))
109 109
335 finally: 335 finally:
336 os.unlink(name) 336 os.unlink(name)
337 337
338 return t 338 return t
339 339
340 def traceback(self): 340 def traceback(self, exc=None):
341 '''print exception traceback if traceback printing enabled. 341 '''print exception traceback if traceback printing enabled.
342 only to call in exception handler. returns true if traceback 342 only to call in exception handler. returns true if traceback
343 printed.''' 343 printed.'''
344 if self._traceback: 344 if self.tracebackflag:
345 traceback.print_exc() 345 if exc:
346 return self._traceback 346 traceback.print_exception(exc[0], exc[1], exc[2])
347 else:
348 traceback.print_exc()
349 return self.tracebackflag
347 350
348 def geteditor(self): 351 def geteditor(self):
349 '''return editor to use''' 352 '''return editor to use'''
350 return (os.environ.get("HGEDITOR") or 353 return (os.environ.get("HGEDITOR") or
351 self.config("ui", "editor") or 354 self.config("ui", "editor") or