Still need to skip "_tivo_4K" sections when building list of found TiVos.
[pyTivo/wmcbrine.git] / pyTivoService.py
blob7c799df1de954fc2dec8792f30d7e0319cf2f024
1 import os
2 import select
3 import sys
4 import time
5 import win32event
6 import win32service
7 import win32serviceutil
9 import pyTivo
11 class PyTivoService(win32serviceutil.ServiceFramework):
12 _svc_name_ = 'pyTivo'
13 _svc_display_name_ = 'pyTivo'
15 def __init__(self, args):
16 win32serviceutil.ServiceFramework.__init__(self, args)
17 self.stop_event = win32event.CreateEvent(None, 0, 0, None)
19 def mainloop(self):
20 httpd = pyTivo.setup(True)
22 while True:
23 sys.stdout.flush()
24 (rx, tx, er) = select.select((httpd,), (), (), 5)
25 for sck in rx:
26 sck.handle_request()
27 rc = win32event.WaitForSingleObject(self.stop_event, 5)
28 if rc == win32event.WAIT_OBJECT_0 or httpd.stop:
29 break
31 httpd.beacon.stop()
32 return httpd.restart
34 def SvcDoRun(self):
35 p = os.path.dirname(__file__)
37 f = open(os.path.join(p, 'log.txt'), 'w')
38 sys.stdout = f
39 sys.stderr = f
41 while self.mainloop():
42 time.sleep(5)
44 def SvcStop(self):
45 win32event.SetEvent(self.stop_event)
47 if __name__ == '__main__':
48 win32serviceutil.HandleCommandLine(PyTivoService)