Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "--param-type" option to ros2param list. #572

Merged
merged 3 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ros2param/ros2param/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ def call_list_parameters(*, node, node_name, prefix=None):
return response.result.names


def get_parameter_type_string(parameter_type):
mapping = {
ParameterType.PARAMETER_BOOL: 'boolean',
ParameterType.PARAMETER_INTEGER: 'integer',
ParameterType.PARAMETER_DOUBLE: 'double',
ParameterType.PARAMETER_STRING: 'string',
ParameterType.PARAMETER_BYTE_ARRAY: 'byte array',
ParameterType.PARAMETER_BOOL_ARRAY: 'boolean array',
ParameterType.PARAMETER_INTEGER_ARRAY: 'integer array',
ParameterType.PARAMETER_DOUBLE_ARRAY: 'double array',
ParameterType.PARAMETER_STRING_ARRAY: 'string array',
ParameterType.PARAMETER_NOT_SET: 'not set',
}
return mapping[parameter_type]


class ParameterNameCompleter:
"""Callable returning a list of parameter names."""

Expand Down
18 changes: 1 addition & 17 deletions ros2param/ros2param/verb/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from rcl_interfaces.msg import ParameterType
from ros2cli.node.direct import DirectNode
from ros2cli.node.strategy import add_arguments
from ros2cli.node.strategy import NodeStrategy
from ros2node.api import get_absolute_node_name
from ros2node.api import get_node_names
from ros2node.api import NodeNameCompleter
from ros2param.api import call_describe_parameters
from ros2param.api import get_parameter_type_string
from ros2param.api import ParameterNameCompleter
from ros2param.verb import VerbExtension

Expand Down Expand Up @@ -77,19 +77,3 @@ def _print_descriptor(self, descriptor):
if descriptor.additional_constraints:
print(' Additional constraints:',
descriptor.additional_constraints)


def get_parameter_type_string(parameter_type):
mapping = {
ParameterType.PARAMETER_BOOL: 'boolean',
ParameterType.PARAMETER_INTEGER: 'integer',
ParameterType.PARAMETER_DOUBLE: 'double',
ParameterType.PARAMETER_STRING: 'string',
ParameterType.PARAMETER_BYTE_ARRAY: 'byte array',
ParameterType.PARAMETER_BOOL_ARRAY: 'boolean array',
ParameterType.PARAMETER_INTEGER_ARRAY: 'integer array',
ParameterType.PARAMETER_DOUBLE_ARRAY: 'double array',
ParameterType.PARAMETER_STRING_ARRAY: 'string array',
ParameterType.PARAMETER_NOT_SET: 'not set',
}
return mapping[parameter_type]
24 changes: 22 additions & 2 deletions ros2param/ros2param/verb/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from ros2node.api import get_absolute_node_name
from ros2node.api import get_node_names
from ros2node.api import NodeNameCompleter
from ros2param.api import call_describe_parameters
from ros2param.api import get_parameter_type_string
from ros2param.verb import VerbExtension
from ros2service.api import get_service_names

Expand All @@ -41,6 +43,9 @@ def add_arguments(self, parser, cli_name): # noqa: D102
parser.add_argument(
'--param-prefixes', nargs='+', default=[],
help='Only list parameters with the provided prefixes')
parser.add_argument(
'--param-type', action='store_true',
help='Print parameter types with parameter names')

def main(self, *, args): # noqa: D102
with NodeStrategy(args) as node:
Expand Down Expand Up @@ -96,8 +101,23 @@ def main(self, *, args): # noqa: D102
if not args.node_name:
print(f'{node_name.full_name}:')
response = future.result()
for name in sorted(response.result.names):
print(f' {name}')
sorted_names = sorted(response.result.names)
# get descriptors for the node if needs to print parameter type
name_to_type_map = {}
if args.param_type is True:
resp = call_describe_parameters(
node=node, node_name=node_name.full_name,
parameter_names=sorted_names)
for descriptor in resp.descriptors:
name_to_type_map[descriptor.name] = get_parameter_type_string(
descriptor.type)

for name in sorted_names:
if args.param_type is True:
param_type_str = name_to_type_map[name]
print(f' {name} (type: {param_type_str})')
else:
print(f' {name}')
else:
e = future.exception()
print(
Expand Down