Updated music plugin to suport the full paths
[pyTivo.git] / pyTivoService.py
blob4cd260eb1a8a48c87670974df143af8940969dbd
1 import beacon, httpserver
2 import win32serviceutil
3 import win32service
4 import win32event
5 import select, sys
6 import config
8 class PyTivoService(win32serviceutil.ServiceFramework):
9 _svc_name_ = 'pyTivo'
10 _svc_display_name_ = 'pyTivo'
12 def __init__(self, args):
13 win32serviceutil.ServiceFramework.__init__(self, args)
14 self.stop_event = win32event.CreateEvent(None, 0, 0, None)
16 def SvcDoRun(self):
18 import sys, os
20 p = os.path.dirname(__file__)
22 f = open(os.path.join(p, 'log.txt'), 'w')
23 sys.stdout = f
24 sys.stderr = f
27 port = config.getPort()
29 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
31 for section, settings in config.getShares():
32 httpd.add_container(section, settings)
34 b = beacon.Beacon()
35 b.add_service('TiVoMediaServer:' + str(port) + '/http')
36 b.start()
38 while 1:
39 sys.stdout.flush()
40 (rx, tx, er) = select.select((httpd,), (), (), 5)
41 for sck in rx:
42 sck.handle_request()
43 rc = win32event.WaitForSingleObject(self.stop_event, 5)
44 if rc == win32event.WAIT_OBJECT_0:
45 b.stop()
46 break
48 def SvcStop(self):
49 win32event.SetEvent(self.stop_event)
51 if __name__ == '__main__':
52 win32serviceutil.HandleCommandLine(PyTivoService)