8 if sys
.version_info
[0] != 2 or sys
.version_info
[1] < 4:
9 print ('ERROR: pyTivo requires Python >= 2.4, < 3.0.\n')
15 from plugin
import GetPlugin
17 def exceptionLogger(*args
):
18 sys
.excepthook
= sys
.__excepthook
__
19 logging
.getLogger('pyTivo').error('Exception in pyTivo', exc_info
=args
)
21 def setup(in_service
=False):
22 config
.init(sys
.argv
[1:])
24 sys
.excepthook
= exceptionLogger
26 port
= config
.getPort()
28 httpd
= httpserver
.TivoHTTPServer(('', int(port
)),
29 httpserver
.TivoHTTPHandler
)
31 logger
= logging
.getLogger('pyTivo')
33 for section
, settings
in config
.getShares():
34 httpd
.add_container(section
, settings
)
35 # Precaching of files: does a recursive list of base path
36 if settings
.get('precache', 'False').lower() == 'true':
37 plugin
= GetPlugin(settings
.get('type'))
38 if hasattr(plugin
, 'pre_cache'):
39 logger
.info('Pre-caching the ' + section
+ ' share.')
40 pre_cache_filter
= getattr(plugin
, 'pre_cache')
42 def build_recursive_list(path
):
44 for f
in os
.listdir(path
):
45 f
= os
.path
.join(path
, f
)
47 build_recursive_list(f
)
53 build_recursive_list(settings
.get('path'))
56 b
.add_service('TiVoMediaServer:%s/http' % port
)
58 if 'listen' in config
.getBeaconAddresses():
62 httpd
.set_service_status(in_service
)
64 logger
.info('pyTivo is ready.')
70 except KeyboardInterrupt:
79 if __name__
== '__main__':