""" tt2p4s.py
Service wrapper to tt2p4s.py.
For this to work as a service, you need a System (not User) DSN, and you need to logon as a user (not Local System Account).
"""
import tt2p4
import win32serviceutil, pywintypes
import win32service
import time
from win32event import *
class TestTrackToPerforce(win32serviceutil.ServiceFramework):
_svc_name_ = "TestTrackToPerforce"
_svc_display_name_ = "Test Track To Perforce Service"
_stopPending = 0
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = CreateEvent(None, 0, 0, None)
self.overlapped = pywintypes.OVERLAPPED()
self.overlapped.hEvent = CreateEvent(None,0,0,None)
self.thread_handles = []
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
#SetEvent(self.hWaitStop)
self._stopPending = 1
def SvcDoRun(self):
# Write an event log record - in debug mode we will also
# see this message printed.
import servicemanager
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, '')
)
tt2p4.init()
while not self._stopPending:
defects = tt2p4.convertDefects()
if defects:
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(`defects`, '')
)
time.sleep(60)
tt2p4.teardown()
if __name__=='__main__':
win32serviceutil.HandleCommandLine(TestTrackToPerforce)