[python-win32] Problems with py2exe and COM
Giles A. Radford
moof at metamoof.net
Mon Dec 29 14:01:49 EST 2003
OK, I'm obviously having a bad day, cos I can't seem to get this to
work. I feel this is lack of understanding on my part, cos I can't find
much documentation on the win32com modules - is there a secret
documentation stash that I'm missing?
I'm trying to create a DLL with some COM classes that update some websites
with certain details.
The problem I have is that I manage to get py2exe to compile the
program (with a few warnigns about classes refrred to that just don't
exist - I don't have Carbon.Folders for instance), but when I try to
register the DLL with regsvr32.exe, I get back a message which said
(paraphrased from spanish) "Error in DllRegisterServer in webupdate.dll
- Returned a code: 0x80040201".
I have no idea what this means. I've been fiddling wiht it all day, and
I'm tired of it now. The fact that I can seem to find no documentation
on the process, and what it's suppsed to do. Also, if I try to compile
the py2exe with --debug I end up with a rather abstruse and
impossible-to-decypher error:
...
creating build\bdist.win32\winexe\collect\webupdater\Scripts.py2exe
Traceback (most recent call last):
File "C:\Documents and Settings\Moof\Mis documentos\Partner\WebUpdater\setup.p
y", line 13, in ?
scripts=['webupdater'],
File "C:\PYTHON23\lib\distutils\core.py", line 149, in setup
dist.run_commands()
File "C:\PYTHON23\lib\distutils\dist.py", line 907, in run_commands
self.run_command(cmd)
File "C:\PYTHON23\lib\distutils\dist.py", line 927, in run_command
cmd_obj.run()
File "C:\PYTHON23\Lib\site-packages\py2exe\build_exe.py", line 698, in run
extra_path + sys.path)
File "C:\PYTHON23\Lib\site-packages\py2exe\build_exe.py", line 842, in find_de
pendend_dlls
alldlls, warnings = bin_depends(loadpath, images)
File "C:\PYTHON23\Lib\site-packages\py2exe\build_exe.py", line 1154, in bin_de
pends
for result in py2exe_util.depends(image, loadpath).items():
py2exe_util.bind_error: C:\PYTHON23\lib\site-packages\py2exe\run_dll_d.dll
I really don't know what I'm doing here. I can't work out from the
source what's supposed to be happening, so I'm at a bit of a loss.
Anyway, can anyone help me work out where I'm goign wrong? or at least
shed some light as to where I can find out?
Here's some of my code, though I've had to keep the site update stuff
out for clarity. I've liberally peppered it with "what does this
actually _do_?"-style comments, and any elucidation you could provide
would be welcome.
__init.py__
-----------
import sys
import pythoncom
if hasattr(sys, 'importers'):
# we are running as py2exe-packed executable
pythoncom.frozen = 1
from win32com.server.util import wrap
import Site1
#For release, debugging=False
debugging = True
if debugging:
from win32com.server.dispatcher import DefaultDebugDispatcher
useDispatcher = DefaultDebugDispatcher
else:
useDispatcher = None
class UpdaterFactory:
"""Stores a directory of possible instances, and returns instances
of the appropriate class when requested to"""
# I found this bit in a random python-list post. I have no idea what
# it does.
_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
_reg_progid_ = 'Foo.UpdaterFactory'
_reg_clsid_ = '{3F3AF37A-59BB-XXXX-A2C4-07D5D3B11FE4}'
_public_methods_ = ['getUpdater',]
_public_attributes_ = ['sites']
#Eventually will have interesting stuff here which lists each
#appropriate class in a number of modules
directory = {'site1': Site1.Site1Updater,
'site2': Site1.Site2Updater}
sites = directory.keys()
def getUpdater(self, site):
"""Will return an instance of a class that will update the
desired website
@param site the site name as a string. Should be in
UpdaterFactory.sites
@raises COMException DISP_E_UKNOWNNAME if the site is
unknown
"""
if site in directory:
return wrap(diectory[site](), useDispatcher=useDispatcher)
else:
import winerror
from win32com.server.exception import COMException
raise COMException("Unknown or Unsupported Site",
winerror.DISP_E_UNKNOWNNAME)
def register():
print "Registering WebUpdater..."
import win32com.server.register
win32com.server.register.UseCommandLine(UpdaterFactory,
debug=debugging)
def unregister():
print "Unregistering WebUpdater..."
import win32com.server.register
win32com.server.register.UnregisterClasses(UpdaterFactory)
if __name__ == '__main__':
if hasattr(sys, 'importers'):
if '--register' in sys.argv[1:]:
register()
elif '--unregister' in sys.argv[1:]:
unregister()
else:
#I don't understand what this does, if anything.
from win32com.server import localserver
localserver.main()
else:
register()
Site1.py
--------
import socket
socket.setdefaulttimeout(60)
import winerror
from win32com.server.exception import COMException
import urllib, urllib2
from mx import DateTime
class Site1Updater:
_public_methods_ = ['update']
_readonly_attrs_ = ['name', 'settings']
name = "site1"
settings = [('usuario', u'Usuario', 'string'),
('passwd', u'Contrase\xf1a', 'string')]
_public_attrs_ = _readonly_attrs_ + [x[0] for x in settings]
def __init__(self):
self.product = 3
def update(self, from_, to_, num):
pass #elided for clarity
class Site2Updater(Site1Updater):
name="site2"
def __init__(self):
Site1Updater.__init__(self)
self.product=1
Setup.py
--------
from distutils.core import setup
import py2exe
setup(name="WebUpdater",
version="0.2",
description="WebUpdater",
author="Giles Antonio Radford",
author_email="moof at metamoof.net",
packages=['webupdater'],
scripts=['webupdater'],
)
More information about the Python-win32
mailing list