Skip to content

Commit

Permalink
Slightly different approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepurvis committed Feb 24, 2017
1 parent 55fc937 commit df0dfb8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
13 changes: 10 additions & 3 deletions tools/roslaunch/resources/example.launch
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@
<!-- more compact import syntax -->
<include ns="included2" file="$(find roslaunch)/resources/example-include.launch" />

<!-- Pass over an include with an if-attribute that evaluates to false. -->
<arg name="dont_include_me" value="false" />
<include if="$(arg dont_include_me)" file="does/not/exist.launch" />
<!-- Pass over an include and node with if-attributes that evaluate to false. -->
<arg name="false_arg" value="false" />
<include if="$(arg false_arg)" file="does/not/exist.launch" />
<node if="$(arg false_arg)" pkg="doesnt_exit" type="nope" name="nope" />

<arg name="true_arg" value="true" />
<group unless="$(arg true_arg)">
<include file="does/not/exist.launch" />
<node pkg="doesnt_exit" type="nope" name="nope" />
</group>
</launch>
36 changes: 14 additions & 22 deletions tools/roslaunch/src/roslaunch/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,16 @@ def _get_arg_value(tag, context):
else:
raise RoslaunchDepsException("No value for arg [%s]"%(name))

def _parse_arg(tag, context):
name = tag.attributes['name'].value
def _check_ifunless(tag, context):
if tag.attributes.has_key('if'):
val = resolve_args(tag.attributes['if'].value, context)
if convert_value(val, 'bool'):
return (name, _get_arg_value(tag, context))
elif tag.attributes.has_key('unless'):
val = resolve_args(tag.attributes['unless'].value, context)
if not convert_value(val, 'bool'):
return (name, _get_arg_value(tag, context))
else:
return (name, _get_arg_value(tag, context))
# nothing to return (no value, or conditional wasn't satisfied)
return None
return False
if tag.attributes.has_key('unless'):
val = resolve_args(tag.attributes['unless'].value, context)
if convert_value(val, 'bool'):
return False
return True

def _parse_subcontext(tags, context):
subcontext = {'arg': {}}
Expand All @@ -117,12 +113,8 @@ def _parse_subcontext(tags, context):
return subcontext

for tag in [t for t in tags if t.nodeType == DomNode.ELEMENT_NODE]:
if tag.tagName == 'arg':
# None is returned for args with if/unless that evaluate to false
ret = _parse_arg(tag, context)
if ret is not None:
(name, val) = ret
subcontext['arg'][name] = val
if tag.tagName == 'arg' and _check_ifunless(tag, context):
subcontext['arg'][tag.attributes['name'].value] = _get_arg_value(tag, context)
return subcontext

def _parse_launch(tags, launch_file, file_deps, verbose, context):
Expand All @@ -131,17 +123,17 @@ def _parse_launch(tags, launch_file, file_deps, verbose, context):

# process group, include, node, and test tags from launch file
for tag in [t for t in tags if t.nodeType == DomNode.ELEMENT_NODE]:
if not _check_ifunless(tag, context):
continue

if tag.tagName == 'group':

#descend group tags as they can contain node tags
_parse_launch(tag.childNodes, launch_file, file_deps, verbose, context)

elif tag.tagName == 'arg':
v = _parse_arg(tag, context)
if v:
(name, val) = v
context['arg'][name] = val
context['arg'][tag.attributes['name'].value] = _get_arg_value(tag, context)

elif tag.tagName == 'include':
if tag.attributes.has_key('if'):
val = resolve_args(tag.attributes['if'].value, context)
Expand Down Expand Up @@ -174,7 +166,7 @@ def _parse_launch(tags, launch_file, file_deps, verbose, context):

if sub_launch_file not in file_deps[launch_file].includes:
file_deps[launch_file].includes.append(sub_launch_file)
if launch_file_pkg != sub_pkg:
if launch_file_pkg != sub_pkg:
file_deps[launch_file].pkgs.append(sub_pkg)

# recurse
Expand Down

0 comments on commit df0dfb8

Please sign in to comment.