Update of /cvsroot/py2exe/py2exe/sandbox/py2exe
In directory sc8-pr-cvs1:/tmp/cvs-serv28162/py2exe
Modified Files:
boot_service.py build_exe.py
Log Message:
Restructure the way services are hosted. Drop any service specific
executables, and move all logic to the service boot script.
Index: boot_service.py
===================================================================
RCS file: /cvsroot/py2exe/py2exe/sandbox/py2exe/boot_service.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** boot_service.py 16 Sep 2003 08:50:52 -0000 1.3
--- boot_service.py 16 Oct 2003 07:52:52 -0000 1.4
***************
*** 1,15 ****
# boot_service.py
import sys
# We assume that py2exe has magically set service_module_names
# to the module names that expose the services we host.
! service_modules = []
try:
for name in service_module_names:
! __import__(name)
! service_modules.append(sys.modules[name])
except NameError:
print "This script is designed to be run from inside py2exe"
sys.exit(1)
- del name
! # nothing more to do!
--- 1,52 ----
# boot_service.py
import sys
+ import os
+ import servicemanager
+ import win32serviceutil
# We assume that py2exe has magically set service_module_names
# to the module names that expose the services we host.
! service_klasses = []
try:
for name in service_module_names:
! mod = __import__(name)
! for ob in mod.__dict__.values():
! if hasattr(ob, "_svc_name_"):
! service_klasses.append(ob)
except NameError:
print "This script is designed to be run from inside py2exe"
sys.exit(1)
! if not service_klasses:
! raise RuntimeError, "No service classes found"
!
! # Event source records come from servicemanager
! evtsrc_dll = os.path.abspath(servicemanager.__file__)
!
! # Tell the Python servicemanager what classes we host.
! if len(service_klasses)==1:
! k = service_klasses[0]
! # One service - make the event name the same as the service.
! servicemanager.Initialize(k._svc_name_, evtsrc_dll)
! # And the class that hosts it.
! servicemanager.PrepareToHostSingle(k)
! else:
! # Multiple services (NOTE - this hasn't been tested!)
! # Use the base name of the exe as the event source
! servicemanager.Initialize(os.path.basename(sys.executable), evtsrc_dll)
! for k in service_klasses:
! servicemanager.PrepareToHostMultiple(k._svc_name_, k)
!
! # Simulate the old py2exe command line handling (to some extent)
! # This could do with some re-thought, although it still isn't clear to
! # MarkH that win32serviceutil command line options are appropriate here.
! if len(sys.argv)>1 and sys.argv[1]=="-install":
! for k in service_klasses:
! svc_display_name = getattr(k, "_svc_display_name_", k._svc_name_)
! win32serviceutil.InstallService(None, k._svc_name_, svc_display_name,
! exeName = sys.executable)
! elif len(sys.argv)>1 and sys.argv[1]=="-remove":
! for k in service_klasses:
! win32serviceutil.RemoveService(k._svc_name_)
! else:
! print "Connecting to the Service Control Manager"
! servicemanager.StartServiceCtrlDispatcher()
Index: build_exe.py
===================================================================
RCS file: /cvsroot/py2exe/py2exe/sandbox/py2exe/build_exe.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** build_exe.py 8 Oct 2003 11:54:14 -0000 1.32
--- build_exe.py 16 Oct 2003 07:52:52 -0000 1.33
***************
*** 299,303 ****
all_files.append(dst)
for target in dist.service:
! dst = self.build_service(target, "run_svc.exe", arcname)
all_files.append(dst)
--- 299,304 ----
all_files.append(dst)
for target in dist.service:
! # Note: we may want to give the user the option of using run_w.exe
! dst = self.build_service(target, "run.exe", arcname)
all_files.append(dst)
***************
*** 394,418 ****
vars = {"service_module_names" : target.modules}
boot = self.get_boot_script("service")
! exe_path = self.build_executable(target, template, arcname, boot, vars)
!
! # and the service specific resources.
! from resources.StringTables import StringTable, RT_STRING
! # resource id in the EXE of the serviceclass,
! # see source/PythonService.cpp
! RESOURCE_SERVICE_NAME = 1016
!
! st = StringTable()
! klass_name, svc_name, svc_display_name, svc_deps = \
! self.get_service_names(module_name)
! st.add_string(RESOURCE_SERVICE_NAME,
! "%s.%s" % (module_name, klass_name))
! st.add_string(RESOURCE_SERVICE_NAME+1, svc_name)
! st.add_string(RESOURCE_SERVICE_NAME+2, svc_display_name)
! # XXX service probably won't have a | in them?
! st.add_string(RESOURCE_SERVICE_NAME+3, "|".join(svc_deps))
! for id, data in st.binary():
! add_resource(exe_path, data, RT_STRING, id, 0)
!
! return exe_path
def build_executable(self, target, template, arcname, script, vars={}):
--- 395,399 ----
vars = {"service_module_names" : target.modules}
boot = self.get_boot_script("service")
! return self.build_executable(target, template, arcname, boot, vars)
def build_executable(self, target, template, arcname, script, vars={}):
***************
*** 624,635 ****
"Carbon.Folder", "Carbon.Folders",
]
- # If services are built, do not complain that servicemanager is missing.
- # It is a builtin module in run_service.exe!
- #
- # XXX Is it better to exclude it here, or to remove it
- # from the missing list afterwards?
- if self.distribution.service:
- self.excludes.append("servicemanager")
-
# special dlls which must be copied to the exe_dir, not the lib_dir
names = "python pywintypes pythoncom".split()
--- 605,608 ----
|