| 1 |
|
|---|
| 2 |
|
|---|
| 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 |
|---|
| 10 |
|
|---|
| 11 |
def init_logging(): |
|---|
| 12 |
config.config_files |
|---|
| 13 |
p = os.path.dirname(__file__) |
|---|
| 14 |
|
|---|
| 15 |
if config.config.has_section('loggers') and\ |
|---|
| 16 |
config.config.has_section('handlers') and\ |
|---|
| 17 |
config.config.has_section('formatters'): |
|---|
| 18 |
|
|---|
| 19 |
logging.config.fileConfig(config.config_files) |
|---|
| 20 |
|
|---|
| 21 |
elif config.getDebug(0): |
|---|
| 22 |
logging.basicConfig(level=logging.DEBUG) |
|---|
| 23 |
else: |
|---|
| 24 |
logging.basicConfig(level=logging.INFO) |
|---|
| 25 |
|
|---|
| 26 |
init_logging() |
|---|
| 27 |
|
|---|
| 28 |
port = config.getPort() |
|---|
| 29 |
|
|---|
| 30 |
httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler) |
|---|
| 31 |
|
|---|
| 32 |
for section, settings in config.getShares(): |
|---|
| 33 |
httpd.add_container(section, settings) |
|---|
| 34 |
|
|---|
| 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') |
|---|
| 40 |
|
|---|
| 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 |
|---|
| 51 |
|
|---|
| 52 |
build_recursive_list(settings.get('path')) |
|---|
| 53 |
|
|---|
| 54 |
b = beacon.Beacon() |
|---|
| 55 |
b.add_service('TiVoMediaServer:' + str(port) + '/http') |
|---|
| 56 |
b.start() |
|---|
| 57 |
if 'listen' in config.getBeaconAddresses(): |
|---|
| 58 |
b.listen() |
|---|
| 59 |
|
|---|
| 60 |
logging.getLogger('pyTivo').info('pyTivo is ready.') |
|---|
| 61 |
|
|---|
| 62 |
try: |
|---|
| 63 |
httpd.serve_forever() |
|---|
| 64 |
except KeyboardInterrupt: |
|---|
| 65 |
b.stop() |
|---|