init_logging() makes more sense in the config module.
[pyTivo/wgw.git] / pyTivo.py
blobbdf6267a889f1c9b5180371a1d2c7cd692877d83
1 #!/usr/bin/env python
3 import beacon
4 import httpserver
5 import os
7 import config
8 from plugin import GetPlugin
10 config.init_logging()
12 port = config.getPort()
14 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
16 for section, settings in config.getShares():
17 httpd.add_container(section, settings)
18 # Precaching of files: does a recursive list of base path
19 if settings.get('precache', 'False').lower() == 'true':
20 plugin = GetPlugin(settings.get('type'))
21 if hasattr(plugin, 'pre_cache'):
22 print 'Pre-caching the', section, 'share.'
23 pre_cache_filter = getattr(plugin, 'pre_cache')
25 def build_recursive_list(path):
26 try:
27 for f in os.listdir(path):
28 f = os.path.join(path, f)
29 if os.path.isdir(f):
30 build_recursive_list(f)
31 else:
32 pre_cache_filter(f)
33 except:
34 pass
36 build_recursive_list(settings.get('path'))
38 b = beacon.Beacon()
39 b.add_service('TiVoMediaServer:' + str(port) + '/http')
40 b.start()
41 if 'listen' in config.getBeaconAddresses():
42 b.listen()
44 logging.getLogger('pyTivo').info('pyTivo is ready.')
46 try:
47 httpd.set_beacon(b)
48 httpd.serve_forever()
49 except KeyboardInterrupt:
50 b.stop()