Пример #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 startup(argv):
    # Before importing gstreamer, fix os.environ so gstreamer finds its
    # plugins.  Do this early before any code is run to prevent any import
    # of gst missing this!
    from miro.plat import resources
    GST_PLUGIN_PATH = os.path.join(resources.app_root(), 'gstreamer-0.10')
    os.environ["GST_PLUGIN_PATH"] = GST_PLUGIN_PATH
    os.environ["GST_PLUGIN_SYSTEM_PATH"] = GST_PLUGIN_PATH

    theme = None
    # Should have code to figure out the theme.

    from miro.plat import pipeipc
    try:
        pipe_server = pipeipc.Server()
    except pipeipc.PipeExists:
        pipeipc.send_command_line_args()
        return
    pipe_server.start_process()

    from miro.plat import prelogger
    prelogger.install()

    from miro.plat.utils import initialize_locale
    initialize_locale()

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro.plat import commandline
    args = commandline.get_command_line()[1:]

    if '--theme' in args:
        index = args.index('--theme')
        theme = args[index + 1]
        del args[index:index + 1]

    if '--debug' in args:
        index = args.index('--debug')
        del args[index]
        from miro import app
        app.debugmode = True

    from miro import startup
    startup.initialize(theme)

    from miro.plat import migrateappname
    migrateappname.migrateSupport('Democracy', 'Miro')

    from miro import commandline
    commandline.set_command_line_args(args)

    # Kick off the application
    from miro.plat.frontends.widgets.application import WindowsApplication
    WindowsApplication().run()
    pipe_server.quit()
Пример #4
0
def startup(argv):
    # Before importing gstreamer, fix os.environ so gstreamer finds its
    # plugins.  Do this early before any code is run to prevent any import
    # of gst missing this!
    from miro.plat import resources
    GST_PLUGIN_PATH = os.path.join(resources.app_root(), 'gstreamer-0.10')
    os.environ["GST_PLUGIN_PATH"] = GST_PLUGIN_PATH
    os.environ["GST_PLUGIN_SYSTEM_PATH"] = GST_PLUGIN_PATH

    theme = None
    # Should have code to figure out the theme.

    from miro.plat import pipeipc
    try:
        pipe_server = pipeipc.Server()
    except pipeipc.PipeExists:
        pipeipc.send_command_line_args()
        return
    pipe_server.start_process()

    from miro.plat import prelogger
    prelogger.install()

    from miro.plat.utils import initialize_locale
    initialize_locale()

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro.plat import commandline
    args = commandline.get_command_line()[1:]

    if '--theme' in args:
        index = args.index('--theme')
        theme = args[index+1]
        del args[index:index+1]

    if '--debug' in args:
        index = args.index('--debug')
        del args[index]
        from miro import app
        app.debugmode = True

    from miro import startup
    startup.initialize(theme)

    from miro.plat import migrateappname
    migrateappname.migrateSupport('Democracy', 'Miro')

    from miro import commandline
    commandline.set_command_line_args(args)

    # Kick off the application
    from miro.plat.frontends.widgets.application import WindowsApplication
    WindowsApplication().run()
    pipe_server.quit()
Пример #5
0
def launch_unit_tests():
    sys.argv.remove('--unittest')

    logging.basicConfig(level=logging.CRITICAL)

    from miro.plat.utils import initialize_locale
    initialize_locale()
    from miro import bootstrap
    bootstrap.bootstrap()
    from miro import test

    print 'Running Miro unit tests:'
    test.run_tests()
