コード例 #1
0
def load_external_components(typesys):
    """Load all external types defined by iotile plugins.

    This allows plugins to register their own types for type annotations and
    allows all registered iotile components that have associated type libraries to
    add themselves to the global type system.
    """

    # Find all of the registered IOTile components and see if we need to add any type libraries for them
    from iotile.core.dev.registry import ComponentRegistry

    reg = ComponentRegistry()
    modules = reg.list_components()

    typelibs = reduce(lambda x, y: x+y, [reg.find_component(x).find_products('type_package') for x in modules], [])
    for lib in typelibs:
        if lib.endswith('.py'):
            lib = lib[:-3]

        typesys.load_external_types(lib)
コード例 #2
0
ファイル: hwmanager.py プロジェクト: kgosalia/coretools
    def _setup_proxies(self):
        """Load in proxy module objects for all of the registered components on this system."""

        # Find all of the registered IOTile components and see if we need to add any proxies for them
        reg = ComponentRegistry()
        modules = reg.list_components()

        proxies = reduce(
            lambda x, y: x + y,
            [reg.find_component(x).proxy_modules() for x in modules], [])
        proxy_classes = []
        for prox in proxies:
            proxy_classes += self._load_module_classes(prox,
                                                       TileBusProxyObject)

        # Find all installed proxy objects through registered entry points
        for entry in pkg_resources.iter_entry_points('iotile.proxy'):
            mod = entry.load()
            proxy_classes += [
                x for x in itervalues(mod.__dict__)
                if inspect.isclass(x) and issubclass(x, TileBusProxyObject)
                and x != TileBusProxyObject
            ]

        for obj in proxy_classes:
            if obj.__name__ in self._proxies:
                continue  #Don't readd proxies that we already know about

            self._proxies[obj.__name__] = obj

            #Check if this object matches a specific shortened name so that we can
            #automatically match a hw module to a proxy without user intervention
            try:
                short_name = obj.ModuleName()
                if short_name in self._name_map:
                    self._name_map[short_name].append(obj)
                else:
                    self._name_map[short_name] = [obj]
            except Exception:  #pylint: disable=broad-except;We don't want this to die if someone loads a misbehaving plugin
                self.logger.exception(
                    "Error importing misbehaving proxy module, skipping.")
コード例 #3
0
ファイル: hwmanager.py プロジェクト: kgosalia/coretools
    def _setup_apps(self):
        """Load in all iotile app objects for all registered or installed components on this system."""

        reg = ComponentRegistry()
        modules = reg.list_components()

        apps = reduce(lambda x, y: x + y,
                      [reg.find_component(x).app_modules() for x in modules],
                      [])
        app_classes = []
        for app in apps:
            app_classes += self._load_module_classes(app, IOTileApp)

        # Find all installed proxy objects through registered entry points
        for entry in pkg_resources.iter_entry_points('iotile.app'):
            mod = entry.load()
            app_classes += [
                x for x in itervalues(mod.__dict__) if inspect.isclass(x)
                and issubclass(x, IOTileApp) and x != IOTileApp
            ]

        for app in app_classes:
            try:
                matches = app.MatchInfo()
                name = app.AppName()
                for tag, ver_range, quality in matches:
                    if tag not in self._known_apps:
                        self._known_apps[tag] = []

                    self._known_apps[tag].append((ver_range, quality, app))

                if name in self._named_apps:
                    self.logger.warning(
                        "Added an app module with an existing name, overriding previous app, name=%s",
                        name)

                self._named_apps[name] = app
            except Exception:  #pylint: disable=broad-except;We don't want this to die if someone loads a misbehaving plugin
                self.logger.exception(
                    "Error importing misbehaving app module, skipping.")