1 import beacon
, httpserver
2 import win32serviceutil
8 class PyTivoService(win32serviceutil
.ServiceFramework
):
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)
20 p
= os
.path
.dirname(__file__
)
22 f
= open(os
.path
.join(p
, 'log.txt'), 'w')
27 port
= config
.getPort()
29 httpd
= httpserver
.TivoHTTPServer(('', int(port
)),
30 httpserver
.TivoHTTPHandler
)
32 for section
, settings
in config
.getShares():
33 httpd
.add_container(section
, settings
)
36 b
.add_service('TiVoMediaServer:' + str(port
) + '/http')
38 if 'listen' in config
.getBeaconAddresses():
45 (rx
, tx
, er
) = select
.select((httpd
,), (), (), 5)
48 rc
= win32event
.WaitForSingleObject(self
.stop_event
, 5)
49 if rc
== win32event
.WAIT_OBJECT_0
:
54 win32event
.SetEvent(self
.stop_event
)
56 if __name__
== '__main__':
57 win32serviceutil
.HandleCommandLine(PyTivoService
)