From 195b63a3efbbd0b5f96a9192bd91070a9c9cb6e3 Mon Sep 17 00:00:00 2001 From: Christophe Date: Tue, 20 Nov 2018 18:45:09 -0500 Subject: [PATCH] roslaunch: add an option in XmlLoader to only load arg tags (#1521) This fixes #1300. It's off/false by default, but it's used by `arg_dump` to stop roslaunch-autocomplete from failing if any arg has no default value. --- tools/roslaunch/src/roslaunch/arg_dump.py | 2 +- tools/roslaunch/src/roslaunch/xmlloader.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/roslaunch/src/roslaunch/arg_dump.py b/tools/roslaunch/src/roslaunch/arg_dump.py index df5a462d64..c886eef577 100644 --- a/tools/roslaunch/src/roslaunch/arg_dump.py +++ b/tools/roslaunch/src/roslaunch/arg_dump.py @@ -45,7 +45,7 @@ from roslaunch.config import load_config_default def get_args(roslaunch_files): - loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False) + loader = roslaunch.xmlloader.XmlLoader(resolve_anon=False, args_only=True) config = load_config_default(roslaunch_files, None, loader=loader, verbose=False, assign_machines=False) return loader.root_context.resolve_dict.get('arg_doc', {}) diff --git a/tools/roslaunch/src/roslaunch/xmlloader.py b/tools/roslaunch/src/roslaunch/xmlloader.py index 226d2bdf08..3e9d0f6825 100644 --- a/tools/roslaunch/src/roslaunch/xmlloader.py +++ b/tools/roslaunch/src/roslaunch/xmlloader.py @@ -166,15 +166,18 @@ class XmlLoader(loader.Loader): Parser for roslaunch XML format. Loads parsed representation into ROSConfig model. """ - def __init__(self, resolve_anon=True): + def __init__(self, resolve_anon=True, args_only=False): """ @param resolve_anon: If True (default), will resolve $(anon foo). If false, will leave these args as-is. @type resolve_anon: bool + @param args_only: if True, will only load arg tags (e.g. autocompletion purposes) + @type args_only: bool """ # store the root XmlContext so that outside code can access it self.root_context = None self.resolve_anon = resolve_anon + self.args_only = args_only def resolve_args(self, args, context): """ @@ -673,7 +676,12 @@ def _recurse_load(self, ros_config, tags, context, default_machine, is_core, ver """ for tag in [t for t in tags if t.nodeType == DomNode.ELEMENT_NODE]: name = tag.tagName - if name == 'group': + if name == 'arg': + self._arg_tag(tag, context, ros_config, verbose=verbose) + elif self.args_only: + # do not load other tags + pass + elif name == 'group': if ifunless_test(self, tag, context): self._check_attrs(tag, context, ros_config, XmlLoader.GROUP_ATTRS) child_ns = self._ns_clear_params_attr(name, tag, context, ros_config) @@ -715,8 +723,6 @@ def _recurse_load(self, ros_config, tags, context, default_machine, is_core, ver default_machine = val elif name == 'env': self._env_tag(tag, context, ros_config) - elif name == 'arg': - self._arg_tag(tag, context, ros_config, verbose=verbose) else: ros_config.add_config_error("unrecognized tag "+tag.tagName) return default_machine