How to use the haros.config_builder.ConfigurationError function in haros

To help you get started, we’ve selected a few haros 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 git-afsantos / haros / haros / config_builder.py View on Github external
def _get_node(self, pkg, exe, args):
        if exe == "nodelet":
            if not args:
                raise ConfigurationError("nodelet without args")
            args = args.split()
            if args[0] == "load" or args[0] == "standalone":
                if len(args) < 3:
                    raise ConfigurationError("nodelet load: too few arguments")
                pkg, exe = args[1].split("/")
        node = self.sources.nodes.get("node:" + pkg + "/" + exe)
        package = self.sources.packages.get("package:" + pkg)
        if not package:
            assert not node
            if self.no_hardcoded:
                self.log.debug(("skipping hard-coded node '%s/%s' "
                                "due to user option"), pkg, exe)
            else:
                self.log.debug("look up hard-coded node '%s/%s'", pkg, exe)
                node = HardcodedNodeParser.get(pkg, exe)
            if not node:
github git-afsantos / haros / haros / config_builder.py View on Github external
def _get_node(self, pkg, exe, args):
        if exe == "nodelet":
            if not args:
                raise ConfigurationError("nodelet without args")
            args = args.split()
            if args[0] == "load" or args[0] == "standalone":
                if len(args) < 3:
                    raise ConfigurationError("nodelet load: too few arguments")
                pkg, exe = args[1].split("/")
        node = self.sources.nodes.get("node:" + pkg + "/" + exe)
        package = self.sources.packages.get("package:" + pkg)
        if not package:
            assert not node
            if self.no_hardcoded:
                self.log.debug(("skipping hard-coded node '%s/%s' "
                                "due to user option"), pkg, exe)
            else:
                self.log.debug("look up hard-coded node '%s/%s'", pkg, exe)
                node = HardcodedNodeParser.get(pkg, exe)
            if not node:
                package = self._find_package(pkg)
        if not node:
            node = Node(exe, package, rosname = RosName("?"), nodelet = exe)
        return node
github git-afsantos / haros / haros / config_builder.py View on Github external
def add_rosrun(self, node):
        if self._invalid:
            raise ConfigurationError("invalid state")
        config = self.configuration
        self.log.debug("Adding rosrun command to configuration. Node: %s",
                       node.node_name)
        if node.is_nodelet:
            raise ValueError("Cannot add a nodelet via 'rosrun' configuration.")
            # ^ because in this case we do not have the args
        name = node.name if not node.rosname else node.rosname.own
        config.add_command("rosrun", [node.package.name, node.name, name])
        scope = LaunchScope(None, config, None)
        scope = scope.make_node(node, name, "/", (), True)
        self._future.append(FutureNodeLinks(scope.node))
github git-afsantos / haros / haros / config_builder.py View on Github external
value = sub.resolve(tag.value, strict=True)
        elif not tag.textfile is None:
            try:
                with open(tag.textfile) as f:
                    value = f.read()
            except IOError as e:
                raise ConfigurationError("cannot read file: " + tag.textfile)
        elif not tag.binfile is None:
            value = None
        elif not tag.command is None:
            value = None
        try:
            scope.make_params(name, ptype, value, condition,
                              line=tag.line, col=tag.column)
        except ValueError as e:
            raise ConfigurationError(str(e))
github git-afsantos / haros / haros / config_builder.py View on Github external
def _rosparam_tag(self, tag, condition, scope, sub):
        assert not tag.children
        command = sub.resolve(tag.command, strict = True)
        ns = sub.resolve(tag.namespace, strict = True)
        filepath = sub.resolve(tag.file, strict = True)
        name = sub.resolve(tag.name, strict = True)
        if command == "load":
            if filepath:
                try:
                    with open(filepath) as f:
                        value = f.read()
                except IOError as e:
                    raise ConfigurationError("cannot read file: " + filepath)
            else:
                value = tag.text
                if sub.resolve(tag.substitute, strict = True):
                    value = sub.sub(value)
                    value = sub.resolve(value, strict = True)
            scope.make_rosparam(name, ns, value, condition,
                                line=tag.line, col=tag.column)
        elif command == "delete":
            scope.remove_param(name, ns, condition)
github git-afsantos / haros / haros / config_builder.py View on Github external
def _find_package(self, name):
        # FIXME this is a hammer
        for pkg in self._pkg_finder.packages:
            if pkg.name == name:
                return pkg
        pkg = self._pkg_finder.find_package(name)
        if pkg is None:
            raise ConfigurationError("cannot find package: " + name)
        return pkg
github git-afsantos / haros / haros / config_builder.py View on Github external
def add_launch(self, launch_file):
        if self._invalid:
            raise ConfigurationError("invalid state")
        assert launch_file.language == "launch"
        config = self.configuration
        config.roslaunch.append(launch_file)
        config.add_command("roslaunch", [launch_file])
        if not launch_file.tree:
            self.errors.append("missing parse tree: " + launch_file.id)
            return False
        sub = SubstitutionParser(env=config.environment,
            pkgs=self.sources.packages, dirname=launch_file.dir_path,
            pkg_depends=config.dependencies.packages,
            env_depends=config.dependencies.environment)
        scope = LaunchScope(None, self.configuration, launch_file,
                            args = sub.arguments)
        self._analyse_tree(launch_file.tree, scope, sub)
    # ----- parameters can only be added in the end, because of rosparam
        for param in scope.parameters:
github git-afsantos / haros / haros / config_builder.py View on Github external
def _lookup_launch(self, filepath):
        self.log.debug("dynamic lookup of launch file: " + filepath)
        for pkg in chain(self._pkg_finder.packages, self._pkg_finder._extra):
            if not pkg.path:
                continue
            if (filepath.startswith(pkg.path)
                    and filepath[len(pkg.path)] == os.path.sep):
                self.log.debug("found package '%s' for launch file", pkg.name)
                break
        else:
            # FIXME we could just open the file at the given path, but then
            # we would not have the Package, File, Location objects.
            # The metamodel needs to be changed.
            self.log.debug("failed to find package for launch file")
            raise ConfigurationError("cannot find launch file: " + filepath)
        for sf in pkg.source_files:
            if sf.path == filepath:
                self.log.debug("found SourceFile '%s' for launch file", sf.name)
                break
        else:
            self.log.debug("failed to find SourceFile object for launch file")
            raise ConfigurationError("cannot find launch file: " + filepath)
        return sf
github git-afsantos / haros / haros / config_builder.py View on Github external
def make_rosparam(self, name, ns, value, condition, line=None, col=None):
    # ---- lazy rosparam import as per the oringinal roslaunch code
        global rosparam
        if rosparam is None:
            import rosparam
        try:
            value = yaml.safe_load(value)
        except yaml.MarkedYAMLError as e:
            raise ConfigurationError(str(e))
    # ----- try to use given name, namespace or both
        ns = self._ns_join(ns or self.private_ns, self.private_ns)
        if name:
            name = self._ns_join(name, ns)
        else:
            if not isinstance(value, dict):
                raise ConfigurationError("'param' attribute must be set"
                                         " for non-dictionary values")
    # ----- this will unfold, so we can use namespace in place of a name
            name = ns
        conditions = list(self.conditions)
        if not condition is True:
            conditions.append(condition)
        self._yaml_param(name, value, conditions, private=False,
                         line=line, col=col)