[pywin32-checkins] pywin32/win32/Lib win32serviceutil.py, 1.25, 1.26
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-02-07 03:33:15
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8131/lib Modified Files: win32serviceutil.py Log Message: Take advantage of all RegisterServiceCtrlHandler() functionality in a backwards compatible way, including a demo. Index: win32serviceutil.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32serviceutil.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** win32serviceutil.py 30 Jun 2007 04:37:52 -0000 1.25 --- win32serviceutil.py 7 Feb 2008 03:33:15 -0000 1.26 *************** *** 589,593 **** # -debug option svcArgs = string.join(args[1:]) ! exeName = LocateSpecificServiceExe(serviceName) try: os.system("%s -debug %s %s" % (exeName, serviceName, svcArgs)) --- 589,600 ---- # -debug option svcArgs = string.join(args[1:]) ! try: ! exeName = LocateSpecificServiceExe(serviceName) ! except win32api.error, exc: ! if exc[0] == winerror.ERROR_FILE_NOT_FOUND: ! print "The service does not appear to be installed." ! print "Please install the service before debugging it." ! sys.exit(1) ! raise try: os.system("%s -debug %s %s" % (exeName, serviceName, svcArgs)) *************** *** 721,730 **** def __init__(self, args): import servicemanager ! self.ssh = servicemanager.RegisterServiceCtrlHandler(args[0], self.ServiceCtrlHandler) servicemanager.SetEventSourceName(self._svc_name_) self.checkPoint = 0 def GetAcceptedControls(self): ! # Setup the service controls we accept based on our attributes accepted = 0 if hasattr(self, "SvcStop"): accepted = accepted | win32service.SERVICE_ACCEPT_STOP --- 728,739 ---- def __init__(self, args): import servicemanager ! self.ssh = servicemanager.RegisterServiceCtrlHandler(args[0], self.ServiceCtrlHandlerEx, True) servicemanager.SetEventSourceName(self._svc_name_) self.checkPoint = 0 def GetAcceptedControls(self): ! # Setup the service controls we accept based on our attributes. Note ! # that if you need to handle controls via SvcOther[Ex](), you must ! # override this. accepted = 0 if hasattr(self, "SvcStop"): accepted = accepted | win32service.SERVICE_ACCEPT_STOP *************** *** 763,769 **** def SvcOther(self, control): ! print "Unknown control status - %d" % control def ServiceCtrlHandler(self, control): if control==win32service.SERVICE_CONTROL_STOP: self.SvcStop() --- 772,791 ---- def SvcOther(self, control): ! try: ! print "Unknown control status - %d" % control ! except IOError: ! # services may not have a valid stdout! ! pass def ServiceCtrlHandler(self, control): + self.ServiceCtrlHandlerEx(control, 0, None) + + # The 'Ex' functions, which take additional params + def SvcOtherEx(self, control, event_type, data): + # The default here is to call self.SvcOther as that is the old behaviour. + # If you want to take advantage of the extra data, override this method + self.SvcOther(control) + + def ServiceCtrlHandlerEx(self, control, event_type, data): if control==win32service.SERVICE_CONTROL_STOP: self.SvcStop() *************** *** 777,781 **** self.SvcShutdown() else: ! self.SvcOther(control) def SvcRun(self): --- 799,803 ---- self.SvcShutdown() else: ! self.SvcOtherEx(control, event_type, data) def SvcRun(self): |