Esempio n. 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
Esempio n. 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
Esempio n. 3
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))
Esempio n. 4
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
Esempio n. 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
Esempio n. 6
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