1
# Miro - an RSS based video player application
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# In addition, as a special exception, the copyright holders give
19
# permission to link the code of portions of this program with the OpenSSL
22
# You must obey the GNU General Public License in all respects for all of
23
# the code used other than OpenSSL. If you modify file(s) with this
24
# exception, you may extend this exception to your version of the file(s),
25
# but you are not obligated to do so. If you do not wish to do so, delete
26
# this exception statement from your version. If you delete this exception
27
# statement from all source files in the program, then also delete it here.
29
"""Miro download daemon - background process
32
def override_modules():
34
import miro.dl_daemon.private.config
35
import miro.dl_daemon.private.httpauth
36
import miro.dl_daemon.private.resources
37
miro.config = miro.dl_daemon.private.config
38
miro.httpauth = miro.dl_daemon.private.httpauth
39
miro.resources = miro.dl_daemon.private.resources
42
# Make all output flush immediately.
43
# Don't add extra import statements here. If there's a problem importing
44
# something we want to see the error in the log.
49
logPath = os.environ.get('DEMOCRACY_DOWNLOADER_LOG')
50
if logPath is not None:
51
if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') == '1':
55
log = open(logPath, logMode)
56
sys.stdout = sys.stderr = log
58
sys.stdout = util.AutoFlushingStream(sys.stdout)
59
sys.stderr = util.AutoFlushingStream(sys.stderr)
63
from miro.plat.utils import setup_logging, initialize_locale
64
setup_logging(inDownloader=True)
68
if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') != '1':
69
logging.info ("*** Starting new downloader log ***")
71
logging.info ("*** Launching Downloader Daemon ****")
73
# Start of normal imports
76
from miro.dl_daemon import daemon
77
from miro.dl_daemon import download
78
from miro import eventloop
79
from miro import httpclient
81
port = int(os.environ['DEMOCRACY_DOWNLOADER_PORT'])
82
short_app_name = os.environ['DEMOCRACY_SHORT_APP_NAME']
83
server = daemon.DownloaderDaemon(port, short_app_name)
85
# remove the limits for the connection pool, we limit them
86
# ourselves in the downloader code. Don't try to pipeline
87
# requests, it doesn't make sense when the download size is so
89
httpclient.HTTPConnectionPool.MAX_CONNECTIONS_PER_SERVER = sys.maxint
90
httpclient.HTTPConnectionPool.MAX_CONNECTIONS = sys.maxint
91
httpclient.PIPELINING_ENABLED = False
92
httpclient.SOCKET_READ_TIMEOUT = 300
93
httpclient.SOCKET_INITIAL_READ_TIMEOUT = 30
95
download.downloadUpdater.startUpdates()
98
# Hack to init gettext after we can get config information
100
# See corresponding hack in gtcache.py
101
from miro import gtcache
103
logging.info ("*** Daemon ready ***")
105
if __name__ == "__main__":