Ejemplo n.º 1
0
    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()
        proxy_classes = reg.load_extensions('iotile.proxy',
                                            class_filter=TileBusProxyObject,
                                            product_name="proxy_module")

        for name, obj in proxy_classes:
            proxy_key = obj.__name__ + ':' + name

            # awu_10/01/19 - we want to add all proxies even if duplicate but diff version
            # if proxy_key in self._proxies:
            #     continue

            self._proxies[proxy_key] = 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 object %s, skipping.",
                    obj)
Ejemplo n.º 2
0
    def _load_providers(self):
        """Load all config_variables providers using pkg_resources
        """

        reg = ComponentRegistry()
        for name, provider in reg.load_extensions('iotile.config_variables'):
            try:
                prefix, conf_vars = provider()
            except (ValueError, TypeError) as exc:
                raise ExternalError("Error loading config variables",
                                    package=name,
                                    error=str(exc))

            for var in conf_vars:
                if len(var) != 3 and len(var) != 4:
                    raise ExternalError(
                        "Error loading config variable, invalid length",
                        data=var,
                        package=name)

                name = prefix + ':' + var[0]
                if len(var) == 3:
                    var_obj = ConfigVariable(var[0], var[1], var[2], MISSING)
                else:
                    var_obj = ConfigVariable(name, var[1], var[2], var[3])

                if name in self._known_variables:
                    raise ExternalError(
                        "The same config variable was defined twice",
                        name=name)

                self._known_variables[name] = var_obj
Ejemplo n.º 3
0
    def _setup_apps(self):
        """Load in all iotile app objects for all registered or installed components on this system."""

        reg = ComponentRegistry()
        app_classes = reg.load_extensions('iotile.app',
                                          class_filter=IOTileApp,
                                          product_name="app_module")

        for _name, 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 %s, skipping.",
                    app)
Ejemplo n.º 4
0
def find_proxy_plugin(component, plugin_name):
    """ Attempt to find a proxy plugin provided by a specific component

    Args:
        component (string): The name of the component that provides the plugin
        plugin_name (string): The name of the plugin to load

    Returns:
        TileBuxProxyPlugin: The plugin, if found, otherwise raises DataError
    """

    reg = ComponentRegistry()

    plugins = reg.load_extensions('iotile.proxy_plugin',
                                  comp_filter=component,
                                  class_filter=TileBusProxyPlugin,
                                  product_name='proxy_plugin')

    for _name, plugin in plugins:
        if plugin.__name__ == plugin_name:
            return plugin

    raise DataError(
        "Could not find proxy plugin module in registered components or installed distributions",
        component=component,
        name=plugin_name)
Ejemplo n.º 5
0
    def _create_stream(self, force_adapter=None):
        conn_string = None
        port = self.port
        if port is not None and "," in port:
            port, conn_string = port.split(',')

        if port is not None:
            port = port.strip()
        if conn_string is not None:
            conn_string = conn_string.strip()

        # Check if we're supposed to use a specific device adapter
        if force_adapter is not None:
            return AdapterCMDStream(force_adapter,
                                    port,
                                    conn_string,
                                    record=self._record)

        # First check if this is the special none stream that creates a transport channel nowhere
        if self.transport == 'none':
            return CMDStream(port, conn_string, record=self._record)

        # Next attempt to find a CMDStream that is registered for this transport type
        reg = ComponentRegistry()
        for _name, stream_factory in reg.load_extensions(
                'iotile.cmdstream', name_filter=self.transport):
            return stream_factory(port, conn_string, record=self._record)

        # Otherwise attempt to find a DeviceAdapter that we can turn into a CMDStream
        for _name, adapter_factory in reg.load_extensions(
                'iotile.device_adapter', name_filter=self.transport):
            return AdapterCMDStream(adapter_factory(port),
                                    port,
                                    conn_string,
                                    record=self._record)

        raise HardwareError(
            "Could not find transport object registered to handle passed transport type",
            transport=self.transport)
Ejemplo n.º 6
0
    def _load_functions(self):
        """Load all config functions that should be bound to this ConfigManager

        Config functions allow you to add functions that will appear under ConfigManager
        but call your specified function.  This is useful for adding complex configuration
        behavior that is callable from the iotile command line tool
        """

        reg = ComponentRegistry()
        for _, conf_func in reg.load_extensions('iotile.config_function'):
            try:
                name = conf_func.__name__

                self.add_function(name, conf_func)
            except (ValueError, TypeError) as exc:
                raise ExternalError("Error loading config function", name=name, error=str(exc))
Ejemplo n.º 7
0
    def _create_stream(self, force_adapter=None, record=None):
        conn_string = None
        port = self.port

        if port is not None:
            port = port.strip()

        # Check if we're supposed to use a specific device adapter
        if force_adapter is not None:
            return AdapterStream(force_adapter, record=record)

        # Attempt to find a DeviceAdapter that can handle this transport type
        reg = ComponentRegistry()

        for _, adapter_factory in reg.load_extensions(
                'iotile.device_adapter', name_filter=self.transport):
            return AdapterStream(adapter_factory(port), record=record)

        raise HardwareError(
            "Could not find transport object registered to handle passed transport type",
            transport=self.transport)