예제 #1
0
def _subprocess_setup(stdin, stdout):
    """Does initial setup for a subprocess.

    Returns a SubprocessHandler to use for the subprocess

    raises the same exceptions that _load_obj does, namely:

    :raises IOError: low-level error while reading from the pipe
    :raises LoadError: data read was corrupted
    """
    # disable warnings so we don't get too much junk on stderr
    warnings.filterwarnings("ignore")
    # setup MessageHandler for messages going to the main process
    msg_handler = PipeMessageProxy(stdout)
    SubprocessResponse.install_handler(msg_handler)
    # load startup info
    msg = _load_obj(stdin)
    if not isinstance(msg, StartupInfo):
        raise LoadError("first message must a StartupInfo obj")
    # setup some basic modules like config and gtcache
    initialize_locale()
    config.load(config.ManualConfig())
    app.config.set_dictionary(msg.config_dict)
    gtcache.init()
    # setup our handler
    msg = _load_obj(stdin)
    if not isinstance(msg, HandlerInfo):
        raise LoadError("second message must a HandlerInfo obj")
    try:
        return msg.handler_class(*msg.handler_args)
    except StandardError, e:
        # log this exception for easier debugging.
        _send_subprocess_error_for_exception()
        raise LoadError("Exception while constructing handler: %s" % e)
예제 #2
0
def _subprocess_setup(stdin, stdout):
    """Does initial setup for a subprocess.

    Returns a SubprocessHandler to use for the subprocess

    raises the same exceptions that _load_obj does, namely:

    :raises IOError: low-level error while reading from the pipe
    :raises LoadError: data read was corrupted
    """
    # disable warnings so we don't get too much junk on stderr
    warnings.filterwarnings("ignore")
    # setup MessageHandler for messages going to the main process
    msg_handler = PipeMessageProxy(stdout)
    SubprocessResponse.install_handler(msg_handler)
    # load startup info
    msg = _load_obj(stdin)
    if not isinstance(msg, StartupInfo):
        raise LoadError("first message must a StartupInfo obj")
    # setup some basic modules like config and gtcache
    initialize_locale()
    config.load(config.ManualConfig())
    app.config.set_dictionary(msg.config_dict)
    gtcache.init()
    # setup our handler
    msg = _load_obj(stdin)
    if not isinstance(msg, HandlerInfo):
        raise LoadError("second message must a HandlerInfo obj")
    try:
        return msg.handler_class(*msg.handler_args)
    except StandardError, e:
        # log this exception for easier debugging.
        _send_subprocess_error_for_exception()
        raise LoadError("Exception while constructing handler: %s" % e)
예제 #3
0
def bootstrap():
    """Run this as soon as possible when starting up miro.

    This method sets up gtcache and the app.config object.  Later on, we will
    replace this app.config with one that's theme aware.
    """
    config.load()
    gtcache.init()
    eventloop.setup_config_watcher()
예제 #4
0
파일: bootstrap.py 프로젝트: youprofit/miro
def bootstrap():
    """Run this as soon as possible when starting up miro.

    This method sets up gtcache and the app.config object.  Later on, we will
    replace this app.config with one that's theme aware.
    """
    config.load()
    gtcache.init()
    eventloop.setup_config_watcher()
예제 #5
0
def launch():
    # Make all output flush immediately.
    # Don't add extra import statements here.  If there's a problem importing
    # something we want to see the error in the log.
    import logging
    import sys
    import os
    from miro import util

    sys.stdout = util.AutoFlushingStream(sys.stdout)
    sys.stderr = sys.stdout

    override_modules()

    from miro.plat.utils import setup_logging, initialize_locale
    setup_logging(in_downloader=True)
    util.setup_logging()
    initialize_locale()

    if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') != '1':
        logging.info("Starting new downloader log")
    else:
        logging.info("Launching Downloader Daemon")
    log_versions()

    # Start of normal imports
    import threading

    from miro.dl_daemon import daemon
    from miro import httpclient

    addr = os.environ['DEMOCRACY_DOWNLOADER_ADDR']
    port = int(os.environ['DEMOCRACY_DOWNLOADER_PORT'])
    short_app_name = os.environ['DEMOCRACY_SHORT_APP_NAME']
    httpclient.start_thread()
    server = daemon.DownloaderDaemon(addr, port, short_app_name)
    # setup config for the downloader
    from miro import eventloop
    config.load(config.DownloaderConfig())
    app.downloader_config_watcher = config.ConfigWatcher(
            lambda foo, *args: eventloop.add_idle(foo, "config watcher",
                args=args))
    # start things up
    eventloop.startup()
예제 #6
0
def launch():
    # Make all output flush immediately.
    # Don't add extra import statements here.  If there's a problem importing
    # something we want to see the error in the log.
    from miro import util

    sys.stdout = util.AutoFlushingStream(sys.stdout)
    sys.stderr = sys.stdout

    override_modules()

    from miro.plat.utils import setup_logging, initialize_locale
    setup_logging(in_downloader=True)
    util.setup_logging()
    initialize_locale()

    if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') != '1':
        logging.info("Starting new downloader log")
    else:
        logging.info("Launching Downloader Daemon")
    log_versions()

    # Start of normal imports
    from miro.dl_daemon import daemon
    from miro import httpclient

    addr = os.environ['DEMOCRACY_DOWNLOADER_ADDR']
    port = int(os.environ['DEMOCRACY_DOWNLOADER_PORT'])
    short_app_name = os.environ['DEMOCRACY_SHORT_APP_NAME']
    httpclient.start_thread()
    daemon.DownloaderDaemon(addr, port, short_app_name)
    # setup config for the downloader
    from miro import eventloop
    config.load(config.ManualConfig())
    app.downloader_config_watcher = config.ConfigWatcher(
        lambda foo, *args: eventloop.add_idle(foo, "config watcher", args=args
                                              ))
    # start things up
    eventloop.startup()