[Spambayes-checkins] spambayes/Outlook2000 config.py, 1.24, 1.25 config_wizard.py, 1.2, 1.3 filter.py, 1.29, 1.30 manager.py, 1.73, 1.74 train.py, 1.29, 1.30

Mark Hammond mhammond at users.sourceforge.net
Sat Aug 23 21:05:18 EDT 2003


Update of /cvsroot/spambayes/spambayes/Outlook2000
In directory sc8-pr-cvs1:/tmp/cvs-serv28936

Modified Files:
	config.py config_wizard.py filter.py manager.py train.py 
Log Message:
Explicitly pass the 'config' object around the dialogs, and lots
of Wizard work.  The wizard pretty much is now fully functional (but only
via test_dialogs.py)


Index: config.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/config.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** config.py	21 Aug 2003 13:08:48 -0000	1.24
--- config.py	24 Aug 2003 03:05:15 -0000	1.25
***************
*** 278,281 ****
--- 278,285 ----
      def __setattr__(self, attr, val):
          raise AttributeError, "No section [%s]" % attr
+     # and delegate a few methods so this object can be used in place of
+     # a real options object. maybe should add this to getattr. do we want all?
+     def get_option(self, section, name):
+         return self._options.get_option(section, name)
  
  def CreateConfig(defaults=defaults):

Index: config_wizard.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/config_wizard.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** config_wizard.py	22 Aug 2003 06:12:38 -0000	1.2
--- config_wizard.py	24 Aug 2003 03:05:15 -0000	1.3
***************
*** 2,5 ****
--- 2,6 ----
  import config
  import copy
+ import os
  
  # NOTE: The Wizard works from a *complete* copy of the standard options
***************
*** 29,36 ****
              """""",
              "", config.RESTORE),
      ),
  }
  
! def InitWizardConfig(manager, new_config, from_existing = True):
      new_config.filter.watch_folder_ids = []
      new_config.filter.watch_include_sub = False
--- 30,39 ----
              """""",
              "", config.RESTORE),
+         ("temp_training_names", "", [], "", "", config.RESTORE),
      ),
  }
  
! def InitWizardConfig(manager, new_config, from_existing):
!     manager.wizard_classifier_data = None # this is hacky
      new_config.filter.watch_folder_ids = []
      new_config.filter.watch_include_sub = False
***************
*** 45,49 ****
      if not new_config.filter.watch_folder_ids:
          for folder in manager.message_store.YieldReceiveFolders():
!             new_config.train.watch_folder_ids.append(folder.GetID())
      if from_existing:
          fc = manager.config.filter
--- 48,52 ----
      if not new_config.filter.watch_folder_ids:
          for folder in manager.message_store.YieldReceiveFolders():
!             new_config.filter.watch_folder_ids.append(folder.GetID())
      if from_existing:
          fc = manager.config.filter
***************
*** 59,63 ****
                  wc.unsure_folder_name = ""
          tc = manager.config.training
-         print "Ham are", tc.ham_folder_ids
          if tc.ham_folder_ids:
              new_config.training.ham_folder_ids = tc.ham_folder_ids
--- 62,65 ----
***************
*** 67,74 ****
          wc.preparation = 1 # "already prepared"
  
  def CommitWizardConfig(manager, wc):
!     pass
  
! def CreateWizardConfig(manager):
      import config
      defaults = wizard_defaults.copy()
--- 69,118 ----
          wc.preparation = 1 # "already prepared"
  
+ def _CreateFolder(manager, name, comment):
+     try:
+         root = manager.message_store.GetRootFolder()
+         new_folder = root.CreateFolder(name, comment, open_if_exists = True)
+         return new_folder
+     except:
+         msg = "There was an error creating the folder named '%s'\r\n" \
+                 "Please restart Outlook and try again" % name
+         manager.ReportError(msg)
+         return None
+     
  def CommitWizardConfig(manager, wc):
!     # Create the ham and spam folders, if necessary.
!     manager.config.filter.watch_folder_ids = wc.filter.watch_folder_ids
!     if wc.filter.spam_folder_id:
!         manager.config.filter.spam_folder_id = wc.filter.spam_folder_id
!     else:
!         assert wc.wizard.spam_folder_name, "No ID, and no name!!!"
!         f = _CreateFolder(manager, wc.wizard.spam_folder_name, "contains spam filtered by SpamBayes")
!         manager.config.filter.spam_folder_id = f.GetID()
!     if wc.filter.unsure_folder_id:
!         manager.config.filter.unsure_folder_id = wc.filter.unsure_folder_id
!     else:
!         assert wc.wizard.unsure_folder_name, "No ID, and no name!!!"
!         f = _CreateFolder(manager, wc.wizard.unsure_folder_name, "contains messages SpamBayes is uncertain about")
!         manager.config.filter.unsure_folder_id = f.GetID()
  
