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