Пример #6
0
Файл: Miro.py Проект: kmshi/miro
def startup(argv):
    theme = None
    # Should have code to figure out the theme.

    from miro.plat import pipeipc
    try:
        pipe_server = pipeipc.Server()
    except pipeipc.PipeExists:
        pipeipc.send_command_line_args()
        return
    pipe_server.start_process()

    from miro.plat import prelogger
    prelogger.install()

    from miro.plat.utils import initialize_locale
    initialize_locale()

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro.plat import fontinfo
    fontinfo.init()

    from miro.plat import commandline
    args = commandline.get_command_line()[1:]

    if '--theme' in args:
        index = args.index('--theme')
        theme = args[index + 1]
        del args[index:index + 1]

    if '--debug' in args:
        index = args.index('--debug')
        del args[index]
        from miro import app
        app.debugmode = True

    from miro import startup
    startup.initialize(theme)

    from miro.plat import migrateappname
    migrateappname.migrateSupport('Democracy', 'Miro')

    from miro import commandline
    commandline.set_command_line_args(args)

    # Kick off the application
    from miro.plat.frontends.widgets.application import WindowsApplication
    WindowsApplication().run()
    pipe_server.quit()
Пример #7
0
def startup(argv):
    theme = None
    # Should have code to figure out the theme.

    from miro.plat import pipeipc
    try:
        pipe_server = pipeipc.Server()
    except pipeipc.PipeExists:
        pipeipc.send_command_line_args()
        return
    pipe_server.start_process()

    from miro.plat import prelogger
    prelogger.install()

    from miro.plat.utils import initialize_locale
    initialize_locale()

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro.plat import fontinfo
    fontinfo.init()

    from miro.plat import commandline
    args = commandline.get_command_line()[1:]

    if '--theme' in args:
        index = args.index('--theme')
        theme = args[index+1]
        del args[index:index+1]

    if '--debug' in args:
        index = args.index('--debug')
        del args[index]
        from miro import app
        app.debugmode = True

    from miro import startup
    startup.initialize(theme)

    from miro.plat import migrateappname
    migrateappname.migrateSupport('Democracy', 'Miro')

    from miro import commandline
    commandline.set_command_line_args(args)

    # Kick off the application
    from miro.plat.frontends.widgets.application import WindowsApplication
    WindowsApplication().run()
    pipe_server.quit()
Пример #8
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()
Пример #9
0
def test_startup(argv):
    import sys
    import logging
    logging.basicConfig(level=logging.CRITICAL)

    from miro import app
    app.debugmode = True

    from miro.plat import utils
    utils.initialize_locale()

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro import test
    from miro.plat import resources

    sys.path.append(resources.app_root())
    test.run_tests()
Пример #10
0
def test_startup(argv):
    import sys
    import logging
    logging.basicConfig(level=logging.CRITICAL)

    from miro import app
    app.debugmode = True

    from miro.plat import utils
    utils.initialize_locale()

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro import test
    from miro.plat import resources

    sys.path.append(resources.app_root())
    test.run_tests()
Пример #11
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()
Пример #12
0
def launch_application(parsed_options, args):
    from miro.plat import migrateappname
    migrateappname.migrateSupport('Democracy', 'Miro')

    from miro.plat.utils import initialize_locale
    initialize_locale()

    from glob import glob
    theme = None
    bundle = Foundation.NSBundle.mainBundle()
    bundle_path = bundle.bundlePath()
    bundle_theme_dir_path = os.path.join(bundle_path, "Contents", "Theme")
    if os.path.exists(bundle_theme_dir_path):
        theme_dirs = glob(os.path.join(bundle_theme_dir_path, "*"))
        theme_dir = theme_dirs[0]
        if os.path.isdir(theme_dir):
            theme = os.path.basename(themeDir)

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro import app
    from miro import prefs

    # Tee output off to a log file
    class AutoflushingTeeStream:
        def __init__(self, streams):
            self.streams = streams
        def write(self, *args):
            for s in self.streams:
                try:
                    s.write(*args)
                except IOError:
                    pass
            self.flush()
        def flush(self):
            for s in self.streams:
                try:
                    s.flush()
                except IOError:
                    pass

    log_file = app.config.get(prefs.LOG_PATHNAME)
    if log_file:
        h = open(log_file, "wt")
        sys.stdout = AutoflushingTeeStream([h, sys.stdout])
        sys.stderr = AutoflushingTeeStream([h, sys.stderr])

    # handle command line args
    if parsed_options.debugmode:
        if parsed_options.debugmode.lower() in ("y", "yes"):
            app.debugmode = True
        else:
            app.debugmode = False
    from miro import commandline
    commandline.set_command_line_args(args)

    # Kick off the application
    from miro import startfrontend
    startfrontend.run_application(parsed_options.frontend, {}, theme)

    # This code is useless, but it tells py2app that we need to import these
    # modules
    import miro.plat.frontends.widgets.application
    import miro.frontends.cli.application
    import miro.frontends.profilewidgets.application
    import miro.frontends.shell.application
