[Zope-dev] Zopeservice and sitecustomize
Sake
sakesun at boonthavorn.com
Mon Mar 8 20:54:54 EST 2004
Hi,
I have Zope and Activestate Python installed together in the same win-xp
machine. Everything works fine until I've learned that I can put
"sys.setdefaultencoding('cp874')" into sitecustomize.py to accomodate my
native language coding. Since I do that, my Zope 2.7.0 service can no
longer start. I can start it manually from "runzope.bat", but it never
start through the windows system service. A full day investigation
reveal that the trouble cause by the missing of the
'<SOFTWARE_HOME>\lib\python' in the system environment's "PYTHONPATH".
The "runzope.bat" set that up before then execution of
"Zope.Startup.run.py", hence it run fine. But "zopeservice.py" rely on
the "<SOFTWARE_HOME>\bin\Lib\site-packages\sitecustomize.py" to set up
the correct "PYTHONPATH". Here is the code inside Zope's sitecustomize.py
""" Add Zope packages in Windows binary distro to sys.path automagically """
import sys
import os
try:
sp = __file__
except:
sp = None
if sp:
dn = os.path.dirname
swhome = os.path.join(dn(dn(dn(dn(sp)))), 'lib', 'python')
if os.path.exists(swhome):
sys.path.insert(0, swhome)
Unluckily, this sitecustomize.py is now masked with my sitecustomize.py
inside Activestate's site-package directory, which actually get loaded
by Zope via the Python registry load path
(HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.3\PythonPath) instead
of the expected one.
I don't think setting up PYTHONPATH inside sitecustomize.py is a good
idea. Better keep this mechanism for site specific problems. I'd rather
insert a line into zopeservice.py like this.
import os.path
from os.path import dirname as dn
import sys
# these are replacements from mkzopeinstance
PYTHONW = r'C:\Zope-2.7.0\bin\pythonw.exe'
SOFTWARE_HOME=r'C:\Zope-2.7.0\lib\python'
INSTANCE_HOME = r'C:\Zope-MIB'
ZOPE_HOME = r'C:\Zope-2.7.0'
ZOPE_RUN = r'%s\Zope\Startup\run.py' % SOFTWARE_HOME
CONFIG_FILE= os.path.join(INSTANCE_HOME, 'etc', 'zope.conf')
PYTHONSERVICE_EXE=r'%s\bin\PythonService.exe' % ZOPE_HOME
sys.path.insert(0, SOFTWARE_HOME)
os.environ['PYTHONPATH'] = SOFTWARE_HOME <---------------- inserted line
from nt_svcutils.service import Service
servicename = 'Zope_%s' % str(hash(INSTANCE_HOME))
class InstanceService(Service):
start_cmd = '"%s" "%s" -C "%s"' % (PYTHONW, ZOPE_RUN, CONFIG_FILE)
_svc_name_ = servicename
_svc_display_name_ = 'Zope instance at %s' % INSTANCE_HOME
_exe_name_ = PYTHONSERVICE_EXE
if __name__ == '__main__':
import win32serviceutil
win32serviceutil.HandleCommandLine(InstanceService)
This is much more palatable in my opinion.
More information about the Zope-Dev
mailing list