[Spambayes-checkins] spambayes/windows pop3proxy_service.py, 1.11,
1.12
Mark Hammond
mhammond at users.sourceforge.net
Tue Sep 16 10:01:49 EDT 2003
Update of /cvsroot/spambayes/spambayes/windows
In directory sc8-pr-cvs1:/tmp/cvs-serv1252
Modified Files:
pop3proxy_service.py
Log Message:
Only munge sys.path in source-code versions, and as the service starts,
have it report the username and ini file it is using.
In binary builds, write a log to %temp%\SpamBayesServicen.log
Index: pop3proxy_service.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/windows/pop3proxy_service.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** pop3proxy_service.py 9 Sep 2003 01:26:16 -0000 1.11
--- pop3proxy_service.py 16 Sep 2003 14:01:47 -0000 1.12
***************
*** 18,45 ****
import sys, os
! # We are in the 'spambayes\win32' directory. We
! # need the parent on sys.path, so 'spambayes.spambayes' is a package,
! # and 'pop3proxy' is a module
try:
! # module imported by service manager, or 2.3 (in which __main__
! # exists, *and* sys.argv[0] is always already absolute)
! this_filename=__file__
! except NameError:
! this_filename = sys.argv[0]
! if not os.path.isabs(sys.argv[0]):
! # Python 2.3 __main__
! # patch up sys.argv, as our cwd will confuse service registration code
! sys.argv[0] = os.path.abspath(sys.argv[0])
! this_filename = sys.argv[0]
! print sys.argv[0]
! sb_dir = os.path.dirname(os.path.dirname(this_filename))
! sb_scripts_dir = os.path.join(sb_dir,"scripts")
! sys.path.insert(0, sb_dir)
! sys.path.insert(-1, sb_scripts_dir)
! # and change directory here, so pop3proxy uses the default
! # config file etc
! os.chdir(sb_dir)
# Rest of the standard Python modules we use.
--- 18,76 ----
import sys, os
!
! # Messages from pop3proxy will go nowhere when executed as a service
! # Try and detect that print will go nowhere and redirect.
! # redirect output somewhere useful when running as a service.
! import win32api
try:
! win32api.GetConsoleTitle()
! except win32api.error:
! # No console - if we are running from Python sources,
! # redirect to win32traceutil, but if running from a binary
! # install, redirect to a log file.
! # Want to move to logging module later, so for now, we
! # hack together a simple logging strategy.
! if hasattr(sys, "frozen"):
! temp_dir = win32api.GetTempPath()
! for i in range(3,0,-1):
! try: os.unlink(os.path.join(temp_dir, "SpamBayesService%d.log" % (i+1)))
! except os.error: pass
! try:
! os.rename(
! os.path.join(temp_dir, "SpamBayesService%d.log" % i),
! os.path.join(temp_dir, "SpamBayesService%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,"SpamBayesService1.log"), "wt", 0)
! sys.stderr = sys.stdout
! else:
! import win32traceutil
! # If running from sources, patch up sys.path
! if not hasattr(sys, "frozen"):
! # We are in the 'spambayes\win32' directory. We
! # need the parent on sys.path, so 'spambayes.spambayes' is a package,
! # and 'pop3proxy' is a module
! try:
! # module imported by service manager, or 2.3 (in which __main__
! # exists, *and* sys.argv[0] is always already absolute)
! this_filename=__file__
! except NameError:
! this_filename = sys.argv[0]
! if not os.path.isabs(sys.argv[0]):
! # Python 2.3 __main__
! # patch up sys.argv, as our cwd will confuse service registration code
! sys.argv[0] = os.path.abspath(sys.argv[0])
! this_filename = sys.argv[0]
! sb_dir = os.path.dirname(os.path.dirname(this_filename))
! sb_scripts_dir = os.path.join(sb_dir,"scripts")
!
! sys.path.insert(0, sb_dir)
! sys.path.insert(-1, sb_scripts_dir)
! # and change directory here, so pop3proxy uses the default
! # config file etc
! os.chdir(sb_dir)
# Rest of the standard Python modules we use.
***************
*** 54,75 ****
import win32serviceutil, win32service
import pywintypes, win32con, winerror
-
from ntsecuritycon import *
- # Messages from pop3proxy will go nowhere when executed as a service
- # Try and detect that print will go nowhere and redirect.
- try:
- # redirect output somewhere useful when running as a service.
- import win32api
- try:
- win32api.GetConsoleTitle()
- except win32api.error:
- # no console - import win32traceutil
- import win32traceutil
- print "popproxy service module loading (as user %s)..." \
- % win32api.GetUserName()
- except ImportError:
- pass
-
class Service(win32serviceutil.ServiceFramework):
# The script name was changed to "sb_server" but I'll leave this as pop3proxy
--- 85,90 ----
***************
*** 88,92 ****
self.event_stopping.set()
sb_server.stop(sb_server.state)
-
def SvcDoRun(self):
--- 103,106 ----
***************
*** 101,109 ****
# Write an event log record - in debug mode we will also
# see this message printed.
import servicemanager
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
! (self._svc_name_, '')
)
--- 115,127 ----
# Write an event log record - in debug mode we will also
# see this message printed.
+ from spambayes.Options import optionsPathname
+ extra = " as user '%s', using config file '%s'" \
+ % (win32api.GetUserNameEx(2).encode("mbcs"),
+ optionsPathname.encode("mbcs"))
import servicemanager
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
! (self._svc_name_, extra)
)
More information about the Spambayes-checkins
mailing list