[Spambayes-checkins] spambayes dbExpImp.py,1.2,1.3

Tim Stone timstone4 at users.sourceforge.net
Sat Feb 1 11:07:12 EST 2003


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

Modified Files:
	dbExpImp.py 
Log Message:
Cleaned up and added some informational messages.

Index: dbExpImp.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/dbExpImp.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** dbExpImp.py	1 Feb 2003 17:57:04 -0000	1.2
--- dbExpImp.py	1 Feb 2003 19:07:10 -0000	1.3
***************
*** 92,96 ****
  from __future__ import generators
  
! import storage
  from spambayes.Options import options
  import sys, os, getopt, errno, re
--- 92,96 ----
  from __future__ import generators
  
! import spambayes.storage
  from spambayes.Options import options
  import sys, os, getopt, errno, re
***************
*** 99,109 ****
  def runExport(dbFN, useDBM, outFN):
  
-     print "running export on %s" % (dbFN)
      if useDBM:
!         bayes = storage.DBDictClassifier(dbFN)
          words = bayes.db.keys()
          words.remove(bayes.statekey)
      else:
!         bayes = storage.PickledClassifier(dbFN)
          words = bayes.wordinfo.keys()
  
--- 99,108 ----
  def runExport(dbFN, useDBM, outFN):
  
      if useDBM:
!         bayes = spambayes.storage.DBDictClassifier(dbFN)
          words = bayes.db.keys()
          words.remove(bayes.statekey)
      else:
!         bayes = spambayes.storage.PickledClassifier(dbFN)
          words = bayes.wordinfo.keys()
  
***************
*** 116,120 ****
      nham = bayes.nham;
      nspam = bayes.nspam;
!     print "nham %s, nspam %s" % (nham, nspam)
      
      fp.write("%s,%s,\n" % (nham, nspam))
--- 115,122 ----
      nham = bayes.nham;
      nspam = bayes.nspam;
!     
!     print "Exporting database %s to file %s" % (dbFN, outFN)
!     print "Database has %s ham, %s spam, and %s words" \
!             % (nham, nspam, len(words))
      
      fp.write("%s,%s,\n" % (nham, nspam))
***************
*** 138,145 ****
                  raise
                  
      if useDBM:
!         bayes = storage.DBDictClassifier(dbFN)
      else:
!         bayes = storage.PickledClassifier(dbFN)
  
      try:
--- 140,159 ----
                  raise
                  
+         try:
+             os.unlink(dbFN+".dat")
+         except OSError, e:
+             if e.errno != 2:     # errno.<WHAT>
+                 raise
+                 
+         try:
+             os.unlink(dbFN+".dir")
+         except OSError, e:
+             if e.errno != 2:     # errno.<WHAT>
+                 raise
+                 
      if useDBM:
!         bayes = spambayes.storage.DBDictClassifier(dbFN)
      else:
!         bayes = spambayes.storage.PickledClassifier(dbFN)
  
      try:
***************
*** 150,154 ****
      
      nline = fp.readline()
-     print nline
      (nham, nspam, junk) = re.split(',', nline)
   
--- 164,167 ----
***************
*** 160,163 ****
--- 173,183 ----
          bayes.nspam += nspam
      
+     if newDBM:
+         impType = "Importing"
+     else:
+         impType = "Merging"
+   
+     print "%s database %s using file %s" % (impType, dbFN, inFN)
+ 
      lines = fp.readlines()
      
***************
*** 177,181 ****
--- 197,216 ----
  
      fp.close()
+ 
+     print "Storing database, please be patient.  Even moderately large"
+     print "databases may take a very long time to store."
      bayes.store()
+     print "Finished storing database"
+     
+     if useDBM:
+         words = bayes.db.keys()
+         words.remove(bayes.statekey)
+     else:
+         words = bayes.wordinfo.keys()
+         
+     print "Database has %s ham, %s spam, and %s words" \
+            % (bayes.nham, bayes.nspam, len(words))
+ 
+ 
  
  





More information about the Spambayes-checkins mailing list