- Fixed bug in vertical padding.
[pyTivo.git] / pyTivoService.py
blob9522b654d7d26196025bcc1e7ca28a99a82b88d5
1 import beacon, httpserver, ConfigParser
2 import win32serviceutil
3 import win32service
4 import win32event
5 import select, sys
7 class PyTivoService(win32serviceutil.ServiceFramework):
8 _svc_name_ = 'pyTivo'
9 _svc_display_name_ = 'pyTivo'
11 def __init__(self, args):
12 win32serviceutil.ServiceFramework.__init__(self, args)
13 self.stop_event = win32event.CreateEvent(None, 0, 0, None)
15 def SvcDoRun(self):
17 import sys, os
19 from Config import config
21 p = os.path.dirname(__file__)
23 f = open(os.path.join(p, 'log.txt'), 'w')
24 sys.stdout = f
25 sys.stderr = f
28 port = config.get('Server', 'Port')
30 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
32 for section in config.sections():
33 if not section == 'Server':
34 httpd.add_container(section, config.get(section, 'type'), config.get(section, 'path'))
36 b = beacon.Beacon()
37 b.add_service('TiVoMediaServer:' + str(port) + '/http')
38 b.start()
40 while 1:
41 sys.stdout.flush()
42 (rx, tx, er) = select.select((httpd,), (), (), 5)
43 for sck in rx:
44 sck.handle_request()
45 rc = win32event.WaitForSingleObject(self.stop_event, 5)
46 if rc == win32event.WAIT_OBJECT_0:
47 b.stop()
48 break
50 def SvcStop(self):
51 win32event.SetEvent(self.stop_event)
53 if __name__ == '__main__':
54 win32serviceutil.HandleCommandLine(PyTivoService)