~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to portable/dl_daemon/Democracy_Downloader.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Miro - an RSS based video player application
2
 
# Copyright (C) 2005-2010 Participatory Culture Foundation
3
 
#
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.
8
 
#
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.
13
 
#
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
17
 
#
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
20
 
# library.
21
 
#
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.
28
 
 
29
 
"""Miro download daemon - background process
30
 
"""
31
 
 
32
 
def override_modules():
33
 
    import miro
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
40
 
 
41
 
def launch():
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.
45
 
    import sys
46
 
    import os
47
 
    from miro import util
48
 
    import logging
49
 
    logPath = os.environ.get('DEMOCRACY_DOWNLOADER_LOG')
50
 
    if logPath is not None:
51
 
        if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') == '1':
52
 
            logMode = 'w'
53
 
        else:
54
 
            logMode = 'a'
55
 
        log = open(logPath, logMode)
56
 
        sys.stdout = sys.stderr = log
57
 
 
58
 
    sys.stdout = util.AutoFlushingStream(sys.stdout)
59
 
    sys.stderr = util.AutoFlushingStream(sys.stderr)
60
 
 
61
 
    override_modules()
62
 
 
63
 
    from miro.plat.utils import setup_logging, initialize_locale
64
 
    setup_logging(inDownloader=True)
65
 
    util.setup_logging()
66
 
    initialize_locale()
67
 
 
68
 
    if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') != '1':
69
 
        logging.info ("*** Starting new downloader log ***")
70
 
    else:
71
 
        logging.info ("*** Launching Downloader Daemon ****")
72
 
 
73
 
    # Start of normal imports
74
 
    import threading
75
 
 
76
 
    from miro.dl_daemon import daemon
77
 
    from miro.dl_daemon import download
78
 
    from miro import eventloop
79
 
    from miro import httpclient
80
 
 
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)
84
 
 
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
88
 
    # large.
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
94
 
 
95
 
    download.downloadUpdater.startUpdates()
96
 
    eventloop.startup()
97
 
 
98
 
    # Hack to init gettext after we can get config information
99
 
    #
100
 
    # See corresponding hack in gtcache.py
101
 
    from miro import gtcache
102
 
    gtcache.init()
103
 
    logging.info ("*** Daemon ready ***")
104
 
 
105
 
if __name__ == "__main__":
106
 
    launch()