Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0, 2.0.1, and 2.0.2

stable TortoiseHgOverlayServer: more logging

Changeset 32bdfd356213

Parent d2444b54d059

by Adrian Buehlmann

Changes to one file · Browse files at 32bdfd356213 Showing diff from parent d2444b54d059 Diff from another changeset...

 
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
54
55
 
148
149
150
151
 
152
153
154
 
155
 
156
157
158
 
166
167
168
 
169
170
171
172
173
 
 
174
175
176
 
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
 
397
398
399
400
 
401
402
403
 
425
426
427
428
 
429
430
431
 
455
456
457
458
459
 
460
461
462
463
464
465
 
466
467
468
 
491
492
493
494
 
495
496
497
 
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
178
179
180
 
181
182
183
 
184
185
186
187
188
189
 
197
198
199
200
201
202
203
204
 
205
206
207
208
209
 
222
223
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
226
227
 
409
410
411
 
412
413
414
415
 
437
438
439
 
440
441
442
443
 
467
468
469
 
 
470
471
472
473
474
475
 
476
477
478
479
 
502
503
504
 
505
506
507
508
@@ -50,6 +50,36 @@
   EXIT_CMD = 1025   +class Logger(): + def __init__(self): + self.file = None + + def setfile(self, name): + oname = name + '.old' + try: + os.unlink(oname) + except: + pass + try: + os.rename(name, oname) + except: + pass + self.file = open(name, 'wb') + self.msg('Logging to file started') + + def msg(self, msg): + ts = '[%s] ' % time.strftime('%c') + f = self.file + if f: + f.write(ts + msg + '\n') + f.flush() + os.fsync(f.fileno()) + print 'L' + ts + msg + else: + print ts + msg + +logger = Logger() +  def SetIcon(hwnd, name, add=False):   # Try and find a custom icon   if '--noicon' in sys.argv: @@ -148,11 +178,12 @@
  def exit_application(self):   if self.stop_pipe_server():   DestroyWindow(self.hwnd) - print "Goodbye" + logger.msg("Goodbye")     def stop_pipe_server(self): - print "Stopping pipe server..." + logger.msg("Stopping pipe server...")   if not self.pipethread.isAlive(): + logger.msg("pipethread is not alive")   return True     # Try the nice way first @@ -166,11 +197,13 @@
  self.pipethread.terminate()   win32pipe.CallNamedPipe(PIPENAME, '', PIPEBUFSIZE, 0)   except: + logger.msg(traceback.format_exc())   pass   cnt += 1     if self.pipethread.isAlive(): - print "WARNING: unable to stop server after %d trys." % max_try + msg = "WARNING: unable to stop server after %d trys." % max_try + logger.msg(msg)   return False   else:   return True @@ -189,27 +222,6 @@
   PIPEBUFSIZE = 4096   -class Logger(): - def __init__(self): - self.file = None - - def setfile(self, name): - self.file = open(name, 'wb') - self.msg('Logging to file started') - - def msg(self, msg): - ts = '[%s] ' % time.strftime('%c') - f = self.file - if f: - f.write(ts + msg + '\n') - f.flush() - os.fsync(f.fileno()) - print 'L' + ts + msg - else: - print ts + msg - -logger = Logger() -  def getrepos(batch):   roots = set()   notifypaths = set() @@ -397,7 +409,7 @@
  self.overlapped.hEvent = win32event.CreateEvent(None,0,0,None)     def SvcStop(self): - print 'PipeServer thread terminating' + logger.msg('PipeServer thread terminating')   win32event.SetEvent(self.hWaitStop)   requests.put('terminate')   @@ -425,7 +437,7 @@
  try:   hr = win32pipe.ConnectNamedPipe(pipeHandle, self.overlapped)   except pywintypes.error, inst: - print "Error connecting pipe: ", inst + logger.msg("Error connecting pipe: %s" % inst)   pipeHandle.Close()   break   @@ -455,14 +467,13 @@
  try:   requests.put(data)   if data == 'terminate|': - print 'PipeServer received terminate from pipe' - print 'posting EXIT_CMD to gui thread...' + logger.msg('PipeServer received terminate from pipe')   PostMessage(self.hwnd, win32con.WM_COMMAND, EXIT_CMD, 0)   break   except SystemExit:   raise SystemExit # interrupted by thread2.terminate()   except: - print "WARNING: something went wrong in requests.put" + logger.msg("WARNING: something went wrong in requests.put")   logger.msg(traceback.format_exc())   status = "ERROR"   # Clean up when we exit @@ -491,7 +502,7 @@
  logfilename = arg   if logfilename:   logger.setfile(logfilename) - elif hasattr(sys, "frozen"): + else:   try:   from win32com.shell import shell, shellcon   appdir = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_APPDATA)