예제 #1
0
    def _load_source(self, source_uuid):
        try:
            source_config = self._source_service.get_by_uuid(source_uuid)
        except exception.NoSuchSource:
            logger.info('no source found with uuid %s', source_uuid)
            return

        on_missing_entrypoints = partial(
            plugin_helpers.on_missing_entrypoints,
            self._namespace,
        )
        manager = NamedExtensionManager(
            self._namespace,
            [source_config['backend']],
            on_load_failure_callback=plugin_helpers.on_load_failure,
            on_missing_entrypoints_callback=on_missing_entrypoints,
            invoke_on_load=True,
        )

        def load(extension):
            return self._add_source_with_config(extension, source_config)

        try:
            for result in manager.map(load):
                return result
        except stevedore.exception.NoMatches:
            return None
예제 #2
0
def run_hooks(hook, options, args, output=None):
    log = logging.getLogger('virtualenvwrapper.hook_loader')
    if output is None:
        output = sys.stdout

    namespace = 'virtualenvwrapper.%s' % hook
    if options.names:
        log.debug('looking for %s hooks %s' % (namespace, options.names))
        hook_mgr = NamedExtensionManager(namespace, options.names)
    else:
        log.debug('looking for %s hooks' % namespace)
        hook_mgr = ExtensionManager(namespace)

    if options.listing:

        def show(ext):
            output.write('  %-10s -- %s\n' %
                         (ext.name, inspect.getdoc(ext.plugin) or ''))

        try:
            hook_mgr.map(show)
        except RuntimeError:  # no templates
            output.write('  No templates installed.\n')

    elif options.sourcing:

        def get_source(ext, args):
            # Show the shell commands so they can
            # be run in the calling shell.
            log.debug('getting source instructions for %s' % ext.name)
            contents = (ext.plugin(args) or '').strip()
            if contents:
                output.write('# %s\n' % ext.name)
                output.write(contents)
                output.write("\n")

        try:
            hook_mgr.map(get_source, args[1:])
        except RuntimeError:
            pass

    else:
        # Just run the plugin ourselves
        def invoke(ext, args):
            log.debug('running %s' % ext.name)
            ext.plugin(args)

        try:
            hook_mgr.map(invoke, args[1:])
        except RuntimeError:
            pass
예제 #3
0
 def threshold_evaluators(self):
     if not self._threshold_evaluators:
         threshold_types = ('threshold', 'gnocchi_resources_threshold',
                            'gnocchi_aggregation_by_metrics_threshold',
                            'gnocchi_aggregation_by_resources_threshold')
         self._threshold_evaluators = NamedExtensionManager(
             'aodh.evaluator', threshold_types, invoke_on_load=True,
             invoke_args=(self.conf,))
     return self._threshold_evaluators
예제 #4
0
def _load_plugins(namespace, names, dependencies):
    names = plugin_helpers.enabled_names(names)
    logger.debug('Enabled plugins: %s', names)
    if not names:
        logger.info('no enabled plugins')
        return

    manager = NamedExtensionManager(
        namespace,
        names,
        name_order=True,
        on_load_failure_callback=plugin_helpers.on_load_failure,
        on_missing_entrypoints_callback=plugin_helpers.on_missing_entrypoints,
        invoke_on_load=True)

    def _load_plugin(ext, *args, **kwargs):
        return ext.name, plugin_helpers.load_plugin(ext, *args, **kwargs)

    return manager, dict(manager.map(_load_plugin, dependencies))
예제 #5
0
def run_hooks(hook, options, args, output=None):
    if output is None:
        output = sys.stdout

    namespace = 'virtualenvwrapper.%s' % hook
    if options.names:
        hook_mgr = NamedExtensionManager(namespace, options.names)
    else:
        hook_mgr = ExtensionManager(namespace)

    if options.listing:

        def show(ext):
            output.write('  %-10s -- %s\n' %
                         (ext.name, inspect.getdoc(ext.plugin) or ''))

        hook_mgr.map(show)

    elif options.sourcing:

        def get_source(ext, args):
            # Show the shell commands so they can
            # be run in the calling shell.
            contents = (ext.plugin(args) or '').strip()
            if contents:
                output.write('# %s\n' % ext.name)
                output.write(contents)
                output.write("\n")

        try:
            hook_mgr.map(get_source, args[1:])
        except RuntimeError:
            pass

    else:
        # Just run the plugin ourselves
        def invoke(ext, args):
            ext.plugin(args)

        try:
            hook_mgr.map(invoke, args[1:])
        except RuntimeError:
            pass
