Exemplo n.º 1
0
 def _load_entry(self, entry):
     # pylint: disable=W0703
     if self._check_extras:
         try:
             entry.require()
         except Exception as err:
             raise PluginDBError(
                 ('Requirements are not satisfied '
                  'for {}:{}: {}').format(self._group, entry.name,
                                          str(err)))
     try:
         result = entry.load()
     except Exception as err:
         # log full traceback of the bad entry to help support
         traceback.print_exc()
         raise PluginDBError('Unable to load {}:{}: {}'.format(
             self._group, entry.name, str(err)))
     if self._interface:
         try:
             verifyClass(self._interface, result)
         except Invalid as err:
             raise PluginDBError(
                 'Plugin {}:{} does not implement {}: {}'.format(
                     self._group, entry.name, self._interface.__name__,
                     str(err)))
     return result
Exemplo n.º 2
0
    def _get(self, name):
        path = name.split('.', 1)
        key = path.pop(0)
        is_leaf = not path
        child = self._children.get(key)

        if isinstance(child, _PluginEntry):
            if not is_leaf:
                raise PluginDBError('Excessive namespace specification: %s' %
                                    path[0])
            return child
        elif child is None:
            raise PluginDBError('Unknown component name: %s' % name)
        else:
            return child._get(path[0])
Exemplo n.º 3
0
class _Plugins(object):
    """
    represent plugins within a namespace
    """
    def __init__(self, namespace, interface=None, check_extras=True):
        if interface is not None:
            assert interface.isOrExtends(IPlugin)

        self._group = '%s.%s' % (_NAMESPACE_BASE, namespace)

        self._interface = interface
        self._check_extras = check_extras

        self._real_tree = None

    def _load_entry(self, entry):
        # pylint: disable=W0703
        if self._check_extras:
            try:
                entry.require()
            except Exception, err:
                raise PluginDBError('Requirements are not satisfied '
                                    'for %s:%s: %s' %
                                    (self._group, entry.name, str(err)))
        try:
            result = entry.load()
        except Exception, err:
            raise PluginDBError('Unable to load %s:%s: %s' %
                                (self._group, entry.name, str(err)))
Exemplo n.º 4
0
    def __getattr__(self, name):
        child = self._children.get(name)
        if child is None:
            raise PluginDBError('Unknown component name: {}'.format(name))

        if isinstance(child, _PluginEntry):
            return child.value
        return child
Exemplo n.º 5
0
 def _load_entry(self, entry):
     # pylint: disable=W0703
     if self._check_extras:
         try:
             entry.require()
         except Exception, err:
             raise PluginDBError('Requirements are not satisfied '
                                 'for %s:%s: %s' %
                                 (self._group, entry.name, str(err)))
Exemplo n.º 6
0
 def _load_entry(self, entry):
     # pylint: disable=W0703
     if self._check_extras:
         try:
             entry.require()
         except Exception as err:
             raise PluginDBError('Requirements are not satisfied '
                                 'for %s:%s: %s' %
                                 (self._group, entry.name, str(err)))
     try:
         result = entry.load()
     except Exception as err:
         raise PluginDBError('Unable to load %s:%s: %s' %
                             (self._group, entry.name, str(err)))
     if self._interface:
         try:
             verifyClass(self._interface, result)
         except Invalid as err:
             raise PluginDBError('Plugin %s:%s does not implement %s: %s' %
                                 (self._group, entry.name,
                                  self._interface.__name__, str(err)))
     return result
Exemplo n.º 7
0
 def _load_entry(self, entry):
     # pylint: disable=W0703
     if self._check_extras:
         try:
             entry.require()
         except Exception as e:
             raise PluginDBError(
                 'Requirements are not satisfied '
                 f'for {self._group}:{entry.name}: {str(e)}') from e
     try:
         result = entry.load()
     except Exception as e:
         # log full traceback of the bad entry to help support
         traceback.print_exc()
         raise PluginDBError(
             f'Unable to load {self._group}:{entry.name}: {str(e)}') from e
     if self._interface:
         try:
             verifyClass(self._interface, result)
         except Invalid as e:
             raise PluginDBError(
                 f'Plugin {self._group}:{entry.name} does not implement '
                 f'{self._interface.__name__}: {str(e)}') from e
     return result
Exemplo n.º 8
0
    def _add(self, name, entry):
        path = name.split('.', 1)
        key = path.pop(0)
        is_leaf = not path
        child = self._children.get(key)

        if is_leaf:
            if child is not None:
                assert isinstance(child, _PluginEntry)
                if child != entry:
                    raise PluginDBError(
                        f'Duplicate entry point for "{child.group}:{child.name}".\n'
                        f'  Previous definition {child.info}\n'
                        f'  This definition {entry.info}')
            else:
                self._children[key] = entry
        else:
            if child is None:
                child = _NSNode()
            assert isinstance(child, _NSNode)
            child._add(path[0], entry)
            self._children[key] = child
Exemplo n.º 9
0
                entry.require()
            except Exception, err:
                raise PluginDBError('Requirements are not satisfied '
                                    'for %s:%s: %s' %
                                    (self._group, entry.name, str(err)))
        try:
            result = entry.load()
        except Exception, err:
            raise PluginDBError('Unable to load %s:%s: %s' %
                                (self._group, entry.name, str(err)))
        if self._interface:
            try:
                verifyClass(self._interface, result)
            except Invalid, err:
                raise PluginDBError('Plugin %s:%s does not implement %s: %s' %
                                    (self._group, entry.name,
                                     self._interface.__name__, str(err)))
        return result

    @property
    def _tree(self):
        if self._real_tree is None:
            self._real_tree = _NSNode()
            for entry in iter_entry_points(self._group):
                self._real_tree.add(
                    entry.name,
                    _PluginEntry(self._group, entry, self._load_entry))
        return self._real_tree

    def load(self):
        self._tree.load()