~sproaty/whyteboard/development

« back to all changes in this revision

Viewing changes to whyteboard/gui/dialogs.py

  • Committer: Steven Sproat
  • Date: 2012-02-12 22:40:10 UTC
  • Revision ID: sproaty@gmail.com-20120212224010-fhjru933n799u1ai
add logs to reporting bug email; sorting out logging for release, validate email on bug report/suggest to provide email if blank

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from whyteboard.lib import BaseErrorDialog, icon, pub
39
39
import whyteboard.tools as tools
40
40
 
 
41
from whyteboard.core import LogRemembererHandler
41
42
from whyteboard.updater import Updater
42
43
from whyteboard.misc import meta
43
44
from whyteboard.misc import (get_home_dir, bitmap_button, fix_std_sizer_tab_order, 
751
752
        BaseErrorDialog.__init__(self, None, title=_("Error Report"), message=msg)
752
753
        self.SetDescriptionLabel(_("An error has occured - please report it"))
753
754
        self.gui = wx.GetTopLevelWindows()[0]
 
755
        self.email_prompted = False
754
756
 
755
757
    def Abort(self):
756
758
        if isinstance(self.gui, ErrorDialog):
763
765
        Need to stick in extra information: preferences, helps with debugging
764
766
        """
765
767
        info = super(ErrorDialog, self).GetEnvironmentInfo()
766
 
 
767
768
        path = os.path.join(get_home_dir(), u"user.pref")
 
769
        
768
770
        if os.path.exists(path):
769
771
            info.append(u"#---- Preferences ----#")
770
772
            with open(path) as f:
772
774
                    preference = preference.rstrip()
773
775
                    info.append(unicode(preference, "utf-8"))
774
776
            info.append(u"")
775
 
            info.append(u"")
 
777
            
776
778
        return os.linesep.join(info)
777
779
 
778
780
    def GetProgramName(self):
779
781
        return u"Whyteboard %s" % meta.version
780
 
 
781
 
 
 
782
    
782
783
    def Send(self):
783
784
        """Send the error report. PHP script calls isset($_POST['submitted'])"""
 
785
        if not self.email_prompted:
 
786
            self.check_email()
 
787
        
784
788
        params = urlencode({'submitted': 'fgdg',
785
789
                            'message': self._panel.err_msg,
786
790
                            'desc': self._panel.action.GetValue(),
787
 
                            'email': self._panel.email.GetValue()})
 
791
                            'email': self._panel.email.GetValue(),
 
792
                            'log': self.get_logs()})
 
793
        
788
794
        f = urlopen(u"http://www.whyteboard.org/bug_submit.php", params)
789
795
 
790
796
        self.gui.prompt_for_save(self.Close)
791
797
 
792
 
 
 
798
    def get_logs(self):
 
799
        logcontents = [x for x in LogRemembererHandler().get_logs()]
 
800
        # last log is stacktrace...
 
801
        return os.linesep.join(logcontents[:-1])  
 
802
 
 
803
    def check_email(self):
 
804
        email = self._panel.email.GetValue()
 
805
        
 
806
        if len(email) < 5:
 
807
            dlg = self.prompt_for_email(email)
 
808
    
 
809
            if dlg.ShowModal() == wx.ID_CANCEL:
 
810
                dlg.Destroy()
 
811
                self.email_prompted = True
 
812
                return False
 
813
            else:
 
814
                valid = self.validate_email(email)
 
815
                
 
816
                while not valid:
 
817
                    if dlg.ShowModal() == wx.ID_CANCEL:
 
818
                        dlg.Destroy()
 
819
                        self.email_prompted = True
 
820
                        return False
 
821
                    new_email = dlg.GetValue()
 
822
                    dlg.Destroy()
 
823
                    if not self.validate_email(new_email):
 
824
                        wx.MessageBox("Please enter a valid email address")
 
825
                        dlg = self.prompt_for_email(new_email)
 
826
                    else:
 
827
                        valid = True
 
828
                    
 
829
                self._panel.email.SetValue(new_email)
 
830
                return True
 
831
            
 
832
        if not self.validate_email(email):
 
833
            wx.MessageBox("Please enter a valid email address")
 
834
            return False
 
835
 
 
836
    def prompt_for_email(self, email):
 
837
        dlg = wx.TextEntryDialog(self, _("You have not given your email address. Providing it can help fix bugs"),
 
838
                                 _("No email address:")) 
 
839
        dlg.SetValue(email)    
 
840
        return dlg
 
841
                    
 
842
    def validate_email(self, email):
 
843
        """
 
844
        http://www.daniweb.com/software-development/python/code/280071
 
845
        """
 
846
        sep = [x for x in email if not x.isalpha()]
 
847
        sepjoined = ''.join(sep)
 
848
        ## sep joined must be ..@.... form
 
849
        if sepjoined.strip('.') != '@': 
 
850
            return False
 
851
        end = email
 
852
        for i in sep:
 
853
            part, i, end = end.partition(i)
 
854
            if len(part) < 2:
 
855
                return False
 
856
        return True
793
857
 #----------------------------------------------------------------------
794
858
 
795
859
def ExceptionHook(exctype, value, trace):