def test_correct_exception_propagated_from_plugin_manager(self):
        plugin_manager = CompositePluginManager(
            plugin_managers=[RaisingPluginManager()]
        )

        with self.assertRaises(CustomException):
            plugin_manager.start()
    def test_propogate_plugin_added_or_remove_events_from_plugin_managers(self):

        a = PluginManager()
        b = PluginManager()
        
        composite_plugin_manager = CompositePluginManager(
            plugin_managers = [a, b]
        )
        composite_plugin_manager._plugins
        
        def added(obj, trait_name, old, new):
            added.count += 1
        added.count = 0

        composite_plugin_manager.on_trait_change(added, 'plugin_added')

        def removed(obj, trait_name, old, new):
            removed.count += 1
        removed.count = 0

        composite_plugin_manager.on_trait_change(removed, 'plugin_removed')

        a.add_plugin(Plugin(id='foo'))
        self.assertEqual(1, self._plugin_count(composite_plugin_manager))
                         
        a.remove_plugin(a.get_plugin('foo'))
        self.assertEqual(0, self._plugin_count(composite_plugin_manager))
        
        return
    def test_find_no_plugins_if_there_are_no_plugins_in_plugin_managers(self):

        plugin_manager = CompositePluginManager(
            plugin_managers=[PluginManager(), PluginManager()])
        ids = [plugin.id for plugin in plugin_manager]

        self.assertEqual(0, len(ids))
    def test_application_gets_propogated_to_plugin_managers(self):

        application = Application()

        composite_plugin_manager = CompositePluginManager(
            application=application,
            plugin_managers=[PluginManager(), PluginManager()])

        for plugin_manager in composite_plugin_manager.plugin_managers:
            self.assertEqual(application, plugin_manager.application)
    def test_propogate_plugin_added_or_remove_events_from_plugin_managers(
            self):

        a = PluginManager()
        b = PluginManager()

        composite_plugin_manager = CompositePluginManager(
            plugin_managers=[a, b])
        composite_plugin_manager._plugins

        def added(obj, trait_name, old, new):
            added.count += 1

        added.count = 0

        composite_plugin_manager.on_trait_change(added, 'plugin_added')

        def removed(obj, trait_name, old, new):
            removed.count += 1

        removed.count = 0

        composite_plugin_manager.on_trait_change(removed, 'plugin_removed')

        a.add_plugin(Plugin(id='foo'))
        self.assertEqual(1, self._plugin_count(composite_plugin_manager))

        a.remove_plugin(a.get_plugin('foo'))
        self.assertEqual(0, self._plugin_count(composite_plugin_manager))
    def test_find_plugins_in_a_single_plugin_manager(self):

        plugin_manager = CompositePluginManager(plugin_managers=[
            PluginManager(
                plugins=[SimplePlugin(id='red'),
                         SimplePlugin(id='yellow')])
        ])
        ids = [plugin.id for plugin in plugin_manager]

        self.assertEqual(2, len(ids))
        self.assertIn('red', ids)
        self.assertIn('yellow', ids)

        self._test_start_and_stop(plugin_manager, ['red', 'yellow'])
示例#7
0
    def test_find_plugins_in_a_single_plugin_manager(self):

        plugin_manager = CompositePluginManager(plugin_managers=[
            PluginManager(
                plugins=[SimplePlugin(id="red"),
                         SimplePlugin(id="yellow")])
        ])
        ids = [plugin.id for plugin in plugin_manager]

        self.assertEqual(2, len(ids))
        self.assertIn("red", ids)
        self.assertIn("yellow", ids)

        self._test_start_and_stop(plugin_manager, ["red", "yellow"])
