[Spambayes-checkins] spambayes/spambayes UserInterface.py,1.3,1.4

Tim Stone timstone4 at users.sourceforge.net
Mon Apr 21 15:15:55 EDT 2003


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

Modified Files:
	UserInterface.py 
Log Message:
Cosmetic changes to configuration page

Index: UserInterface.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/UserInterface.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** UserInterface.py	20 Apr 2003 09:41:15 -0000	1.3
--- UserInterface.py	21 Apr 2003 21:15:52 -0000	1.4
***************
*** 73,76 ****
--- 73,77 ----
  import cgi
  import mailbox
+ import types
  
  import PyMeldLite
***************
*** 204,208 ****
      """Serves the HTML user interface."""
  
!     def __init__(self, bayes, config_parms=()):
          """Load up the necessary resources: ui.html and helmet.gif."""
          global classifier
--- 205,209 ----
      """Serves the HTML user interface."""
  
!     def __init__(self, bayes, config_parms=[], config_display=[]):
          """Load up the necessary resources: ui.html and helmet.gif."""
          global classifier
***************
*** 210,213 ****
--- 211,215 ----
          classifier = bayes
          self.parm_ini_map = config_parms
+         self.display = config_display
  
      def onClassify(self, file, text, which):
***************
*** 376,384 ****
  
          # Loop though the sections.
!         for sect, opt in self.parm_ini_map:
!             # We need a string to use as the html key that we can change to
!             # and from the sect, opt pair.  We like irony, so we use '_' as
!             # the delimiter <wink>
!             if opt is None:
                  if configTable is not None and section is not None:
                      # Finish off the box for this section and add it
--- 378,383 ----
  
          # Loop though the sections.
!         for html_key in self.display:
!             if not self.parm_ini_map.has_key(html_key):
                  if configTable is not None and section is not None:
                      # Finish off the box for this section and add it
***************
*** 395,398 ****
--- 394,398 ----
                  configCbRow1 = configTable.configCbRow1.clone()
                  configRow2 = configTable.configRow2.clone()
+                 configTextRow2 = configTable.configTextRow2.clone()
                  blankRow = configTable.blankRow.clone()
                  del configTable.configTextRow1
***************
*** 400,408 ****
                  del configTable.configRow2
                  del configTable.blankRow
!                 del configTable.folderRow
!                 section.heading = sect
                  del section.iconCell
                  continue
!             html_key = sect + '_' + opt
  
              # Populate the rows with the details and add them to the table.
--- 400,407 ----
                  del configTable.configRow2
                  del configTable.blankRow
!                 section.heading = html_key
                  del section.iconCell
                  continue
!             (sect, opt) = self.parm_ini_map[html_key]
  
              # Populate the rows with the details and add them to the table.
***************
*** 427,433 ****
                      if options.is_boolean(sect, opt):
                          if str(val) == "0":
!                             val = "False"
                          elif str(val) == "1":
!                             val = "True"
                      newOption.val_label = str(val)
                      if options.multiple_values_allowed(sect, opt):
--- 426,432 ----
                      if options.is_boolean(sect, opt):
                          if str(val) == "0":
!                             val = "Yes"
                          elif str(val) == "1":
!                             val = "No"
                      newOption.val_label = str(val)
                      if options.multiple_values_allowed(sect, opt):
***************
*** 450,468 ****
                                       cgi.escape(options.doc(sect, opt))
  
-             newConfigRow2 = configRow2.clone()
              currentValue = options[sect, opt]
              # for Python 2.2
              if options.is_boolean(sect, opt):
                  if str(currentValue) == '0':
!                     currentValue = "False"
                  elif str(currentValue) == '1':
!                     currentValue = "True"
!             # XXX Something needs to be done here, otherwise really
!             # XXX long options squeeze the help text too far to the
!             # XXX right.  Browsers can't wrap the text (even if
!             # XXX no-wrap is False) unless there is whitespace to
!             # XXX wrap on - comma's don't count.  This works, but
!             # XXX it's a bit ugly.  Ideas?
!             # currentValue = str(currentValue).replace(',', '<br />')
              newConfigRow2.currentValue = currentValue
              configTable += newConfigRow1 + newConfigRow2 + blankRow
--- 449,466 ----
                                       cgi.escape(options.doc(sect, opt))
  
              currentValue = options[sect, opt]
+ 
+             if type(currentValue) in types.StringTypes and \
+                 str(currentValue) not in (0,1):
+                 currentValue = currentValue.replace(',', ', ')
+                 newConfigRow2 = configTextRow2.clone()
+             else:
+                 newConfigRow2 = configRow2.clone()
              # for Python 2.2
              if options.is_boolean(sect, opt):
                  if str(currentValue) == '0':
