9 if sys
.version_info
[0] != 2 or sys
.version_info
[1] < 4:
10 print ('ERROR: pyTivo requires Python >= 2.4, < 3.0.\n')
16 from plugin
import GetPlugin
18 def exceptionLogger(*args
):
19 sys
.excepthook
= sys
.__excepthook
__
20 logging
.getLogger('pyTivo').error('Exception in pyTivo', exc_info
=args
)
24 path
= os
.path
.dirname(__file__
)
27 for root
, dirs
, files
in os
.walk(path
):
29 if name
.endswith('.py'):
30 tm
= os
.stat(os
.path
.join(root
, name
)).st_mtime
34 return time
.asctime(time
.localtime(lasttime
))
36 def setup(in_service
=False):
37 config
.init(sys
.argv
[1:])
39 sys
.excepthook
= exceptionLogger
41 port
= config
.getPort()
43 httpd
= httpserver
.TivoHTTPServer(('', int(port
)),
44 httpserver
.TivoHTTPHandler
)
46 logger
= logging
.getLogger('pyTivo')
47 logger
.info('Last modified: ' + last_date())
48 logger
.info('Python: ' + platform
.python_version())
49 logger
.info('System: ' + platform
.platform())
51 for section
, settings
in config
.getShares():
52 httpd
.add_container(section
, settings
)
53 # Precaching of files: does a recursive list of base path
54 if settings
.get('precache', 'False').lower() == 'true':
55 plugin
= GetPlugin(settings
.get('type'))
56 if hasattr(plugin
, 'pre_cache'):
57 logger
.info('Pre-caching the ' + section
+ ' share.')
58 pre_cache_filter
= getattr(plugin
, 'pre_cache')
60 def build_recursive_list(path
):
62 for f
in os
.listdir(path
):
63 f
= os
.path
.join(path
, f
)
65 build_recursive_list(f
)
71 build_recursive_list(settings
.get('path'))
74 b
.add_service('TiVoMediaServer:%s/http' % port
)
76 if 'listen' in config
.getBeaconAddresses():
80 httpd
.set_service_status(in_service
)
82 logger
.info('pyTivo is ready.')
88 except KeyboardInterrupt:
97 if __name__
== '__main__':