[pywin32-checkins] pywin32/win32/Lib win32serviceutil.py,1.23,1.24
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2006-01-10 00:18:32
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26887 Modified Files: win32serviceutil.py Log Message: * If you tried to debug a service and pass it arguments, after the service terminated the usage() message would be printed. * Allow for py2exe services that don't explicitly specify the executable name default to using the current executable. * Allow for service debug mode to work in a py2exe service. * Drop the "to Python class mod.klass" in the install string. Index: win32serviceutil.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32serviceutil.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** win32serviceutil.py 24 Oct 2005 06:17:54 -0000 1.23 --- win32serviceutil.py 10 Jan 2006 00:18:24 -0000 1.24 *************** *** 13,16 **** --- 13,20 ---- def LocatePythonServiceExe(exeName = None): + if not exeName and hasattr(sys, "frozen"): + # If py2exe etc calls this with no exeName, default is current exe. + return sys.executable + # Try and find the specified EXE somewhere. If specifically registered, # use it. Otherwise look down sys.path, and the global PATH environment. *************** *** 421,424 **** --- 425,457 ---- print "Gave up waiting for the old service to stop!" + def _DebugCtrlHandler(evt): + if evt in (win32con.CTRL_C_EVENT, win32con.CTRL_BREAK_EVENT): + assert g_debugService + print "Stopping debug service." + g_debugService.SvcStop() + return True + return False + + def DebugService(cls, argv = []): + # Run a service in "debug" mode. Re-implements what pythonservice.exe + # does when it sees a "-debug" param. + # Currently only used by "frozen" (ie, py2exe) programs (but later may + # end up being used for all services should we ever remove + # pythonservice.exe) + import servicemanager + global g_debugService + + print "Debugging service %s - press Ctrl+C to stop." % (cls._svc_name_,) + servicemanager.Debugging(True) + servicemanager.PrepareToHostSingle(cls) + g_debugService = cls(argv) + # Setup a ctrl+c handler to simulate a "stop" + win32api.SetConsoleCtrlHandler(_DebugCtrlHandler, True) + try: + g_debugService.SvcRun() + finally: + win32api.SetConsoleCtrlHandler(_DebugCtrlHandler, False) + servicemanager.Debugging(False) + g_debugService = None def GetServiceClassString(cls, argv = None): *************** *** 554,568 **** elif arg=="debug": knownArg = 1 ! svcArgs = string.join(args[1:]) ! exeName = LocateSpecificServiceExe(serviceName) ! try: ! os.system("%s -debug %s %s" % (exeName, serviceName, svcArgs)) ! # ^C is used to kill the debug service. Sometimes Python also gets ! # interrupted - ignore it... ! except KeyboardInterrupt: ! pass ! if len(args)<>1: ! usage() if arg=="install": --- 587,608 ---- elif arg=="debug": knownArg = 1 ! if not hasattr(sys, "frozen"): ! # non-frozen services use pythonservice.exe which handles a ! # -debug option ! svcArgs = string.join(args[1:]) ! exeName = LocateSpecificServiceExe(serviceName) ! try: ! os.system("%s -debug %s %s" % (exeName, serviceName, svcArgs)) ! # ^C is used to kill the debug service. Sometimes Python also gets ! # interrupted - ignore it... ! except KeyboardInterrupt: ! pass ! else: ! # py2exe services don't use pythonservice - so we simulate ! # debugging here. ! DebugService(cls, args) ! if not knownArg and len(args)<>1: ! usage() # the rest of the cmds don't take addn args if arg=="install": *************** *** 584,588 **** except AttributeError: description = None ! print "Installing service %s to Python class %s" % (serviceName,serviceClassString) # Note that we install the service before calling the custom option # handler, so if the custom handler fails, we have an installed service (from NT's POV) --- 624,628 ---- except AttributeError: description = None ! print "Installing service %s" % (serviceName,) # Note that we install the service before calling the custom option # handler, so if the custom handler fails, we have an installed service (from NT's POV) *************** *** 634,637 **** --- 674,679 ---- try: ChangeServiceConfig(serviceClassString, serviceName, serviceDeps = serviceDeps, startType=startup, bRunInteractive=interactive, userName=userName,password=password, exeName=exeName, displayName = serviceDisplayName, perfMonIni=perfMonIni,perfMonDll=perfMonDll,exeArgs=exeArgs,description=description) + if customOptionHandler: + apply( customOptionHandler, (opts,) ) print "Service updated" except win32service.error, (hr, fn, msg): |