[Spambayes-checkins] spambayes/scripts sb_imapfilter.py,1.57,1.58

Tony Meyer anadelonbrin at users.sourceforge.net
Thu Apr 21 09:09:12 CEST 2005


Update of /cvsroot/spambayes/spambayes/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7311/scripts

Modified Files:
	sb_imapfilter.py 
Log Message:
Move __future__ import to correct place.

Add [ 1182703 ] sb_imapfilter binary should output to log

This only takes effect when frozen, but hopefully the scheme will work even if there exists a frozen sb_imapfilter for *nix one day.

Index: sb_imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_imapfilter.py,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** sb_imapfilter.py	6 Apr 2005 02:48:33 -0000	1.57
--- sb_imapfilter.py	21 Apr 2005 07:09:09 -0000	1.58
***************
*** 48,51 ****
--- 48,53 ----
  """
  
+ from __future__ import generators
+ 
  todo = """
      o IMAP supports authentication via other methods than the plain-text
***************
*** 69,74 ****
                "much to isbg by Roger Binns (http://www.rogerbinns.com/isbg)."
  
- from __future__ import generators
- 
  try:
      True, False
--- 71,74 ----
***************
*** 77,85 ****
      True, False = 1, 0
  
! import socket
  import os
  import re
  import time
- import sys
  import getopt
  import types
--- 77,133 ----
      True, False = 1, 0
  
! # If we are running as a frozen application, then chances are that
! # output is just lost.  We'd rather log this, like sb_server and Oulook
! # log, so that the user can pull up the output if possible.  We could just
! # rely on the user piping the output appropriately, but would rather have
! # more control.  The sb_server tray application only does this if not
! # running in a console window, but we do it whenever we are frozen.
  import os
+ import sys
+ if hasattr(sys, "frozen"):
+     # We want to move to logging module later, so for now, we
+     # hack together a simple logging strategy.
+     try:
+         import win32api
+     except ImportError:
+         if sys.platform == "win32":
+             # Fall back to CWD, but warn user.
+             status = "Warning: your log is stored in the current " \
+                      "working directory.  We recommend installing " \
+                      "the pywin32 extensions, so that the log is " \
+                      "stored in the Windows temp directory."
+             temp_dir = os.getcwd()
+         else:
+             # Try for a /tmp directory.
+             if os.path.isdir("/tmp"):
+                 temp_dir = "/tmp"
+                 status = "Log file opened in /tmp"
+             else:
+                 status = "Warning: your log is stored in the current " \
+                          "working directory.  If this does not suit you " \
+                          "please let the spambayes at python.org crowd know " \
+                          "so that an alternative can be arranged."
+     else:
+         temp_dir = win32api.GetTempPath()
+         status = "Log file opened in " + temp_dir
+     for i in range(3,0,-1):
+         try:
+             os.unlink(os.path.join(temp_dir, "SpamBayesIMAP%d.log" % (i+1)))
+         except os.error:
+             pass
+         try:
+             os.rename(
+                 os.path.join(temp_dir, "SpamBayesIMAP%d.log" % i),
+                 os.path.join(temp_dir, "SpamBayesIMAP%d.log" % (i+1))
+                 )
+         except os.error:
+             pass
+     # Open this log, as unbuffered, so crashes still get written.
+     sys.stdout = open(os.path.join(temp_dir,"SpamBayesIMAP1.log"), "wt", 0)
+     sys.stderr = sys.stdout
+ 
+ import socket
  import re
  import time
  import getopt
  import types



More information about the Spambayes-checkins mailing list