Use a single save/load for the config, instead of having a separate
[pyTivo/wgw.git] / pyTivo.py
blob50dbb5c98f51f717b6ac349d1f0e1d84323057be
1 #!/usr/bin/env python
3 import logging
4 import os
6 import beacon
7 import httpserver
8 import config
9 from plugin import GetPlugin
11 config.init_logging()
13 port = config.getPort()
15 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
17 for section, settings in config.getShares():
18 httpd.add_container(section, settings)
19 # Precaching of files: does a recursive list of base path
20 if settings.get('precache', 'False').lower() == 'true':
21 plugin = GetPlugin(settings.get('type'))
22 if hasattr(plugin, 'pre_cache'):
23 print 'Pre-caching the', section, 'share.'
24 pre_cache_filter = getattr(plugin, 'pre_cache')
26 def build_recursive_list(path):
27 try:
28 for f in os.listdir(path):
29 f = os.path.join(path, f)
30 if os.path.isdir(f):
31 build_recursive_list(f)
32 else:
33 pre_cache_filter(f)
34 except:
35 pass
37 build_recursive_list(settings.get('path'))
39 b = beacon.Beacon()
40 b.add_service('TiVoMediaServer:%s/http' % port)
41 b.start()
42 if 'listen' in config.getBeaconAddresses():
43 b.listen()
45 logging.getLogger('pyTivo').info('pyTivo is ready.')
47 try:
48 httpd.set_beacon(b)
49 httpd.serve_forever()
50 except KeyboardInterrupt:
51 b.stop()