def test_exclude_specific(self):
        """ exclude specific """

        # Add all of the eggs in the egg basket.
        self._add_eggs_on_path([self.egg_dir])

        # The Ids of the plugins that we expect the plugin manager to find.
        expected = ['acme.bar']

        # We explicitly limit the plugins to be just the 'acme' test plugins
        # because otherwise the egg plugin manager will pick up *every* plugin
        # in *every* egg on sys.path!
        include = ['acme.*']

        # Now exclude all but 'acme.bar'...
        exclude = ['acme\.foo', 'acme\.baz']

        # Make sure that the plugin manager excludes the specified plugins.
        plugin_manager = EggPluginManager(include=include, exclude=exclude)

        # Make sure the plugin manager found only the required plugins and that
        # it starts and stops them correctly..
        self._test_start_and_stop(plugin_manager, expected)

        return
Ejemplo n.º 2
0
def run():
    """ The function that starts your application. """

    # We do the imports here because the modules may well be in eggs that get
    # added to the path in 'main'.
    from envisage.api import EggPluginManager
    from acme.acmelab.api import Acmelab

    # Create an application that uses the egg plugin manager to find its
    # plugins.
    acmelab = Acmelab(plugin_manager=EggPluginManager())

    # Run it! This starts the application, starts the GUI event loop, and when
    # that terminates, stops the application.
    return acmelab.run()
Ejemplo n.º 3
0
    def test_uses_global_working_set_by_default(self):
        original_working_set = pkg_resources.working_set

        try:
            # Create fresh working set for this test, to make sure that the
            # plugin manager picks up the *current* value of
            # pkg_resources.working_set.
            pkg_resources.working_set = pkg_resources.WorkingSet()
            plugin_manager = EggPluginManager()
            self.assertEqual(
                plugin_manager.working_set,
                pkg_resources.working_set,
            )
        finally:
            pkg_resources.working_set = original_working_set
    def test_no_include_or_exclude(self):
        """ no include or exclude """

        # Add all of the eggs in the egg basket.
        self._add_eggs_on_path([self.egg_dir])

        # Make sure that the plugin manager only includes those plugins.
        plugin_manager = EggPluginManager()

        # We don't know how many plugins we will actually get - it depends on
        # what eggs are on sys.path! What we *do* know however is the the 3
        # 'acme' test eggs should be in there!
        ids = [plugin.id for plugin in plugin_manager]

        self.assertTrue("acme.foo" in ids)
        self.assertTrue("acme.bar" in ids)
        self.assertTrue("acme.baz" in ids)
    def test_include_multiple(self):
        """ include multiple """

        # Add all of the eggs in the egg basket.
        self._add_eggs_on_path([self.egg_dir])

        # The Ids of the plugins that we expect the plugin manager to find.
        expected = ["acme.foo", "acme.bar", "acme.baz"]

        # We explicitly limit the plugins to be just the 'acme' test plugins
        # because otherwise the egg plugin manager will pick up *every* plugin
        # in *every* egg on sys.path!
        include = ["acme.*"]

        # Make sure that the plugin manager only includes those plugins.
        plugin_manager = EggPluginManager(include=include)

        # Make sure the plugin manager found only the required plugins and that
        # it starts and stops them correctly..
        self._test_start_and_stop(plugin_manager, expected)
Ejemplo n.º 6
0
def run():
    """ The function that starts your application. """

    # Enthought library imports.
    #
    # We do the imports here in case the Enthought eggs are loaded dyanmically
    # via the 'EGG_PATH'.
    from envisage.api import Application, EggPluginManager

    # Create a plugin manager that ignores all eggs except the ones that we
    # need for this example.
    plugin_manager = EggPluginManager(
        include=['envisage.core', 'acme.motd', 'acme.motd.software_quotes'])

    # Create an application that uses the egg plugin manager to find its
    # plugins.
    application = Application(id='acme.motd', plugin_manager=plugin_manager)

    # Run it!
    return application.run()
Ejemplo n.º 7
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()