Пример #13
0
#
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.

"""Miro test utility -- console application for running unit tests.
"""

import sys
import logging

from miro.plat import utils
utils.initialize_locale()

from miro import bootstrap
bootstrap.bootstrap()

# from miro import gtcache
# gtcache.init()

if "-v" not in sys.argv:
    logging.basicConfig(level=logging.CRITICAL)

from miro import test
from miro.plat import resources

sys.path.append(resources.appRoot())
test.run_tests()
Пример #14
0
def launch_application(parsed_options, args):
    from miro.plat import migrateappname
    migrateappname.migrateSupport('Democracy', 'Miro')

    from miro.plat.utils import initialize_locale
    initialize_locale()

    from glob import glob
    theme = None
    bundle = NSBundle.mainBundle()
    bundle_path = bundle.bundlePath()
    bundle_theme_dir_path = os.path.join(bundle_path, "Contents", "Theme")
    if os.path.exists(bundle_theme_dir_path):
        theme_dirs = glob(os.path.join(bundle_theme_dir_path, "*"))
        theme_dir = theme_dirs[0]
        if os.path.isdir(theme_dir):
            theme = os.path.basename(theme_dir)

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro import app
    from miro import prefs

    # Tee output off to a log file
    class AutoflushingTeeStream:
        def __init__(self, streams):
            self.streams = streams
        def write(self, *args):
            for s in self.streams:
                try:
                    s.write(*args)
                except IOError:
                    pass
            self.flush()
        def flush(self):
            for s in self.streams:
                try:
                    s.flush()
                except IOError:
                    pass

    log_file = app.config.get(prefs.LOG_PATHNAME)
    if log_file:
        h = open(log_file, "wt")
        sys.stdout = AutoflushingTeeStream([h, sys.stdout])
        sys.stderr = AutoflushingTeeStream([h, sys.stderr])

    # handle command line args
    if parsed_options.debugmode:
        if parsed_options.debugmode.lower() in ("y", "yes"):
            app.debugmode = True
        else:
            app.debugmode = False
    from miro import commandline
    commandline.set_command_line_args(args)

    # Kick off the application
    from miro import startfrontend
    startfrontend.run_application(parsed_options.frontend, {}, theme)

    # This code is useless, but it tells py2app that we need to import these
    # modules
    import miro.plat.frontends.widgets.application
    import miro.frontends.cli.application
    import miro.frontends.profilewidgets.application
    import miro.frontends.shell.application
