Skip to content

Commit

Permalink
cosmetic fixes for ros2param dump command. (#933)
Browse files Browse the repository at this point in the history
* cosmetic fixes for ros2param dump command.

Signed-off-by: Tomoya Fujita <[email protected]>

* pass through no parameters available case.

Signed-off-by: Tomoya Fujita <[email protected]>

* bug fix from review comment.

Signed-off-by: Tomoya Fujita <[email protected]>

* remove unnecessary initial assignment.

Signed-off-by: Tomoya Fujita <[email protected]>

---------

Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya authored Oct 3, 2024
1 parent 379f3f4 commit 8e46bf2
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions ros2param/ros2param/verb/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,6 @@ def add_arguments(self, parser, cli_name): # noqa: D102
'--timeout', metavar='N', type=int, default=1,
help='Wait for N seconds until node becomes available (default %(default)s sec)')

@staticmethod
def get_parameter_values(node, node_name, params):
response = call_get_parameters(
node=node, node_name=node_name,
parameter_names=params)

# requested parameter not set
if not response.values:
return None

# extract type specific value
return [get_value(parameter_value=i) for i in response.values]

def insert_dict(self, dictionary, key, value):
split = key.split(PARAMETER_SEPARATOR_STRING, 1)
if len(split) > 1:
Expand All @@ -80,7 +67,7 @@ def main(self, *, args): # noqa: D102
with DirectNode(args) as node:
yaml_output = {node_name.full_name: {'ros__parameters': {}}}

# retrieve values
# retrieve parameter names
response = call_list_parameters(node=node, node_name=absolute_node_name)
if response is None:
print(
Expand All @@ -93,17 +80,26 @@ def main(self, *, args): # noqa: D102
'Exception while calling list_parameters service of node '
f"'{node_name.full_name}': {e}", file=sys.stderr)
return

response = response.result().result.names
response = sorted(response)
parameter_values = self.get_parameter_values(node, absolute_node_name, response)
if parameter_values is None:
parameter_names = sorted(response.result().result.names)

# retrieve parameter values
response = None
try:
response = call_get_parameters(
node=node, node_name=absolute_node_name, parameter_names=parameter_names)
except RuntimeError as e:
print(
'Exception while calling get_parameters service of node '
f"'{node_name.full_name}': {e}", file=sys.stderr)
return

for param_name, pval in zip(response, parameter_values):
if response.values is None:
# pass through here, no parameters are available with this node.
# since this is not failure, it proceeds to print the yaml as consistent behavior.
pass
parameter_values = [get_value(parameter_value=i) for i in response.values]

# create dictionary with parameter names and values
for param_name, pval in zip(parameter_names, parameter_values):
self.insert_dict(
yaml_output[node_name.full_name]['ros__parameters'], param_name, pval)

Expand Down

0 comments on commit 8e46bf2

Please sign in to comment.