PythonWin -- COM server won't change???

  • Thread starter U-CDK_CHARLES\\Charles
  • Start date
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)
 
S

Steve Holden

U-CDK_CHARLES\Charles said:
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.
Well, for example, if it's currently mapped into a process you'll have
to somehow get that process to reload() the module. I can't remember
offhand what the default is, btu I know that the only way I can pick up
a re-registered object under IIS is to have a web page import and then
reload() the module that the COM server is defined in. Kinda yucky, but
it works, don't know whether it'll help you.

regards
Steve
 
U

U-CDK_CHARLES\\Charles

Well, for example, if it's currently mapped into a process you'll have
to somehow get that process to reload() the module. I can't remember
offhand what the default is, btu I know that the only way I can pick up
a re-registered object under IIS is to have a web page import and then
reload() the module that the COM server is defined in. Kinda yucky, but
it works, don't know whether it'll help you.

AH!! . . Exactly!!

I was invoking it from a VB program, and changed it while my program was
open in the IDE.

All is well.

Thanx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,242
Latest member
KendrickKo

Latest Threads

Top