Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

overlay: catch and log tracebacks

Changeset 8cb7454e342d

Parent 38aabe2c5435

by Steve Borho

Changes to one file · Browse files at 8cb7454e342d Showing diff from parent 38aabe2c5435 Diff from another changeset...

 
9
10
11
 
12
13
14
 
29
30
31
32
33
34
 
 
 
 
 
 
 
 
 
 
 
35
36
37
 
430
431
432
433
434
435
 
436
437
438
439
440
441
 
 
 
 
442
443
444
 
456
457
458
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
460
461
 
9
10
11
12
13
14
15
 
30
31
32
 
 
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
439
440
441
 
442
 
443
444
445
446
447
448
449
450
451
452
453
454
455
456
 
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
@@ -9,6 +9,7 @@
 import threading  import cStringIO  import Queue +import traceback    from win32api import *  from win32gui import * @@ -29,9 +30,17 @@
 from tortoisehg.util import thread2, paths, shlib    if hasattr(sys, "frozen"): - # Give stdout/stderr closed attributes to prevent ui.py errors - sys.stdout.closed = True - sys.stderr.closed = True + class BlackHole(object): + closed = True + softspace = 0 + def write(self, data): + pass + def close(self): + pass + def flush(self): + pass + sys.stdout = BlackHole() + sys.stderr = BlackHole()    APP_TITLE = _('TortoiseHg Overlay Icon Server')   @@ -430,15 +439,18 @@
  except SystemExit:   raise SystemExit # interrupted by thread2.terminate()   except: - import traceback   print "WARNING: something went wrong in requests.put" - print traceback.format_exc() + logger.msg(traceback.format_exc())   status = "ERROR"   # Clean up when we exit   self.SvcStop()    RUNMUTEXNAME = 'thgtaskbar-' + GetUserName()   +def ehook(etype, values, tracebackobj): + elist = traceback.format_exception(etype, values, tracebackobj) + logger.msg(''.join(elist)) +  def main():   args = sys.argv[1:]   sa = win32security.SECURITY_ATTRIBUTES() @@ -456,6 +468,20 @@
  logfilename = arg   if logfilename:   logger.setfile(logfilename) + elif hasattr(sys, "frozen"): + try: + from win32com.shell import shell, shellcon + appdir = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_APPDATA) + except pywintypes.com_error: + appdir = os.environ['APPDATA'] + logfilename = os.path.join(appdir, 'TortoiseHg', 'OverlayServerLog.txt') + try: + os.makedirs(os.path.dirname(logfilename)) + except EnvironmentError: + pass + logger.setfile(logfilename) + + sys.excepthook = ehook     w=MainWindow()   PumpMessages()