How to use the stevedore.exception.NoMatches function in stevedore

To help you get started, we’ve selected a few stevedore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wongnai / eastern / eastern / yaml_formatter / formatter.py View on Github external
# line must only have precending spaces
        if not re.match(r"^\s*$", before):
            return line

        splitted = after.strip().split(" ", 1)
        command = splitted[0]
        args = []

        if len(splitted) > 1:
            args = splitted[1]

        try:
            func = DriverManager(DRIVER_NS, command)
            func.propagate_map_exceptions = True
        except NoMatches:
            self.logger.debug("Command not found %s", command, exc_info=True)
            return line

        output = func(lambda ext: ext.plugin(args, line=line, formatter=self))

        if output is None:
            output = []
        elif isinstance(output, str):
            output = output.split(os.linesep)

        output = os.linesep.join([before + item for item in output])

        output = self.plugin.chain("line_post_hook", output, formatter=self)
        return output
github wongnai / eastern / eastern / plugin.py View on Github external
def map(self, *args, **kwargs):
        try:
            return super().map(*args, **kwargs)
        except NoMatches:
            return []
github openstack / stevedore / stevedore / driver.py View on Github external
def _init_plugins(self, extensions):
        super(DriverManager, self)._init_plugins(extensions)

        if not self.extensions:
            name = self._names[0]
            raise NoMatches('No %r driver found, looking for %r' %
                            (self.namespace, name))
        if len(self.extensions) > 1:
            discovered_drivers = ','.join(e.entry_point_target
                                          for e in self.extensions)

            raise MultipleMatches('Multiple %r drivers found: %s' %
                                  (self.namespace, discovered_drivers))
github openstack / stevedore / stevedore / extension.py View on Github external
The first argument to func(), 'ext', is the
        :class:`~stevedore.extension.Extension` instance.

        Exceptions raised from within func() are propagated up and
        processing stopped if self.propagate_map_exceptions is True,
        otherwise they are logged and ignored.

        :param func: Callable to invoke for each extension.
        :param args: Variable arguments to pass to func()
        :param kwds: Keyword arguments to pass to func()
        :returns: List of values returned from func()
        """
        if not self.extensions:
            # FIXME: Use a more specific exception class here.
            raise NoMatches('No %s extensions found' % self.namespace)
        response = []
        for e in self.extensions:
            self._invoke_one_plugin(response.append, func, e, args, kwds)
        return response
github openstack / stevedore / stevedore / dispatch.py View on Github external
The first argument to func(), 'ext', is the
        :class:`~stevedore.extension.Extension` instance.

        Exceptions raised from within func() are propagated up and
        processing stopped if self.propagate_map_exceptions is True,
        otherwise they are logged and ignored.

        :param filter_func: Callable to test each extension.
        :param func: Callable to invoke for each extension.
        :param args: Variable arguments to pass to func()
        :param kwds: Keyword arguments to pass to func()
        :returns: List of values returned from func()
        """
        if not self.extensions:
            # FIXME: Use a more specific exception class here.
            raise NoMatches('No %s extensions found' % self.namespace)
        response = []
        for e in self.extensions:
            if filter_func(e, *args, **kwds):
                self._invoke_one_plugin(response.append, func, e, args, kwds)
        return response