Skip to content

Commit

Permalink
[WIP] Udpate runtime introspector to get name of the package and the …
Browse files Browse the repository at this point in the history
…name from the linux processes manager
  • Loading branch information
ipa-nhg committed Feb 9, 2024
1 parent 33b2f75 commit 3d08b52
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ros2model/verb/runtime_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import ros2model.api.runtime_parser.rosmodel_runtime_parser as RuntimeParser
import ros2model.core.metamodels.metamodel_ros as ROSModel

import psutil
import sys

class RuntimeNodeVerb(VerbExtension):
"""Create .ros2 for each node in a runtime system"""
Expand Down Expand Up @@ -43,6 +45,17 @@ def name_component_file(self, grapg_name: ROSModel.GraphName):
else:
file_name = f"{grapg_name.namespace[1:]}__{n}"
return file_name

def find_process_by_node_name(self, node_name, namespace):
for process in psutil.process_iter(['pid', 'cmdline']):
try:
cmdline = process.info['cmdline']
if namespace in str(cmdline) and node_name in str(cmdline):
cmdline_list = cmdline[0].split('/')
return cmdline_list[-2], cmdline_list[-1]
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return 'TODO', 'TODO'

def main(self, *, args):
output_dir = Path(args.output_folder)
Expand All @@ -60,9 +73,10 @@ def main(self, *, args):
args.include_hidden_nodes,
args.include_hidden_interfaces,
)
package_name, artifact_name = self.find_process_by_node_name(n.name, n.namespace)
runtime_pkg = ROSModel.Package(
name="TODO",
artifact=[ROSModel.Artifact(name="TODO", node=[node_instance])],
name=package_name,
artifact=[ROSModel.Artifact(name=artifact_name, node=[node_instance])],
)
node_generator.generate_a_file(
model=runtime_pkg,
Expand Down

0 comments on commit 3d08b52

Please sign in to comment.