!                     currentValue = "Yes"
                  elif str(currentValue) == '1':
!                     currentValue = "No"
              newConfigRow2.currentValue = currentValue
              configTable += newConfigRow1 + newConfigRow2 + blankRow
***************
*** 478,483 ****
  
      def onChangeopts(self, **parms):
-         if parms.has_key("how"):
-             del parms["how"]
          html = self.html.clone()
          html.shutdownTableCell = "&nbsp;"
--- 476,479 ----
***************
*** 494,501 ****
  
          for name, value in parms.items():
!             print name, value
!             sect, opt = name.split('_', 1)
!             if (sect, opt) in self.parm_ini_map:
!                 options.set(sect, opt, value)
  
          op = open(optionsPathname, "r")
--- 490,496 ----
  
          for name, value in parms.items():
!            if self.parm_ini_map.has_key(name):
!                sect, opt = self.parm_ini_map[name]
!                options.set(sect, opt, value)
  
          op = open(optionsPathname, "r")
***************
*** 530,534 ****
          '''Check that the given input is valid.'''
          # Most of the work here is done by the options class, but
!         # we may have a few extra checks that are beyond its capabilities
          errmsg = ''
  
--- 525,529 ----
          '''Check that the given input is valid.'''
          # Most of the work here is done by the options class, but
!         # we have a few extra checks that are beyond its capabilities
          errmsg = ''
  
***************
*** 544,552 ****
                  del parms[name]
  
!         for sect, opt in self.parm_ini_map:
!             if opt is None:
!                 nice_section_name = sect
                  continue
!             html_key = sect + '_' + opt
              if not parms.has_key(html_key):
                  # This is a set of checkboxes where none are selected
--- 539,547 ----
                  del parms[name]
  
!         for html_key in self.display:
!             if not self.parm_ini_map.has_key(html_key):
!                 nice_section_name = html_key
                  continue
!             sect, opt = self.parm_ini_map[html_key]
              if not parms.has_key(html_key):
                  # This is a set of checkboxes where none are selected
***************
*** 560,564 ****
                          value_string += val
                          value_string += ','
!                     value = value_string[:-1]   # remove trailing comma
                  value = options.convert(sect, opt, value)
              if not options.is_valid(sect, opt, value):
--- 555,559 ----
                          value_string += val
                          value_string += ','
!                     value = value_string[:-1]
                  value = options.convert(sect, opt, value)
              if not options.is_valid(sect, opt, value):
***************
*** 574,577 ****
--- 569,606 ----
              parms[html_key] = value
  
+         # check for equal number of pop3servers and ports
+         slist = parms['p3servers'].split(',')
+         plist = parms['p3ports'].split(',')
+         if len(slist) != len(plist):
+             errmsg += '<li>The number of POP3 proxy ports specified ' + \
+                       'must match the number of servers specified</li>\n'
+ 
+         # check for duplicate ports
+         plist.sort()
+         for p in range(len(plist)-1):
+             try:
+                 if plist[p] == plist[p+1]:
+                     errmsg += '<li>All POP3 port numbers must be unique</li>'
+                     break
+             except IndexError:
+                 pass
+ 
+         # check for equal number of smtpservers and ports
+         slist = parms['smtpservers'].split(',')
+         plist = parms['smtpports'].split(',')
+         if len(slist) != len(plist):
+             errmsg += '<li>The number of SMTP proxy ports specified ' + \
+                       'must match the number of servers specified</li>\n'
+ 
+         # check for duplicate ports
+         plist.sort()
+         for p in range(len(plist)-1):
+             try:
+                 if plist[p] == plist[p+1]:
+                     errmsg += '<li>All SMTP port numbers must be unique</li>'
+                     break
+             except IndexError:
+                 pass
+ 
          return errmsg
  
***************
*** 586,593 ****
  
          # Only restore the settings that appear on the form.
!         for section, option in self.parm_ini_map:
!             if option is not None:
!                 if not options.no_restore(section, option):
!                     options.set(section, option, c.get(section,option))
  
          op = open(optionsPathname, "r")
--- 615,621 ----
  
          # Only restore the settings that appear on the form.
!         for section, option in self.parm_ini_map.values():
!             if not options.no_restore(section, option):
!                 options.set(section, option, c.get(section,option))
  
          op = open(optionsPathname, "r")





More information about the Spambayes-checkins mailing list