Пример #15
0
def startup(argv):
    # Rewrite the stdout and stderr to catch cases debug being printed via
    # a print or via a write to stderr.  Normally we would use shortAppName
    # but at this point nothing has been bootstrapped yet.  We only want to
    # catch it though if py2exe has fiddled with our file descriptors.
    #
    # The stdout/stderr are redirected again in the Windows-specific
    # setup_logging().
    #
    # See bz17793
    redirected = sys.stdout != sys.__stdout__
    if redirected:
        try:
            logfile = os.path.join(tempfile.gettempdir(), 'Miro_console.log')
            sys.stderr = sys.stdout = open(logfile, 'w')
        except EnvironmentError:
            # too bad ... let's silence rather than spew stuff to stop it
            # writing to a file that it might not have permissions to.
            # Hopefully, this does not happen often.
            sys.stderr = sys.stdout = open(os.devnull, 'w')

    # Before importing gstreamer, fix os.environ so gstreamer finds its
    # plugins.  Do this early before any code is run to prevent any import
    # of gst missing this!
    from miro.plat import resources
    from miro.plat import config
    GST_PLUGIN_PATH = os.path.join(resources.app_root(), 'gstreamer-0.10')
    os.environ["GST_PLUGIN_PATH"] = GST_PLUGIN_PATH
    os.environ["GST_PLUGIN_SYSTEM_PATH"] = GST_PLUGIN_PATH
    # normally we'd use app.config to get this, but we're starting up
    os.environ["GST_REGISTRY"] = os.path.join(config._get_support_directory(),
                                              'gst_registry.bin')

    theme = None
    # Should have code to figure out the theme.

    from miro.plat import pipeipc
    try:
        pipe_server = pipeipc.Server()
    except pipeipc.PipeExists:
        pipeipc.send_command_line_args()
        return
    pipe_server.start_process()

    from miro.plat import prelogger
    prelogger.install()

    from miro.plat.utils import initialize_locale
    initialize_locale()

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro.plat import commandline
    args = commandline.get_command_line()[1:]

    if '--theme' in args:
        index = args.index('--theme')
        theme = args[index + 1]
        del args[index:index + 1]

    if '--debug' in args:
        index = args.index('--debug')
        del args[index]
        from miro import app
        app.debugmode = True

    from miro.plat import migrateappname
    migrateappname.migrateSupport('Democracy', 'Miro')

    from miro import commandline
    commandline.set_command_line_args(args)

    # Kick off the application
    from miro import startfrontend
    startfrontend.run_application('widgets', {}, None)
    pipe_server.quit()
Пример #16
0
def startup(argv):
    # Rewrite the stdout and stderr to catch cases debug being printed via
    # a print or via a write to stderr.  Normally we would use shortAppName
    # but at this point nothing has been bootstrapped yet.  We only want to
    # catch it though if py2exe has fiddled with our file descriptors.
    #
    # The stdout/stderr are redirected again in the Windows-specific
    # setup_logging(). 
    #
    # See bz17793
    redirected = sys.stdout != sys.__stdout__
    if redirected:
        try:
            logfile = os.path.join(tempfile.gettempdir(), 'Miro_console.log')
            sys.stderr = sys.stdout = open(logfile, 'w')
        except EnvironmentError:
            # too bad ... let's silence rather than spew stuff to stop it 
            # writing to a file that it might not have permissions to.  
            # Hopefully, this does not happen often.
            sys.stderr = sys.stdout = open(os.devnull, 'w')

    # Before importing gstreamer, fix os.environ so gstreamer finds its
    # plugins.  Do this early before any code is run to prevent any import
    # of gst missing this!
    from miro.plat import resources
    from miro.plat import config
    GST_PLUGIN_PATH = os.path.join(resources.app_root(), 'gstreamer-0.10')
    os.environ["GST_PLUGIN_PATH"] = GST_PLUGIN_PATH
    os.environ["GST_PLUGIN_SYSTEM_PATH"] = GST_PLUGIN_PATH
    # normally we'd use app.config to get this, but we're starting up
    os.environ["GST_REGISTRY"] = os.path.join(config._get_support_directory(),
                                              'gst_registry.bin')

    theme = None
    # Should have code to figure out the theme.

    from miro.plat import pipeipc
    try:
        pipe_server = pipeipc.Server()
    except pipeipc.PipeExists:
        pipeipc.send_command_line_args()
        return
    pipe_server.start_process()

    from miro.plat import prelogger
    prelogger.install()

    from miro.plat.utils import initialize_locale
    initialize_locale()

    from miro import bootstrap
    bootstrap.bootstrap()

    from miro.plat import commandline
    args = commandline.get_command_line()[1:]

    if '--theme' in args:
        index = args.index('--theme')
        theme = args[index+1]
        del args[index:index+1]

    if '--debug' in args:
        index = args.index('--debug')
        del args[index]
        from miro import app
        app.debugmode = True

    from miro import startup
    startup.initialize(theme)

    from miro.plat import migrateappname
    migrateappname.migrateSupport('Democracy', 'Miro')

    from miro import commandline
    commandline.set_command_line_args(args)

    # Kick off the application
    startfrontend.run_application('widgets', {}, None)
    pipe_server.quit()