Lets get the body id before using it.
[pyTivo.git] / pyTivo.py
blob30725f786614ba74f8dffc80eef1e5a6648c8cde
1 #!/usr/bin/env python
3 import logging
4 import logging.config
5 import os
6 import ConfigParser
7 import beacon, httpserver, os, sys
8 import config
9 from plugin import GetPlugin
11 def init_logging():
12 config.config_files
13 p = os.path.dirname(__file__)
15 if config.config.has_section('loggers') and\
16 config.config.has_section('handlers') and\
17 config.config.has_section('formatters'):
19 logging.config.fileConfig(config.config_files)
21 elif config.getDebug(0):
22 logging.basicConfig(level=logging.DEBUG)
23 else:
24 logging.basicConfig(level=logging.INFO)
26 init_logging()
28 port = config.getPort()
30 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
32 for section, settings in config.getShares():
33 httpd.add_container(section, settings)
34 # Precaching of files: does a recursive list of base path
35 if settings.get('precache', 'False').lower() == 'true':
36 plugin = GetPlugin(settings.get('type'))
37 if hasattr(plugin, 'pre_cache'):
38 print 'Pre-caching the', section, 'share.'
39 pre_cache_filter = getattr(plugin, 'pre_cache')
41 def build_recursive_list(path):
42 try:
43 for f in os.listdir(path):
44 f = os.path.join(path, f)
45 if os.path.isdir(f):
46 build_recursive_list(f)
47 else:
48 pre_cache_filter(f)
49 except:
50 pass
52 build_recursive_list(settings.get('path'))
54 b = beacon.Beacon()
55 b.add_service('TiVoMediaServer:' + str(port) + '/http')
56 b.start()
57 if 'listen' in config.getBeaconAddresses():
58 b.listen()
60 logging.getLogger('pyTivo').info('pyTivo is ready.')
62 try:
63 httpd.serve_forever()
64 except KeyboardInterrupt:
65 b.stop()