!     wiz_cd = manager.wizard_classifier_data
!     manager.wizard_classifier_data = None
!     if wiz_cd:
!         manager.classifier_data.Adopt(wiz_cd)
!     manager.config.filter.enabled = True
! 
! def CancelWizardConfig(manager, wc):
!     if manager.wizard_classifier_data:
!         manager.wizard_classifier_data.Close()
!         manager.wizard_classifier_data = None
!     # Cleanup temp files that may have been created.
!     for fname in wc.wizard.temp_training_names:
!         if os.path.exists(fname):
!             try:
!                 os.remove(fname)
!             except OSError:
!                 print "Warning: unable to remove", fname
! 
! def CreateWizardConfig(manager, from_existing):
      import config
      defaults = wizard_defaults.copy()
***************
*** 76,80 ****
      options = config.CreateConfig(defaults)
      cfg = config.OptionsContainer(options)
!     InitWizardConfig(manager, cfg)
!     return options, cfg
   
--- 120,124 ----
      options = config.CreateConfig(defaults)
      cfg = config.OptionsContainer(options)
!     InitWizardConfig(manager, cfg, from_existing)
!     return cfg
   

Index: filter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/filter.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** filter.py	13 Aug 2003 13:41:27 -0000	1.29
--- filter.py	24 Aug 2003 03:05:15 -0000	1.30
***************
*** 95,100 ****
          return "Failed"
  
! def filter_folder(f, mgr, progress):
!     config = mgr.config.filter_now
      only_unread = config.only_unread
      only_unseen = config.only_unseen
--- 95,99 ----
          return "Failed"
  
! def filter_folder(f, mgr, config, progress):
      only_unread = config.only_unread
      only_unseen = config.only_unseen
***************
*** 122,127 ****
  
  # Called for "filter now"
! def filterer(mgr, progress):
!     config = mgr.config.filter_now
      if not config.folder_ids:
          progress.error("You must specify at least one folder")
--- 121,126 ----
  
  # Called for "filter now"
! def filterer(mgr, config, progress):
!     config = config.filter_now
      if not config.folder_ids:
          progress.error("You must specify at least one folder")
***************
*** 136,140 ****
      for f in mgr.message_store.GetFolderGenerator(config.folder_ids, config.include_sub):
          progress.set_status("Filtering folder '%s'" % (f.name))
!         this_dispositions = filter_folder(f, mgr, progress)
          for key, val in this_dispositions.items():
              dispositions[key] = dispositions.get(key, 0) + val
--- 135,139 ----
      for f in mgr.message_store.GetFolderGenerator(config.folder_ids, config.include_sub):
          progress.set_status("Filtering folder '%s'" % (f.name))
!         this_dispositions = filter_folder(f, mgr, config, progress)
          for key, val in this_dispositions.items():
              dispositions[key] = dispositions.get(key, 0) + val

Index: manager.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/manager.py,v
retrieving revision 1.73
retrieving revision 1.74
diff -C2 -d -r1.73 -r1.74
*** manager.py	22 Aug 2003 06:12:20 -0000	1.73
--- manager.py	24 Aug 2003 03:05:15 -0000	1.74
***************
*** 758,765 ****
          import dialogs
          # Need to get the plugin hwnd
!         dialogs.ShowDialog(0, self, "IDD_MANAGER")
          # And re-save now, just incase Outlook dies on the way down.
          self.SaveConfig()
!         
      def ShowHtml(self,url):
          """Displays the main SpamBayes documentation in your Web browser"""
--- 758,765 ----
          import dialogs
          # Need to get the plugin hwnd
!         dialogs.ShowDialog(0, self, self.config, "IDD_MANAGER")
          # And re-save now, just incase Outlook dies on the way down.
          self.SaveConfig()
! 
      def ShowHtml(self,url):
          """Displays the main SpamBayes documentation in your Web browser"""

Index: train.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/train.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** train.py	22 Aug 2003 06:12:20 -0000	1.29
--- train.py	24 Aug 2003 03:05:16 -0000	1.30
***************
*** 125,130 ****
  
  # Called back from the dialog to do the actual training.
! def trainer(mgr, progress):
!     config = mgr.config
      rebuild = config.training.rebuild
      rescore = config.training.rescore
--- 125,129 ----
  
  # Called back from the dialog to do the actual training.
! def trainer(mgr, config, progress):
      rebuild = config.training.rebuild
      rescore = config.training.rescore





More information about the Spambayes-checkins mailing list