How to use the haros.metamodel.Node 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 ipa320 / ros-model / tools / docker / ros_model_extractor.py View on Github external
ws = ros_pkg_path[:ros_pkg_path.find("/src:")]
        #FIND PACKAGE PATH
        pkg = Package(self.args.package_name)
        rospack = rospkg.RosPack()
        pkg.path = rospack.get_path(self.args.package_name)

        #BONSAI PARSER
        parser = CppAstParser(workspace = ws)
        parser.set_library_path("/usr/lib/llvm-3.8/lib")
        parser.set_standard_includes("/usr/lib/llvm-3.8/lib/clang/3.8.0/include")
        db_dir = os.path.join(ws, "build")
        if os.path.isfile(os.path.join(db_dir, "compile_commands.json")):
            parser.set_database(db_dir)
        #HAROS NODE EXTRACTOR
        analysis = NodeExtractor(pkg, env=dict(os.environ), ws=ws ,node_cache=False, parse_nodes=True)
        node = Node(self.args.name, pkg, rosname=RosName(self.args.name))
        srcdir = pkg.path[len(ws):]
        srcdir = os.path.join(ws, srcdir.split(os.sep, 1)[0])
        bindir = os.path.join(ws, "build")
        #HAROS CMAKE PARSER
        parser = RosCMakeParser(srcdir, bindir, pkgs = [pkg])
        parser.parse(os.path.join(pkg.path, "CMakeLists.txt"))
        for target in parser.executables.itervalues():
            if target.output_name == self.args.name:
                for file_in in target.files:
                    full_path = file_in
                    relative_path = full_path.replace(pkg.path+"/","").rpartition("/")[0]
                    file_name = full_path.rsplit('/', 1)[-1]
                    source_file = SourceFile(file_name, relative_path , pkg)
                    node.source_files.append(source_file)
        parser = CppAstParser(workspace = ws)
        node.source_tree = parser.global_scope
github git-afsantos / haros / haros / config_builder.py View on Github external
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 / extractor.py View on Github external
package.is_metapackage = not el.find("metapackage") is None
            if not el.find("nodelet") is None:
                nodelets = el.find("nodelet").get("plugin")
                nodelets = nodelets.replace("${prefix}", package.path)
                with open(nodelets, "r") as handle:
                    root = ET.parse(handle).getroot()
                PackageParser.log.info("Found nodelets at %s", nodelets)
                if root.tag == "library":
                    libs = (root,)
                else:
                    libs = root.findall("library")
                for el in libs:
                    libname = el.get("path").rsplit(os.sep)[-1]
                    for cl in el.findall("class"):
                        nodelet = cl.get("type").split("::")[-1]
                        node = Node(libname, package, nodelet = nodelet)
                        package.nodes.append(node)
github git-afsantos / haros / haros / extractor.py View on Github external
data = [datum for datum in self.node_cache.itervalues()]
        self.node_cache = {}
        for datum in data:
            try:
                pkg = self._get_package(datum["package"])
                source_files = self._get_files(pkg, datum["files"])
            except ValueError as e:
                # either a package or a file is no longer part of the analysis
                self.log.debug("Cached node %s: %s", datum["name"], e)
                continue
            mtime = datum["timestamp"]
            for sf in source_files:
                if sf.timestamp > mtime:
                    # a file was modified, needs to be parsed again
                    continue
            node = Node(datum["name"], pkg, rosname = datum["rosname"],
                        nodelet = datum["nodelet"])
            node.source_files = source_files
            for p in datum["advertise"]:
                node.advertise.append(self._pub_from_JSON(p))
            for p in datum["subscribe"]:
                node.subscribe.append(self._sub_from_JSON(p))
            for p in datum["service"]:
                node.service.append(self._srv_from_JSON(p))
            for p in datum["client"]:
                node.client.append(self._client_from_JSON(p))
            for p in datum["readParam"]:
                node.read_param.append(self._read_from_JSON(p))
            for p in datum["writeParam"]:
                node.write_param.append(self._write_from_JSON(p))
            self.node_cache[node.node_name] = node
github git-afsantos / haros / haros / extractor.py View on Github external
def _register_nodes(self, executables):
        for target in executables.itervalues():
            node = Node(target.output_name, self.package)
            for path in target.files:
                sf = self._get_file(path)
                if sf:
                    node.source_files.append(sf)
            for link in target.links:
                for path in link.files:
                    sf = self._get_file(path)
                    if sf:
                        node.source_files.append(sf)
            self.nodes.append(node)
            self.package.nodes.append(node)
github git-afsantos / haros / haros / extractor.py View on Github external
pattern = re.compile('^def\s+main\s*\(.*\)\s*:')
            for file in pkg.source_files:
                if file.language != 'python':
                    continue # continue with next file
                entry_point_found = False
                with open(file.path) as f:
                    for line in f:
                        match = pattern.match(line)
                        if match is not None:
                            entry_point_found = True
                            break
                if entry_point_found == False:
                    continue # continue with next file
                # else: this is a python file with a 'main' function,
                # so we consider it a node.
                node = Node(file.full_name, pkg)
                node.source_files.append(file)
                self.nodes.append(node)
                self.package.nodes.append(node)
        if self.parse_nodes:
            self._extract_primitives()