flag console debug echoes
[pyTivo/wgw.git] / pyTivo.py
blobc46a3695e4eae31347023d9ed7bec33a391fba03
1 #!/usr/bin/env python
3 import beacon, httpserver, os, sys
4 import config
5 from debug import print_conf, fn_attr
6 from plugin import GetPlugin
8 port = config.getPort()
10 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
12 for section, settings in config.getShares():
13 httpd.add_container(section, settings)
14 # Precaching of files: does a recursive list of base path
15 if settings.get('precache', 'False').lower() == 'true':
16 plugin = GetPlugin(settings.get('type'))
17 if hasattr(plugin, 'pre_cache'):
18 print 'Pre-caching the', section, 'share.'
19 pre_cache_filter = getattr(plugin, 'pre_cache')
21 def build_recursive_list(path):
22 for f in os.listdir(path):
23 f = os.path.join(path, f)
24 if os.path.isdir(f):
25 build_recursive_list(f)
26 else:
27 pre_cache_filter(f)
29 build_recursive_list(settings.get('path'))
31 b = beacon.Beacon()
32 b.add_service('TiVoMediaServer:' + str(port) + '/http')
33 b.start()
34 if 'listen' in config.getBeaconAddresses():
35 b.listen()
37 print_conf(__name__, fn_attr())
38 print 'pyTivo is ready.'
39 try:
40 httpd.serve_forever()
41 except KeyboardInterrupt:
42 b.stop()