U
U-CDK_CHARLES\\Charles
List:
I made a small change to a COM server under PythonWin.
I unregistered, then reregistered the server.
But the old version is still being invoked.
Did I miss a step:
Code follows.
Thanx
Charles
# cbLogger.py -- This logs messages to the specified file
# Originally simpleLogger.py. It's supposed to be
# more object oriented than the original
#
# This is modeled after SimpleCOMServer.py, from "Python Win32
# Programming" By Hammond and Robinson
from time import ctime
from time import time
class cbLogger:
defaultLogFile = r'C:\loggerTests\testLog.log'
def __init__(self, fileName = defaultLogFile, visible = 'no'):
# I'm hoping we can open the file . . maybe
try:
self.logFile = file(fileName, 'a')
except IOError:
self.logFile = None
# Any other exception is a fatal error,
# so we don't handle them.
# Good News! We've succeeded!
else:
self.__call__(self.__class__.__name__, \
'Log opened successfully')
def __del__(self):
self.__call__(self.__class__.__name__, 'Closing log file.')
self.logFile.close()
self.logFile = None
def logShow(self):
return 0
def __call__(self, caller = 'Unknown Caller', \
message = 'Unknown Message'):
self.logFile.write(ctime(time()) + ' <' + caller \
+ '> -- ' + message + '\n')
return 0
class cbCOMLogger:
# Wraps cbLogger in a COM object
# Note this is a kludge. It's the same as the wrapped class, but
# not sure how to make it so without copying it into a unicode
# string
defaultLogFile = u'C:\\loggerTests\\testLog.log'
_public_methods_ = ['open', 'close', 'logEntry', 'show']
_reg_progid_ = 'cbLogger.logServer'
# NEVER copy the following ID
# Use "print pythoncom.CreateGuid()" to make a new one
_reg_clsid_ = "{4BBB5C62-C460-43C5-82A4-52FD373A7D2A}"
def __init__(self):
self.fileOpen = False
def open(self, fileName = defaultLogFile, visible = u'no'):
if self.fileOpen == False:
self.__Logger = cbLogger(str(fileName), str(visible))
self.fileOpen = True
return 0
else:
return -1
def close(self):
if self.fileOpen == True:
del self.__Logger
self.fileOpen = False
return 0
def logShow(self):
return 0
def logEntry(self, caller = u'Unknown Caller', \
message = u'Unknown Message'):
if self.fileOpen == True:
return self.__Logger(str(caller), str(message))
else:
return -1
def __del__(self):
if self.fileOpen == True:
self.close()
return 0
# Add code so that when this script is run by
# Python.exe, it self-registers.
if __name__=='__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(cbCOMLogger)
I made a small change to a COM server under PythonWin.
I unregistered, then reregistered the server.
But the old version is still being invoked.
Did I miss a step:
Code follows.
Thanx
Charles
# cbLogger.py -- This logs messages to the specified file
# Originally simpleLogger.py. It's supposed to be
# more object oriented than the original
#
# This is modeled after SimpleCOMServer.py, from "Python Win32
# Programming" By Hammond and Robinson
from time import ctime
from time import time
class cbLogger:
defaultLogFile = r'C:\loggerTests\testLog.log'
def __init__(self, fileName = defaultLogFile, visible = 'no'):
# I'm hoping we can open the file . . maybe
try:
self.logFile = file(fileName, 'a')
except IOError:
self.logFile = None
# Any other exception is a fatal error,
# so we don't handle them.
# Good News! We've succeeded!
else:
self.__call__(self.__class__.__name__, \
'Log opened successfully')
def __del__(self):
self.__call__(self.__class__.__name__, 'Closing log file.')
self.logFile.close()
self.logFile = None
def logShow(self):
return 0
def __call__(self, caller = 'Unknown Caller', \
message = 'Unknown Message'):
self.logFile.write(ctime(time()) + ' <' + caller \
+ '> -- ' + message + '\n')
return 0
class cbCOMLogger:
# Wraps cbLogger in a COM object
# Note this is a kludge. It's the same as the wrapped class, but
# not sure how to make it so without copying it into a unicode
# string
defaultLogFile = u'C:\\loggerTests\\testLog.log'
_public_methods_ = ['open', 'close', 'logEntry', 'show']
_reg_progid_ = 'cbLogger.logServer'
# NEVER copy the following ID
# Use "print pythoncom.CreateGuid()" to make a new one
_reg_clsid_ = "{4BBB5C62-C460-43C5-82A4-52FD373A7D2A}"
def __init__(self):
self.fileOpen = False
def open(self, fileName = defaultLogFile, visible = u'no'):
if self.fileOpen == False:
self.__Logger = cbLogger(str(fileName), str(visible))
self.fileOpen = True
return 0
else:
return -1
def close(self):
if self.fileOpen == True:
del self.__Logger
self.fileOpen = False
return 0
def logShow(self):
return 0
def logEntry(self, caller = u'Unknown Caller', \
message = u'Unknown Message'):
if self.fileOpen == True:
return self.__Logger(str(caller), str(message))
else:
return -1
def __del__(self):
if self.fileOpen == True:
self.close()
return 0
# Add code so that when this script is run by
# Python.exe, it self-registers.
if __name__=='__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(cbCOMLogger)