예제 #6
0
def run_hooks(hook, options, args, output=None):
    log = logging.getLogger('virtualenvwrapper.hook_loader')
    if output is None:
        output = sys.stdout

    namespace = 'virtualenvwrapper.%s' % hook
    if options.names:
        log.debug('looking for %s hooks %s' % (namespace, options.names))
        hook_mgr = NamedExtensionManager(namespace, options.names)
    else:
        log.debug('looking for %s hooks' % namespace)
        hook_mgr = ExtensionManager(namespace)

    if options.listing:
        def show(ext):
            output.write('  %-10s -- %s\n' %
                         (ext.name, inspect.getdoc(ext.plugin) or ''))
        try:
            hook_mgr.map(show)
        except RuntimeError:  # no templates
            output.write('  No templates installed.\n')

    elif options.sourcing:
        def get_source(ext, args):
            # Show the shell commands so they can
            # be run in the calling shell.
            log.debug('getting source instructions for %s' % ext.name)
            contents = (ext.plugin(args) or '').strip()
            if contents:
                output.write('# %s\n' % ext.name)
                output.write(contents)
                output.write("\n")
        try:
            hook_mgr.map(get_source, args[1:])
        except RuntimeError:
            pass

    else:
        # Just run the plugin ourselves
        def invoke(ext, args):
            log.debug('running %s' % ext.name)
            ext.plugin(args)
        try:
            hook_mgr.map(invoke, args[1:])
        except RuntimeError:
            pass
예제 #7
0
def run_hooks(hook, options, args, output=None):
    if output is None:
        output = sys.stdout

    namespace = 'virtualenvwrapper.%s' % hook
    if options.names:
        hook_mgr = NamedExtensionManager(namespace, options.names)
    else:
        hook_mgr = ExtensionManager(namespace)

    if options.listing:
        def show(ext):
            output.write('  %-10s -- %s\n' %
                         (ext.name, inspect.getdoc(ext.plugin) or ''))
        hook_mgr.map(show)

    elif options.sourcing:
        def get_source(ext, args):
            # Show the shell commands so they can
            # be run in the calling shell.
            contents = (ext.plugin(args) or '').strip()
            if contents:
                output.write('# %s\n' % ext.name)
                output.write(contents)
                output.write("\n")
        try:
            hook_mgr.map(get_source, args[1:])
        except RuntimeError:
            pass

    else:
        # Just run the plugin ourselves
        def invoke(ext, args):
            ext.plugin(args)
        try:
            hook_mgr.map(invoke, args[1:])
        except RuntimeError:
            pass
예제 #8
0
 def test_named_manager_should_populate_names(self):
     extensions = [test_extension, test_extension2]
     em = NamedExtensionManager.make_test_instance(extensions)
     self.assertEqual(em.names(), ['test_extension', 'another_one'])
예제 #9
0
 def test_named_manager_should_use_supplied_namespace(self):
     namespace = 'testing.1.2.3'
     em = NamedExtensionManager.make_test_instance([], namespace=namespace)
     self.assertEqual(namespace, em.namespace)
예제 #10
0
 def test_named_manager_should_have_default_namespace(self):
     em = NamedExtensionManager.make_test_instance([])
     self.assertEqual(em.namespace, 'TESTING')
예제 #11
0
def test_named_manager_should_have_default_namespace():
    em = NamedExtensionManager.make_test_instance([])

    assert em.namespace
예제 #12
0
def test_named_manager_should_use_supplied_namespace():
    namespace = 'testing.1.2.3'
    em = NamedExtensionManager.make_test_instance([], namespace=namespace)

    assert namespace == em.namespace
예제 #13
0
def test_named_manager_should_populate_names():
    extensions = [test_extension, test_extension2]
    em = NamedExtensionManager.make_test_instance(extensions)

    assert ['test_extension', 'another_one'] == em.names()
def test_named_manager_should_use_supplied_namespace():
    namespace = 'testing.1.2.3'
    em = NamedExtensionManager.make_test_instance([], namespace=namespace)

    assert namespace == em.namespace
예제 #15
0
def test_named_manager_should_use_supplied_extensions():
    extensions = [test_extension, test_extension2]
    em = NamedExtensionManager.make_test_instance(extensions)

    assert extensions == em.extensions
예제 #16
0
 def test_named_manager_should_use_supplied_extensions(self):
     extensions = [test_extension, test_extension2]
     em = NamedExtensionManager.make_test_instance(extensions)
     self.assertEqual(extensions, em.extensions)
예제 #17
0
 def test_named_manager_should_use_supplied_namespace(self):
     namespace = 'testing.1.2.3'
     em = NamedExtensionManager.make_test_instance([], namespace=namespace)
     self.assertEqual(namespace, em.namespace)
예제 #18
0
 def test_named_manager_should_have_default_namespace(self):
     em = NamedExtensionManager.make_test_instance([])
     self.assertEqual(em.namespace, 'TESTING')
def test_named_manager_should_populate_names():
    extensions = [test_extension, test_extension2]
    em = NamedExtensionManager.make_test_instance(extensions)

    assert ['test_extension', 'another_one'] == em.names()
예제 #20
0
 def test_named_manager_should_use_supplied_extensions(self):
     extensions = [test_extension, test_extension2]
     em = NamedExtensionManager.make_test_instance(extensions)
     self.assertEqual(extensions, em.extensions)
def test_named_manager_should_use_supplied_extensions():
    extensions = [test_extension, test_extension2]
    em = NamedExtensionManager.make_test_instance(extensions)

    assert extensions == em.extensions
예제 #22
0
 def test_named_manager_should_populate_names(self):
     extensions = [test_extension, test_extension2]
     em = NamedExtensionManager.make_test_instance(extensions)
     self.assertEqual(em.names(), ['test_extension', 'another_one'])
def test_named_manager_should_have_default_namespace():
    em = NamedExtensionManager.make_test_instance([])

    assert em.namespace