[Spambayes-checkins] spambayes/spambayes Options.py, 1.100, 1.101 hammiebulk.py, 1.11, 1.12

Tony Meyer anadelonbrin at users.sourceforge.net
Mon Jan 12 03:36:17 EST 2004


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

Modified Files:
	Options.py hammiebulk.py 
Log Message:
Well, it's been some time, and no-one disagreed, and three people liked the idea,
so here it is.

MAY BREAK THINGS!

>From now, path/file options are not relative to the current working directory,
they are relative to the last configuration file loaded.  This still defaults to the
current working directory (except on Windows with win32all, where it's still
the User Application Data directory).  So this should mean no noticeable change,
unless your last configuration file is not in the current working directory, and
your data is.

Index: Options.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/Options.py,v
retrieving revision 1.100
retrieving revision 1.101
diff -C2 -d -r1.100 -r1.101
*** Options.py	12 Jan 2004 06:49:37 -0000	1.100
--- Options.py	12 Jan 2004 08:36:15 -0000	1.101
***************
*** 1159,1162 ****
--- 1159,1173 ----
              try:
                  from win32com.shell import shell, shellcon
+             except ImportError:
+                 # We are on Windows, with no BAYESCUSTOMIZE set, no ini file
+                 # in the current directory, and no win32 extensions installed
+                 # to locate the "user" directory - seeing things are so lamely
+                 # setup, it is worth printing a warning
+                 print >>sys.stderr, "NOTE: We can not locate an INI file " \
+                       "for SpamBayes, and the Python for Windows extensions " \
+                       "are not installed, meaning we can't locate your " \
+                       "'user' directory.  An empty configuration file at " \
+                       "'%s' will be used." % optionsPathname.encode('mbcs')
+             else:
                  windowsUserDirectory = os.path.join(
                          shell.SHGetFolderPath(0,shellcon.CSIDL_APPDATA,0,0),
***************
*** 1165,1168 ****
--- 1176,1183 ----
                      if not os.path.isdir(windowsUserDirectory):
                          os.makedirs(windowsUserDirectory)
+                 except os.error:
+                     # unable to make the directory - stick to default.
+                     pass
+                 else:
                      optionsPathname = os.path.join(windowsUserDirectory,
                                                     'bayescustomize.ini')
***************
*** 1172,1209 ****
                      if os.path.exists(optionsPathname):
                          options.merge_file(optionsPathname)
!                     else:
!                         # If the file doesn't exist, then let's get the user to
!                         # store their databases and caches here as well, by
!                         # default, and save the file.
!                         db_name = os.path.join(windowsUserDirectory,
!                                                "statistics_database.db")
!                         mi_db = os.path.join(windowsUserDirectory,
!                                                "message_info_database.db")
!                         h_cache = os.path.join(windowsUserDirectory,
!                                                "ham_cache").encode("mbcs")
!                         u_cache = os.path.join(windowsUserDirectory,
!                                                "unknown_cache").encode("mbcs")
!                         s_cache = os.path.join(windowsUserDirectory,
!                                                "spam_cache").encode("mbcs")
!                         options["Storage", "spam_cache"] = s_cache
!                         options["Storage", "ham_cache"] = h_cache
!                         options["Storage", "unknown_cache"] = u_cache
!                         options["Storage", "persistent_storage_file"] = \
!                                            db_name.encode("mbcs")
!                         options["Storage", "messageinfo_storage_file"] = \
!                                            mi_db.encode("mbcs")
!                         options.update_file(optionsPathname)
!                 except os.error:
!                     # unable to make the directory - stick to default.
!                     pass
!             except ImportError:
!                 # We are on Windows, with no BAYESCUSTOMIZE set, no ini file
!                 # in the current directory, and no win32 extensions installed
!                 # to locate the "user" directory - seeing things are so lamely
!                 # setup, it is worth printing a warning
!                 print "NOTE: We can not locate an INI file for SpamBayes, and the"
!                 print "Python for Windows extensions are not installed, meaning we"
!                 print "can't locate your 'user' directory.  An empty configuration"
!                 print "file at '%s' will be used." % optionsPathname.encode('mbcs')
  
  # Ideally, we should not create the objects at import time - but we have
--- 1187,1198 ----
                      if os.path.exists(optionsPathname):
                          options.merge_file(optionsPathname)
! 
! def get_pathname_option(section, option):
!     """Return the option relative to the path specified in the
!     gloabl optionsPathname, unless it is already an absolute path."""
!     filename = os.path.expanduser(options.get(section, option))
!     if os.path.isabs(filename):
!         return filename
!     return os.path.join(os.path.dirname(optionsPathname), filename)
  
  # Ideally, we should not create the objects at import time - but we have

Index: hammiebulk.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/hammiebulk.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** hammiebulk.py	9 Oct 2003 03:04:48 -0000	1.11
--- hammiebulk.py	12 Jan 2004 08:36:15 -0000	1.12
***************
*** 52,56 ****
  import getopt
  
! from spambayes.Options import options
  from spambayes import classifier, mboxutils, hammie, Corpus
  
--- 52,56 ----
  import getopt
  
! from spambayes.Options import options, get_pathname_option
  from spambayes import classifier, mboxutils, hammie, Corpus
  
***************
*** 60,70 ****
  
  # Default database name
- DEFAULTDB = os.path.expanduser(options["Storage", "persistent_storage_file"])
  # This is a bit of a hack to counter the default for
  # persistent_storage_file changing from ~/.hammiedb to hammie.db
  # This will work unless a user had hammie.db as their value for
  # persistent_storage_file
! if DEFAULTDB == options.default("Storage", "persistent_storage_file"):
!     DEFAULTDB = os.path.expanduser(os.path.join("~", ".hammiedb"))
  
  # Probability at which a message is considered spam
--- 60,72 ----
  
  # Default database name
  # This is a bit of a hack to counter the default for
  # persistent_storage_file changing from ~/.hammiedb to hammie.db
  # This will work unless a user had hammie.db as their value for
  # persistent_storage_file
! if options["Storage", "persistent_storage_file"] == \
!    options.default("Storage", "persistent_storage_file"):
!     options["Storage", "persistent_storage_file"] = \
!                        os.path.join("~", ".hammiedb"))
! DEFAULTDB = get_pathname_option("Storage", "persistent_storage_file")
  
  # Probability at which a message is considered spam





More information about the Spambayes-checkins mailing list