How to use the haros.launch_parser.SubstitutionError 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 / launch_parser.py View on Github external
def _optenv(self, parts):
        if len(parts) != 2:
            raise SubstitutionError("optenv expects at least one argument")
        args = parts[1].split(None, 1)
        self.env_depends.add(args[0])
        default = args[1] if len(args) == 2 else ""
        return self.environment.get(parts[1], default)
github git-afsantos / haros / haros / config_builder.py View on Github external
def _analyse_tree(self, tree, scope, sub):
        for tag in tree.children:
            if tag.tag == "error":
                self.errors.append(tag.text)
                continue
            try:
                condition = self._condition(tag.condition, sub,
                                            tag.line, tag.column)
                if condition is False:
                    continue
                handler = getattr(self, "_" + tag.tag + "_tag")
                handler(tag, condition, scope, sub)
            except (ConfigurationError, SubstitutionError) as e:
                self.errors.append(e.value)
github git-afsantos / haros / haros / launch_parser.py View on Github external
def to_int(self, value):
        try:
            return int(value)
        except ValueError as e:
            raise SubstitutionError("invalid int value: " + value)
github git-afsantos / haros / haros / launch_parser.py View on Github external
def _arg(self, parts):
        if len(parts) != 2:
            raise SubstitutionError("arg takes exactly one argument")
        name = parts[1]
        if name in self.arguments:
            value = self.arguments[name]
            if value is None or isinstance(value, UnresolvedValue):
                return ("arg", name)
            return value
        raise SubstitutionError("undeclared arg: " + name)
github git-afsantos / haros / haros / launch_parser.py View on Github external
def _arg(self, parts):
        if len(parts) != 2:
            raise SubstitutionError("arg takes exactly one argument")
        name = parts[1]
        if name in self.arguments:
            value = self.arguments[name]
            if value is None or isinstance(value, UnresolvedValue):
                return ("arg", name)
            return value
        raise SubstitutionError("undeclared arg: " + name)
github git-afsantos / haros / haros / launch_parser.py View on Github external
def _env(self, parts):
        if len(parts) != 2:
            raise SubstitutionError("env takes exactly one argument")
        self.env_depends.add(parts[1])
        return self.environment.get(parts[1], tuple(parts))
github git-afsantos / haros / haros / launch_parser.py View on Github external
def __getitem__(self, key):
        try:
            return self._functions[key]
        except KeyError:
            if key in self._args:
                value = self._args[key]
                if value is None or isinstance(value, UnresolvedValue):
                    return ("arg", key)
                return _convert_value(value)
            raise SubstitutionError("undeclared arg: " + key)
github git-afsantos / haros / haros / launch_parser.py View on Github external
def _find(self, parts):
        if len(parts) != 2:
            raise SubstitutionError("find takes exactly one argument")
        name = parts[1]
        self.pkg_depends.add(name)
        try:
            package = self.packages.get("package:" + name)
        except KeyError:
            package = None

        if package:
            if package.path:
                return package.path
            return ("find", name)
        raise SubstitutionError("unknown package: " + name)
github git-afsantos / haros / haros / launch_parser.py View on Github external
value = parser.sub("$$(arg test)$")
    assert value == "$value$"
    parser.environment["TEST"] = "value"
    value = parser.sub("$(env TEST)")
    assert value == "value"
    value = parser.sub("$(optenv TEST)")
    assert value == "value"
    try:
        parser.sub("$(arg $(arg name))")
        assert False
    except SubstitutionError as e:
        pass
    try:
        parser.sub("$($)")
        assert False
    except SubstitutionError as e:
        pass
    try:
        parser.sub("va$(eval 'lue')")
        assert False
    except SubstitutionError as e:
        pass
    try:
        parser.sub("value$(arg name)$(env VAR)")
        assert False
    except SubstitutionError as e:
        pass