1 """GNUmed exception handling widgets."""
2
3
4
5 __version__ = "$Revision: 1.17 $"
6 __author__ = "K. Hilbert <Karsten.Hilbert@gmx.net>"
7 __license__ = "GPL (details at http://www.gnu.org)"
8
9 import logging, exceptions, traceback, re as regex, sys, os, shutil, datetime as pyDT, codecs
10
11
12 import wx
13
14
15 from Gnumed.business import gmSurgery
16 from Gnumed.pycommon import gmDispatcher, gmTools, gmCfg2, gmI18N, gmLog2
17 from Gnumed.wxpython import gmGuiHelpers
18 from Gnumed.wxGladeWidgets import wxgUnhandledExceptionDlg
19
20
21 _log2 = logging.getLogger('gm.gui')
22 _log2.info(__version__)
23
24 _prev_excepthook = None
25 application_is_closing = False
26
28 global _client_version
29 _client_version = version
30
32 global _sender_email
33 _sender_email = email
34
36 global _helpdesk
37 _helpdesk = helpdesk
38
40 global _staff_name
41 _staff_name = staff_name
42
44 global _is_public_database
45 _is_public_database = value
46
48
49 _log2.debug('unhandled exception caught:', exc_info = (t, v, tb))
50
51
52 if t == KeyboardInterrupt:
53 print "<Ctrl-C>: Shutting down ..."
54 top_win = wx.GetApp().GetTopWindow()
55 wx.CallAfter(top_win.Close)
56 return
57
58
59 try: wx.EndBusyCursor()
60 except: pass
61
62
63 if application_is_closing:
64
65 if t == wx._core.PyDeadObjectError:
66 return
67 gmLog2.log_stack_trace()
68 return
69
70
71 if t == wx._core.PyDeadObjectError:
72 _log.warning('continuing and hoping for the best')
73 return
74
75
76 if t == exceptions.ImportError:
77 gmGuiHelpers.gm_show_error (
78 aTitle = _('Missing GNUmed module'),
79 aMessage = _(
80 'GNUmed detected that parts of it are not\n'
81 'properly installed. The following message\n'
82 'names the missing part:\n'
83 '\n'
84 ' "%s"\n'
85 '\n'
86 'Please make sure to get the missing\n'
87 'parts installed. Otherwise some of the\n'
88 'functionality will not be accessible.'
89 ) % v
90 )
91 _log2.error('module [%s] not installed', v)
92 return
93
94
95 _log2.error('enabling debug mode')
96 _cfg = gmCfg2.gmCfgData()
97 _cfg.set_option(option = 'debug', value = True)
98 root_logger = logging.getLogger()
99 root_logger.setLevel(logging.DEBUG)
100 gmLog2.log_stack_trace()
101
102 name = os.path.basename(_logfile_name)
103 name, ext = os.path.splitext(name)
104 new_name = os.path.expanduser(os.path.join (
105 '~',
106 'gnumed',
107 'logs',
108 '%s_%s%s' % (name, pyDT.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'), ext)
109 ))
110
111 dlg = cUnhandledExceptionDlg(parent = None, id = -1, exception = (t, v, tb), logfile = new_name)
112 dlg.ShowModal()
113 comment = dlg._TCTRL_comment.GetValue()
114 dlg.Destroy()
115 if (comment is not None) and (comment.strip() != u''):
116 _log2.error(u'user comment: %s', comment.strip())
117
118 _log2.warning('syncing log file for backup to [%s]', new_name)
119 gmLog2.flush()
120 shutil.copy2(_logfile_name, new_name)
121
143
150
156
158
160
161 exception = kwargs['exception']
162 del kwargs['exception']
163 self.logfile = kwargs['logfile']
164 del kwargs['logfile']
165
166 wxgUnhandledExceptionDlg.wxgUnhandledExceptionDlg.__init__(self, *args, **kwargs)
167
168 if _sender_email is not None:
169 self._TCTRL_sender.SetValue(_sender_email)
170 self._TCTRL_helpdesk.SetValue(_helpdesk)
171 self._TCTRL_logfile.SetValue(self.logfile)
172 t, v, tb = exception
173 self._TCTRL_exc_type.SetValue(str(t))
174 self._TCTRL_exc_value.SetValue(str(v))
175 self._TCTRL_traceback.SetValue(''.join(traceback.format_tb(tb)))
176
177 self.Fit()
178
189
332
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394