misiing </a> in template reported by Mike G
[pyTivo/wmcbrine/lucasnz.git] / pyTivo.py
blob84d94b28ab7d6caab72c0430a46943ea90c85663
1 #!/usr/bin/env python
3 import logging
4 import os
5 import sys
7 if sys.version_info[0] != 2 or sys.version_info[1] < 4:
8 print ('ERROR: pyTivo requires Python >= 2.4, < 3.0.\n')
9 sys.exit(1)
11 import beacon
12 import config
13 import httpserver
14 from plugin import GetPlugin
16 def exceptionLogger(*args):
17 sys.excepthook = sys.__excepthook__
18 logging.getLogger('pyTivo').error('Exception in pyTivo', exc_info=args)
20 config.init(sys.argv[1:])
21 config.init_logging()
22 sys.excepthook = exceptionLogger
24 port = config.getPort()
26 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
28 logger = logging.getLogger('pyTivo')
30 for section, settings in config.getShares():
31 httpd.add_container(section, settings)
32 # Precaching of files: does a recursive list of base path
33 if settings.get('precache', 'False').lower() == 'true':
34 plugin = GetPlugin(settings.get('type'))
35 if hasattr(plugin, 'pre_cache'):
36 logger.info('Pre-caching the ' + section + ' share.')
37 pre_cache_filter = getattr(plugin, 'pre_cache')
39 def build_recursive_list(path):
40 try:
41 for f in os.listdir(path):
42 f = os.path.join(path, f)
43 if os.path.isdir(f):
44 build_recursive_list(f)
45 else:
46 pre_cache_filter(f)
47 except:
48 pass
50 build_recursive_list(settings.get('path'))
52 b = beacon.Beacon()
53 b.add_service('TiVoMediaServer:%s/http' % port)
54 b.start()
55 if 'listen' in config.getBeaconAddresses():
56 b.listen()
58 logger.info('pyTivo is ready.')
60 try:
61 httpd.set_beacon(b)
62 httpd.serve_forever()
63 except KeyboardInterrupt:
64 b.stop()