Attachment 'dialogerror.py'

Download

   1 # -*- coding: iso-8859-1 -*-#
   2 #/usr/bin/env python
   3 #Boa:Dialog:DialogError
   4 import wx
   5 import wx.lib.masked.textctrl
   6 
   7 import os
   8 import sys
   9 import traceback
  10 import platform
  11 import __version__
  12 
  13 # Import the email modules we'll need
  14 from email import Encoders
  15 from email.MIMEMultipart import MIMEMultipart
  16 from email.MIMEText import MIMEText
  17 from email.Generator import Generator
  18 import smtplib
  19 
  20 import simplemapi
  21 
  22 # definitions for error handling dialog
  23 eMailSubject = 'A problem report for "MyApp"'
  24 eMailToAddr = 'support@MyApp.com'
  25 
  26 
  27 def create(parent):
  28     return DialogError(parent)
  29 
  30 [wxID_DIALOGERROR, wxID_DIALOGERRORCANCEL, wxID_DIALOGERRORCLEAR, 
  31  wxID_DIALOGERRORCONTEXTHELPBUTTON1, wxID_DIALOGERROREMAIL, 
  32  wxID_DIALOGERRORINFOMSG, wxID_DIALOGERRORMESSAGE, wxID_DIALOGERRORSEND, 
  33  wxID_DIALOGERRORSENDMAPI, wxID_DIALOGERRORSMTPAUTH, 
  34  wxID_DIALOGERRORSMTPPASSWORD, wxID_DIALOGERRORSMTPSERVER, 
  35  wxID_DIALOGERRORSMTPUSER, wxID_DIALOGERRORSQLLOG, 
  36  wxID_DIALOGERRORSTATICLINE1, wxID_DIALOGERRORSTATUSBAR, 
  37  wxID_DIALOGERRORSTDERRLOG, wxID_DIALOGERRORSTDOUTLOG, 
  38  wxID_DIALOGERRORSTEMAIL, wxID_DIALOGERRORSTERRLOG, wxID_DIALOGERRORSTMESSAGE, 
  39  wxID_DIALOGERRORSTPASSWORD, wxID_DIALOGERRORSTSMTPSERVER, 
  40  wxID_DIALOGERRORSTSMTPUSER, wxID_DIALOGERRORSTSQLLOG, 
  41  wxID_DIALOGERRORSTSTDLOG, 
  42 ] = [wx.NewId() for _init_ctrls in range(26)]
  43 
  44 class DialogError(wx.Dialog):
  45     def _init_coll_bsPage_Items(self, parent):
  46         # generated method, don't edit
  47 
  48         parent.AddSizer(self.fgsmsg, 3, border=2, flag=wx.ALL | wx.EXPAND)
  49         parent.AddWindow(self.staticLine1, 0, border=2, flag=wx.ALL | wx.EXPAND)
  50         parent.AddSizer(self.fgsOther, 0, border=2, flag=wx.ALL | wx.EXPAND)
  51         parent.AddWindow(self.infoMsg, 0, border=2, flag=wx.ALL | wx.EXPAND)
  52         parent.AddSizer(self.fgsButtons, 0, border=2, flag=wx.ALL | wx.EXPAND)
  53         parent.AddWindow(self.statusBar, 0, border=2, flag=wx.ALL | wx.EXPAND)
  54 
  55     def _init_coll_fgsmsg_Items(self, parent):
  56         # generated method, don't edit
  57 
  58         parent.AddWindow(self.stMessage, 1, border=2,
  59               flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  60         parent.AddWindow(self.message, 1, border=2, flag=wx.ALL | wx.EXPAND)
  61         parent.AddWindow(self.stStdLog, 1, border=2,
  62               flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  63         parent.AddWindow(self.stdoutlog, 1, border=2, flag=wx.ALL | wx.EXPAND)
  64         parent.AddWindow(self.stErrLog, 1, border=2,
  65               flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  66         parent.AddWindow(self.stderrlog, 1, border=2, flag=wx.ALL | wx.EXPAND)
  67         parent.AddWindow(self.stSqlLog, 1, border=2,
  68               flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  69         parent.AddWindow(self.sqllog, 1, border=2, flag=wx.ALL | wx.EXPAND)
  70 
  71     def _init_coll_fgsOther_Items(self, parent):
  72         # generated method, don't edit
  73 
  74         parent.AddWindow(self.stEmail, 1, border=2,
  75               flag=wx.ADJUST_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  76         parent.AddWindow(self.eMail, 0, border=2, flag=wx.ALL)
  77         parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
  78         parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
  79         parent.AddWindow(self.stSMTPServer, 1, border=2,
  80               flag=wx.ADJUST_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  81         parent.AddWindow(self.smtpServer, 0, border=2, flag=wx.ALL)
  82         parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
  83         parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
  84         parent.AddWindow(self.smtpAuth, 0, border=2, flag=wx.ALL)
  85         parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
  86         parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
  87         parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
  88         parent.AddWindow(self.stSMTPuser, 0, border=2,
  89               flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  90         parent.AddWindow(self.smtpUser, 0, border=2, flag=wx.ALL | wx.EXPAND)
  91         parent.AddWindow(self.stPassword, 0, border=2,
  92               flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
  93         parent.AddWindow(self.smtpPassword, 0, border=2,
  94               flag=wx.ALL | wx.EXPAND)
  95 
  96     def _init_coll_fgsButtons_Items(self, parent):
  97         # generated method, don't edit
  98 
  99         parent.AddWindow(self.send, 1, border=2, flag=wx.ALL)
 100         parent.AddWindow(self.sendMAPI, 1, border=2, flag=wx.ALL)
 101         parent.AddWindow(self.clear, 1, border=2, flag=wx.ALL)
 102         parent.AddWindow(self.cancel, 1, border=2, flag=wx.ALL)
 103         parent.AddSpacer(wx.Size(8, 8), border=0, flag=wx.ALL)
 104         parent.AddWindow(self.contextHelpButton1, 1, border=2, flag=wx.ALL)
 105 
 106     def _init_coll_fgsmsg_Growables(self, parent):
 107         # generated method, don't edit
 108 
 109         parent.AddGrowableRow(0)
 110         parent.AddGrowableRow(1)
 111         parent.AddGrowableRow(2)
 112         parent.AddGrowableRow(3)
 113         parent.AddGrowableCol(0)
 114         parent.AddGrowableCol(1)
 115 
 116     def _init_coll_statusBar_Fields(self, parent):
 117         # generated method, don't edit
 118         parent.SetFieldsCount(1)
 119 
 120         parent.SetStatusText(number=0, text='')
 121 
 122         parent.SetStatusWidths([-1])
 123 
 124     def _init_sizers(self):
 125         # generated method, don't edit
 126         self.bsPage = wx.BoxSizer(orient=wx.VERTICAL)
 127 
 128         self.fgsmsg = wx.FlexGridSizer(cols=2, hgap=0, rows=0, vgap=0)
 129 
 130         self.fgsOther = wx.FlexGridSizer(cols=4, hgap=0, rows=0, vgap=0)
 131 
 132         self.fgsButtons = wx.FlexGridSizer(cols=0, hgap=0, rows=1, vgap=0)
 133 
 134         self._init_coll_bsPage_Items(self.bsPage)
 135         self._init_coll_fgsmsg_Items(self.fgsmsg)
 136         self._init_coll_fgsmsg_Growables(self.fgsmsg)
 137         self._init_coll_fgsOther_Items(self.fgsOther)
 138         self._init_coll_fgsButtons_Items(self.fgsButtons)
 139 
 140         self.SetSizer(self.bsPage)
 141 
 142     def _init_ctrls(self, prnt):
 143         # generated method, don't edit
 144         wx.Dialog.__init__(self, id=wxID_DIALOGERROR, name='DialogError',
 145               parent=prnt, pos=wx.Point(645, 213), size=wx.Size(846, 714),
 146               style=wx.DEFAULT_DIALOG_STYLE, title='Programming Error')
 147         self.SetClientSize(wx.Size(830, 678))
 148         self.Center(wx.BOTH)
 149         self.Bind(wx.EVT_CLOSE, self.OnDialogerrorClose)
 150 
 151         self.stMessage = wx.StaticText(id=wxID_DIALOGERRORSTMESSAGE,
 152               label='Message', name='stMessage', parent=self, pos=wx.Point(4,
 153               4), size=wx.Size(150, 51), style=0)
 154 
 155         self.message = wx.lib.masked.TextCtrl(id=wxID_DIALOGERRORMESSAGE,
 156               name='message', parent=self, pos=wx.Point(158, 4),
 157               size=wx.Size(668, 51), style=wx.TE_WORDWRAP | wx.TE_MULTILINE,
 158               value='')
 159 
 160         self.stStdLog = wx.StaticText(id=wxID_DIALOGERRORSTSTDLOG,
 161               label='Standard out log (display only):', name='stStdLog',
 162               parent=self, pos=wx.Point(4, 59), size=wx.Size(150, 180),
 163               style=0)
 164 
 165         self.stdoutlog = wx.TextCtrl(id=wxID_DIALOGERRORSTDOUTLOG,
 166               name='stdoutlog', parent=self, pos=wx.Point(158, 59),
 167               size=wx.Size(668, 180),
 168               style=wx.TE_READONLY | wx.TE_WORDWRAP | wx.TE_MULTILINE,
 169               value='')
 170 
 171         self.stErrLog = wx.StaticText(id=wxID_DIALOGERRORSTERRLOG,
 172               label='Standard error log (display only):', name='stErrLog',
 173               parent=self, pos=wx.Point(4, 243), size=wx.Size(150, 121),
 174               style=0)
 175 
 176         self.stderrlog = wx.TextCtrl(id=wxID_DIALOGERRORSTDERRLOG,
 177               name='stderrlog', parent=self, pos=wx.Point(158, 243),
 178               size=wx.Size(668, 121),
 179               style=wx.TE_READONLY | wx.TE_WORDWRAP | wx.TE_MULTILINE,
 180               value='')
 181 
 182         self.stSqlLog = wx.StaticText(id=wxID_DIALOGERRORSTSQLLOG,
 183               label='SQL log (display only):', name='stSqlLog', parent=self,
 184               pos=wx.Point(4, 368), size=wx.Size(150, 51), style=0)
 185 
 186         self.sqllog = wx.TextCtrl(id=wxID_DIALOGERRORSQLLOG, name='sqllog',
 187               parent=self, pos=wx.Point(158, 368), size=wx.Size(668, 51),
 188               style=wx.TE_READONLY | wx.TE_WORDWRAP | wx.TE_MULTILINE,
 189               value='')
 190 
 191         self.staticLine1 = wx.StaticLine(id=wxID_DIALOGERRORSTATICLINE1,
 192               name='staticLine1', parent=self, pos=wx.Point(2, 426),
 193               size=wx.Size(826, 2), style=0)
 194 
 195         self.stEmail = wx.StaticText(id=wxID_DIALOGERRORSTEMAIL,
 196               label='Your e-mail address:', name='stEmail', parent=self,
 197               pos=wx.Point(4, 438), size=wx.Size(95, 13), style=0)
 198 
 199         self.eMail = wx.lib.masked.TextCtrl(id=wxID_DIALOGERROREMAIL,
 200               name='eMail', parent=self, pos=wx.Point(161, 434),
 201               size=wx.Size(330, 22), style=0, value='')
 202 
 203         self.stSMTPServer = wx.StaticText(id=wxID_DIALOGERRORSTSMTPSERVER,
 204               label='Your SMTP server address:', name='stSMTPServer',
 205               parent=self, pos=wx.Point(4, 464), size=wx.Size(130, 13),
 206               style=0)
 207 
 208         self.smtpServer = wx.lib.masked.TextCtrl(id=wxID_DIALOGERRORSMTPSERVER,
 209               name='smtpServer', parent=self, pos=wx.Point(161, 460),
 210               size=wx.Size(330, 22), style=0, value='')
 211 
 212         self.smtpAuth = wx.CheckBox(id=wxID_DIALOGERRORSMTPAUTH,
 213               label='SMTP requires authorization', name='smtpAuth', parent=self,
 214               pos=wx.Point(4, 486), size=wx.Size(153, 13), style=0)
 215         self.smtpAuth.SetValue(False)
 216         self.smtpAuth.Bind(wx.EVT_CHECKBOX, self.OnSmtpAuthCheckbox,
 217               id=wxID_DIALOGERRORSMTPAUTH)
 218 
 219         self.stSMTPuser = wx.StaticText(id=wxID_DIALOGERRORSTSMTPUSER,
 220               label='SMTP user id', name='stSMTPuser', parent=self,
 221               pos=wx.Point(4, 507), size=wx.Size(61, 13), style=0)
 222 
 223         self.stPassword = wx.StaticText(id=wxID_DIALOGERRORSTPASSWORD,
 224               label='SMTP password', name='stPassword', parent=self,
 225               pos=wx.Point(495, 507), size=wx.Size(130, 13), style=0)
 226 
 227         self.smtpUser = wx.TextCtrl(id=wxID_DIALOGERRORSMTPUSER,
 228               name='smtpUser', parent=self, pos=wx.Point(161, 503),
 229               size=wx.Size(330, 21), style=0, value='')
 230         self.smtpUser.Enable(False)
 231 
 232         self.smtpPassword = wx.TextCtrl(id=wxID_DIALOGERRORSMTPPASSWORD,
 233               name='smtpPassword', parent=self, pos=wx.Point(629, 503),
 234               size=wx.Size(100, 21), style=wx.TE_PASSWORD, value='')
 235         self.smtpPassword.Enable(False)
 236 
 237         self.infoMsg = wx.TextCtrl(id=wxID_DIALOGERRORINFOMSG, name='infoMsg',
 238               parent=self, pos=wx.Point(2, 530), size=wx.Size(826, 88),
 239               style=wx.TE_MULTILINE | wx.TE_WORDWRAP | wx.TE_READONLY,
 240               value='')
 241 
 242         self.send = wx.Button(id=wxID_DIALOGERRORSEND, label='Send E-mail',
 243               name='send', parent=self, pos=wx.Point(4, 624), size=wx.Size(216,
 244               23), style=0)
 245         self.send.SetDefault()
 246         self.send.Bind(wx.EVT_BUTTON, self.OnSendButton,
 247               id=wxID_DIALOGERRORSEND)
 248 
 249         self.sendMAPI = wx.Button(id=wxID_DIALOGERRORSENDMAPI,
 250               label='Send using MAPI', name='sendMAPI', parent=self,
 251               pos=wx.Point(224, 624), size=wx.Size(216, 23), style=0)
 252         self.sendMAPI.Bind(wx.EVT_BUTTON, self.OnSendMAPIButton,
 253               id=wxID_DIALOGERRORSENDMAPI)
 254 
 255         self.cancel = wx.Button(id=wxID_DIALOGERRORCANCEL,
 256               label='Cancel and Close', name='close', parent=self,
 257               pos=wx.Point(662, 622), size=wx.Size(216, 23), style=0)
 258         self.cancel.Bind(wx.EVT_BUTTON, self.OnCancelButton,
 259               id=wxID_DIALOGERRORCANCEL)
 260 
 261         self.clear = wx.Button(id=wxID_DIALOGERRORCLEAR,
 262               label='Clear logs and Close', name='clear', parent=self,
 263               pos=wx.Point(444, 624), size=wx.Size(216, 23), style=0)
 264         self.clear.Bind(wx.EVT_BUTTON, self.OnClearButton,
 265               id=wxID_DIALOGERRORCLEAR)
 266 
 267         self.contextHelpButton1 = wx.ContextHelpButton(parent=self,
 268               pos=wx.Point(888, 624), size=wx.Size(20, 19),
 269               style=wx.BU_AUTODRAW)
 270 
 271         self.statusBar = wx.StatusBar(id=wxID_DIALOGERRORSTATUSBAR,
 272               name='statusBar', parent=self, style=0)
 273         self._init_coll_statusBar_Fields(self.statusBar)
 274 
 275         self._init_sizers()
 276 
 277     def __init__(self, parent):
 278         # None is passed as this is most often called from the wx.App
 279         self._init_ctrls(None)
 280 
 281         self.eMail.SetAutoformat('EMAIL')
 282         self.eMail.SetMask('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
 283         self.eMail.SetFormatcodes('F>')
 284         self.eMail.SetDescription('Email address')
 285         self.eMail.SetExcludeChars(' \\/*&%$#!+=\'"')
 286         self.eMail.SetValidRegex('^\\w+([\\-\\.]\\w+)*@((([a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*\\.)+)[a-zA-Z]{2,4}|\\[(\\d|\\d\\d|(1\\d\\d|2[0-4]\\d|25[0-5]))(\\.(\\d|\\d\\d|(1\\d\\d|2[0-4]\\d|25[0-5]))){3}\\]) *$')
 287         self.eMail.SetEmptyInvalid(True)
 288 
 289         self.smtpServer.SetEmptyInvalid(True)
 290         self.smtpServer.SetMask('X{50}')
 291 
 292         self.FixDefaultSize(self)
 293 ##        icon = myimages.getlogo32v1Icon()
 294 ##        self.SetIcon(icon)
 295         
 296         self.SetGetText()
 297         self.caller = parent
 298         
 299         self.msgtxt = self.caller.msg
 300         self.stdouttxt = self.caller.stdoutlog.read()
 301         self.stderrtxt = self.caller.stderrlog.read()
 302         self.sqllogtxt = self.caller.sqllog.read()
 303 
 304         self.message.WriteText(self.msgtxt)
 305         self.message.AppendText('\n\n') # some empty lines
 306         self.message.AppendText('Platform information:\n')
 307         self.message.AppendText(('System: %s\n') % platform.system())
 308         self.message.AppendText(('Release: %s\n') % platform.release())
 309         self.message.AppendText(('Version: %s\n') % platform.version())
 310         self.message.AppendText(('Machine: %s\n') % platform.machine())
 311         self.message.AppendText('Other:\n')
 312         self.message.AppendText(('Python version: %s, %s\n') % (platform.python_version(), platform.python_compiler()))
 313         self.message.AppendText(('wxPython version: %s\n') % wx.version())
 314 
 315         # db connection might not be available yet
 316         try:
 317             # getting license status from database
 318             #prefs = wx.GetApp().GetPrefs()
 319             #licenseYes = wx.GetApp().GetIt(prefs.owner, prefs.licensekey)
 320             licenseYes = True # fake the license status
 321             self.message.AppendText(('App version: %s-%s\n') % (__version__.appVERSION_STRING,
 322                                                              licenseYes))
 323         except:
 324             self.message.AppendText(('App version: %s-%s\n') % (__version__.appVERSION_STRING,
 325                                                                  'unknown'))
 326             
 327         self.message.AppendText('\n\n') # some empty lines
 328         
 329         self.stdoutlog.WriteText(self.stdouttxt)
 330         self.stderrlog.WriteText(self.stderrtxt)
 331         self.sqllog.WriteText(self.sqllogtxt)
 332         self.eMail.WriteText(self.caller.eMail)
 333         self.smtpServer.WriteText(self.caller.smtpServer)
 334         self.eMail.SetFocus()
 335         
 336         self.toaddr = eMailToAddr
 337         self.subject = eMailSubject
 338         
 339         self.Layout()
 340 
 341     def FixDefaultSize(self, window):
 342         if isinstance(window, wx.lib.masked.textctrl.TextCtrl):
 343             return
 344         window.SetMinSize(wx.DefaultSize)
 345         for child in window.GetChildren():
 346             self.FixDefaultSize(child)
 347         window.Layout()
 348         window.Refresh()
 349 
 350     def SetGetText(self):
 351         """Boa doesn't allow me to use _() directly, so I use SetLabel for
 352         each control to be translated, BUT this also has the advantage to be
 353         able to do dynamic switching of language by calling this function (not
 354         perfect as some controls don't allow setting labels after creation.
 355         """
 356         self.SetTitle(_('Programming error'))
 357 
 358         self.stMessage.SetLabel(_('Message'))
 359         self.message.SetToolTipString(_('Enter some additional information about the problem'))
 360         self.message.SetHelpText(_('Enter some additional information about the problem'))
 361         
 362         self.stStdLog.SetLabel(_('Standard out log (display only)'))
 363         self.stErrLog.SetLabel(_('Standard error log (display only)'))
 364         self.stSqlLog.SetLabel(_('SQL log (display only)'))
 365 
 366         self.stEmail.SetLabel(_('Your e-mail address'))
 367         self.eMail.SetToolTipString(_('Your e-mail address'))
 368         self.eMail.SetHelpText(_('Your e-mail address'))
 369 
 370         self.stSMTPServer.SetLabel(_('Your SMTPServer address'))
 371         self.smtpServer.SetToolTipString(_('Your SMTPServer address'))
 372         self.smtpServer.SetHelpText(_('Your SMTPServer address'))
 373         
 374         msgSMTP = _('A program error occured, please enter your e-mail address, your SMTP server name (e.g. smtp.free.fr), connect to the Internet and press the send e-mail button.')
 375         msgSMTP2 = _('If your SMTP server uses authorization enter the user id and password.')
 376         msgMAPI = _('Alternatively you can use the button "Send e-mail to support - MAPI" to send the email using your default email programme.')
 377         self.infoMsg.WriteText(msgSMTP + '\n\n' + msgSMTP2 + '\n\n' +msgMAPI)
 378 
 379         self.send.SetLabel(_('Send e-mail to support - SMTP'))
 380         self.send.SetToolTipString(_('Send e-mail to support - using SMTP server'))
 381         self.send.SetHelpText(_('Send e-mail to support - using SMTP server'))
 382 
 383         self.sendMAPI.SetLabel(_('Send e-mail to support - MAPI'))
 384         self.sendMAPI.SetToolTipString(_('Send e-mail to support - using MAPI'))
 385         self.sendMAPI.SetHelpText(_('Send e-mail to support - using MAPI'))
 386         
 387         self.clear.SetLabel(_('Clear logs and close dialog'))
 388         self.clear.SetToolTipString(_('Clear logs and close dialog.'))
 389         self.clear.SetHelpText(_('Clear logs and close dialog.'))
 390 
 391         self.cancel.SetLabel(_('Close dialog'))
 392         self.cancel.SetToolTipString(_('Close dialog - without clearing logs.'))
 393         self.cancel.SetHelpText(_('Close dialog - without clearing logs.'))
 394 
 395     def OnDialogerrorClose(self, event):
 396         event.Skip()
 397 
 398     def OnSendButton(self, event):
 399         self.statusBar.SetStatusText(number=0, text='')
 400         if not self.eMail.IsValid():
 401             self.statusBar.SetStatusText(number=0, text=_('Please enter a valid e-mail address'))
 402             return
 403         
 404         if not self.smtpServer.IsValid():
 405             self.statusBar.SetStatusText(number=0, text=_('Please enter a valid SMTP server address'))
 406             return
 407 
 408         self.caller.appConfig.Write(key='EMail', value=self.eMail.GetValue())
 409         self.caller.appConfig.Write(key='SMTPServer', value=self.smtpServer.GetValue())
 410         
 411         fromaddr, toaddr, mimemsg = self.PrepareMime()
 412         self.SendViaSMTP(fromaddr, toaddr, mimemsg)
 413 
 414     def PrepareMime(self):
 415         fromaddr = self.eMail.GetValue()
 416         
 417         mimemsg = MIMEMultipart()
 418         mimemsg['Subject'] = self.subject
 419         mimemsg['From'] = fromaddr
 420         mimemsg['To'] = self.toaddr
 421         mimemsg['CC'] = fromaddr
 422         mimemsg.preamble = self.subject
 423         mimemsg.epilogue = ''
 424     
 425         msg = MIMEText(self.message.GetValue())
 426         mimemsg.attach(msg)
 427         
 428         if len(self.stdouttxt) >0:
 429             stdout = MIMEText(self.stdouttxt)
 430             stdout.add_header('Content-Disposition', 'attachment', filename='stdout')
 431             mimemsg.attach(stdout)
 432             
 433         if len(self.stderrtxt) >0:
 434             stderr = MIMEText(self.stderrtxt)
 435             stderr.add_header('Content-Disposition', 'attachment', filename='stderr')
 436             mimemsg.attach(stderr)
 437             
 438         if len(self.sqllogtxt) >0:
 439             sqllog = MIMEText(self.sqllogtxt)
 440             sqllog.add_header('Content-Disposition', 'attachment', filename='sqllog')
 441             mimemsg.attach(sqllog)
 442 
 443         return fromaddr, self.toaddr, mimemsg
 444 
 445     def SendViaSMTP(self, fromaddr, toaddr, mimemsg):
 446         # Send the email via an SMTP server.
 447         try:
 448             s = smtplib.SMTP()
 449             s.connect(self.smtpServer.GetValue().strip())
 450             if self.smtpAuth.GetValue() == True:
 451                 # login to server
 452                 try:
 453                     s.login(self.smtpUser.GetValue(), self.smtpPassword.GetValue())
 454                 except smtplib.SMTPAuthenticationError:
 455                     self.statusBar.SetStatusText(number=0, text=_('SMTP authentication failed'))
 456                     return
 457             s.sendmail(fromaddr, toaddr, mimemsg.as_string())
 458             s.close()
 459             self.send.Enable(False)
 460             self.ClearAllFiles()
 461             self.statusBar.SetStatusText(number=0, text=_('Report was sent to support - thank you.'))
 462     
 463         except smtplib.SMTPServerDisconnected:
 464             self.statusBar.SetStatusText(number=0, text=_('SMTP server disconnected'))
 465     
 466         except smtplib.SMTPSenderRefused:
 467             self.statusBar.SetStatusText(number=0, text=_('Email address problem "From"'))
 468     
 469         except smtplib.SMTPRecipientsRefused:
 470             self.statusBar.SetStatusText(number=0, text=_('Email address problem "To"'))
 471                 
 472         except smtplib.SMTPDataError:
 473             self.statusBar.SetStatusText(number=0, text=_('Message data problem'))
 474             type, value, tb = sys.exc_info()
 475             for line in traceback.format_exception_only(type, value):
 476                 print line
 477     
 478         except smtplib.SMTPConnectError:
 479             self.statusBar.SetStatusText(number=0, text=_('SMTP could not establish connection'))
 480             type, value, tb = sys.exc_info()
 481             for line in traceback.format_exception_only(type, value):
 482                 print line
 483     
 484         except smtplib.socket.gaierror:
 485             self.statusBar.SetStatusText(number=0, text=_('SMTP server address problems - are you connected to the internet?'))
 486     
 487         except:
 488             self.statusBar.SetStatusText(number=0, text=_('SMTP - unknown error'))
 489             type, value, tb = sys.exc_info()
 490             for line in traceback.format_exception_only(type, value):
 491                 print line
 492 
 493     def OnCancelButton(self, event):
 494         self.caller.appConfig.Write(key='EMail', value=self.eMail.GetValue())
 495         self.caller.appConfig.Write(key='SMTPServer', value=self.smtpServer.GetValue())
 496         self.Close()
 497 
 498     def OnClearButton(self, event):
 499         self.ClearAllFiles()
 500         self.Close()
 501         
 502     def ClearAllFiles(self):
 503         self.caller.sqllog.truncate(0)
 504         self.caller.stderrlog.truncate(0)
 505         self.caller.stdoutlog.truncate(0)
 506 
 507         self.caller.sqllog.seek(0)
 508         self.caller.stderrlog.seek(0)
 509         self.caller.stdoutlog.seek(0)
 510 
 511     def OnSendMAPIButton(self, event):
 512         self.statusBar.SetStatusText(number=0, text='')
 513         
 514         if platform.system() != 'Windows':
 515             self.statusBar.SetStatusText(number=0, text=_('Option only supported on Windows OS!'))
 516             return
 517         if not self.eMail.IsValid():
 518             self.statusBar.SetStatusText(number=0, text=_('Please enter a valid e-mail address'))
 519             return
 520         
 521         self.caller.appConfig.Write(key='EMail', value=self.eMail.GetValue())
 522         self.caller.appConfig.Write(key='SMTPServer', value=self.smtpServer.GetValue())
 523         # TODO: maybe update smtp auth stuff into config
 524 
 525         # simplemapi
 526         recipient = [(1, self.toaddr)]
 527         files = []
 528 
 529         if len(self.stdouttxt) >0:
 530             files.append(self.caller.stdoutlog.name)
 531         if len(self.stderrtxt) >0:
 532             files.append(self.caller.stderrlog.name)
 533         if len(self.sqllogtxt) >0:
 534             files.append(self.caller.sqllog.name)
 535 
 536         attachment = files
 537         subject = '%s' % self.subject
 538         body = '%s' % self.message.GetValue()
 539 
 540         try:
 541             simplemapi.SendMail(recipient, subject, body, attachment)
 542             self.sendMAPI.Enable(False)
 543             self.ClearAllFiles()
 544         except WindowsError, (errmsg, ):
 545             # ignore logon failure and abort errors
 546             if errmsg != 'MAPI error 3' and errmsg != 'MAPI error 1':
 547                 raise
 548 
 549     def OnSmtpAuthCheckbox(self, event):
 550         obj = event.GetEventObject()
 551         if obj.GetValue() == True:
 552             self.smtpPassword.Enable(True)
 553             self.smtpUser.Enable(True)
 554         else:
 555             self.smtpPassword.Enable(False)
 556             self.smtpUser.Enable(False)
 557         event.Skip()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-10-04 09:16:02, 0.2 KB) [[attachment:__version__.py]]
  • [get | view] (2009-10-04 09:16:02, 24.5 KB) [[attachment:dialogerror.py]]
  • [get | view] (2009-10-04 09:16:02, 6.4 KB) [[attachment:errorDiagTestApp.py]]
  • [get | view] (2009-10-04 09:16:02, 2.9 KB) [[attachment:errorDiagTestF.py]]
  • [get | view] (2009-10-04 09:16:02, 52.6 KB) [[attachment:errorDialog.zip]]
  • [get | view] (2009-10-04 09:16:02, 6.3 KB) [[attachment:simplemapi.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.