1 """GNUmed exception handling widgets."""
2
3
4
5 __version__ = "$Revision: 1.16 $"
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 == exceptions.ImportError:
72 gmGuiHelpers.gm_show_error (
73 aTitle = _('Missing GNUmed module'),
74 aMessage = _(
75 'GNUmed detected that parts of it are not\n'
76 'properly installed. The following message\n'
77 'names the missing part:\n'
78 '\n'
79 ' "%s"\n'
80 '\n'
81 'Please make sure to get the missing\n'
82 'parts installed. Otherwise some of the\n'
83 'functionality will not be accessible.'
84 ) % v
85 )
86 _log2.error('module [%s] not installed', v)
87 return
88
89
90 _log2.error('enabling debug mode')
91 _cfg = gmCfg2.gmCfgData()
92 _cfg.set_option(option = 'debug', value = True)
93 root_logger = logging.getLogger()
94 root_logger.setLevel(logging.DEBUG)
95 gmLog2.log_stack_trace()
96
97 name = os.path.basename(_logfile_name)
98 name, ext = os.path.splitext(name)
99 new_name = os.path.expanduser(os.path.join (
100 '~',
101 'gnumed',
102 'logs',
103 '%s_%s%s' % (name, pyDT.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'), ext)
104 ))
105
106 dlg = cUnhandledExceptionDlg(parent = None, id = -1, exception = (t, v, tb), logfile = new_name)
107 dlg.ShowModal()
108 comment = dlg._TCTRL_comment.GetValue()
109 dlg.Destroy()
110 if (comment is not None) and (comment.strip() != u''):
111 _log2.error(u'user comment: %s', comment.strip())
112
113 _log2.warning('syncing log file for backup to [%s]', new_name)
114 gmLog2.flush()
115 shutil.copy2(_logfile_name, new_name)
116
138
145
151
153
155
156 exception = kwargs['exception']
157 del kwargs['exception']
158 self.logfile = kwargs['logfile']
159 del kwargs['logfile']
160
161 wxgUnhandledExceptionDlg.wxgUnhandledExceptionDlg.__init__(self, *args, **kwargs)
162
163 if _sender_email is not None:
164 self._TCTRL_sender.SetValue(_sender_email)
165 self._TCTRL_helpdesk.SetValue(_helpdesk)
166 self._TCTRL_logfile.SetValue(self.logfile)
167 t, v, tb = exception
168 self._TCTRL_exc_type.SetValue(str(t))
169 self._TCTRL_exc_value.SetValue(str(v))
170 self._TCTRL_traceback.SetValue(''.join(traceback.format_tb(tb)))
171
172 self.Fit()
173
184
327
333
334
335
336
337
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