示例#8
0
def run(plugins=[], use_eggs=True, egg_path=[], image_path=[], template_path=[], startup_task="", application_name="Omnivore", debug_log=False, document_class=None):
    """Start the application
    
    :param plugins: list of user plugins
    :param use_eggs Boolean: search for setuptools plugins and plugins in local eggs?
    :param egg_path: list of user-specified paths to search for more plugins
    :param startup_task string: task factory identifier for task shown in initial window
    :param application_name string: change application name instead of default Omnivore
    """
    EnthoughtWxApp.mac_menubar_app_name = application_name
    _app = EnthoughtWxApp(redirect=False)
    if False:  # enable this to use FilterEvent
        _app.FilterEvent = _app.FilterEventMouseWheel

    # Enthought library imports.
    from envisage.api import PluginManager
    from envisage.core_plugin import CorePlugin

    # Local imports.
    from omnivore.framework.application import FrameworkApplication
    from omnivore.framework.plugin import OmnivoreTasksPlugin, OmnivoreMainPlugin
    from omnivore.file_type.plugin import FileTypePlugin
    from omnivore import get_image_path
    from omnivore.utils.jobs import get_global_job_manager

    # Include standard plugins
    core_plugins = [ CorePlugin(), OmnivoreTasksPlugin(), OmnivoreMainPlugin(), FileTypePlugin() ]
    if sys.platform == "darwin":
        from omnivore.framework.osx_plugin import OSXMenuBarPlugin
        core_plugins.append(OSXMenuBarPlugin())

    import omnivore.file_type.recognizers
    core_plugins.extend(omnivore.file_type.recognizers.plugins)

    import omnivore.plugins
    core_plugins.extend(omnivore.plugins.plugins)

    # Add the user's plugins
    core_plugins.extend(plugins)

    # Check basic command line args
    default_parser = argparse.ArgumentParser(description="Default Parser")
    default_parser.add_argument("--no-eggs", dest="use_eggs", action="store_false", default=True, help="Do not load plugins from python eggs")
    options, extra_args = default_parser.parse_known_args()

    # The default is to use the specified plugins as well as any found
    # through setuptools and any local eggs (if an egg_path is specified).
    # Egg/setuptool plugin searching is turned off by the use_eggs parameter.
    default = PluginManager(
        plugins = core_plugins,
    )
    if use_eggs and options.use_eggs:
        from pkg_resources import Environment, working_set
        from envisage.api import EggPluginManager
        from envisage.composite_plugin_manager import CompositePluginManager

        # Find all additional eggs and add them to the working set
        environment = Environment(egg_path)
        distributions, errors = working_set.find_plugins(environment)
        if len(errors) > 0:
            raise SystemError('cannot add eggs %s' % errors)
        logger = logging.getLogger()
        logger.debug('added eggs %s' % distributions)
        map(working_set.add, distributions)

        # The plugin manager specifies which eggs to include and ignores all others
        egg = EggPluginManager(
            include = [
                'omnivore.tasks',
            ]
        )

        plugin_manager = CompositePluginManager(
            plugin_managers=[default, egg]
        )
    else:
        plugin_manager = default

    # Add omnivore icons after all image paths to allow user icon themes to take
    # precidence
    from pyface.resource_manager import resource_manager
    import os
    image_paths = image_path[:]
    image_paths.append(get_image_path("icons"))
    image_paths.append(get_image_path("../omnivore8bit/icons"))
    resource_manager.extra_paths.extend(image_paths)

    from omnivore.templates import template_subdirs
    template_subdirs.extend(template_path)

    kwargs = {}
    if startup_task:
        kwargs['startup_task'] = startup_task
    if application_name:
        kwargs['name'] = application_name
    if document_class:
        kwargs['document_class'] = document_class

    # Create a debugging log
    if debug_log:
        filename = app.get_log_file_name("debug")
        handler = logging.FileHandler(filename)
        logger = logging.getLogger('')
        logger.addHandler(handler)
        logger.setLevel(logging.DEBUG)

    # Turn off omnivore log debug messages by default
    log = logging.getLogger("omnivore")
    log.setLevel(logging.INFO)

    # check for logging stuff again to pick up any new loggers loaded since
    # startup
    import omnivore.utils.wx.error_logger as error_logger
    if "-d" in extra_args:
        i = extra_args.index("-d")
        error_logger.enable_loggers(extra_args[i+1])
    app = FrameworkApplication(plugin_manager=plugin_manager, command_line_args=extra_args, **kwargs)

    app.run()

    job_manager = get_global_job_manager()
    if job_manager is not None:
        job_manager.shutdown()