Esempio n. 1
0
def _parse_launch(tags, launch_file, file_deps, verbose):
    _, launch_file_pkg = roslib.packages.get_dir_pkg(
        os.path.dirname(os.path.abspath(launch_file)))

    # 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 tag.tagName == 'group':

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

        elif tag.tagName == 'include':
            try:
                sub_launch_file = resolve_args(tag.attributes['file'].value)
            except KeyError, e:
                raise RoslaunchDepsException(
                    "Cannot load roslaunch <%s> tag: missing required attribute %s.\nXML is %s"
                    % (tag.tagName, str(e), tag.toxml()))

            if verbose:
                print "processing included launch %s" % sub_launch_file

            # determine package dependency for included file
            _, sub_pkg = roslib.packages.get_dir_pkg(
                os.path.dirname(os.path.abspath(sub_launch_file)))
            if sub_pkg is None:
                print >> sys.stderr, "ERROR: cannot determine package for [%s]" % sub_launch_file

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

            # recurse
            file_deps[sub_launch_file] = RoslaunchDeps()
            try:
                dom = parse(sub_launch_file).getElementsByTagName('launch')
                if not len(dom):
                    print >> sys.stderr, "ERROR: %s is not a valid roslaunch file" % sub_launch_file
                else:
                    launch_tag = dom[0]
                    _parse_launch(launch_tag.childNodes, sub_launch_file,
                                  file_deps, verbose)
            except IOError, e:
                raise RoslaunchDepsException(
                    "Cannot load roslaunch include '%s' in '%s'" %
                    (sub_launch_file, launch_file))
Esempio n. 2
0
def _parse_launch(tags, launch_file, file_deps, verbose):
    _, launch_file_pkg = roslib.packages.get_dir_pkg(os.path.dirname(os.path.abspath(launch_file)))

    # 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 tag.tagName == "group":

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

        elif tag.tagName == "include":
            try:
                sub_launch_file = resolve_args(tag.attributes["file"].value)
            except KeyError, e:
                raise RoslaunchDepsException(
                    "Cannot load roslaunch <%s> tag: missing required attribute %s.\nXML is %s"
                    % (tag.tagName, str(e), tag.toxml())
                )

            if verbose:
                print "processing included launch %s" % sub_launch_file

            # determine package dependency for included file
            _, sub_pkg = roslib.packages.get_dir_pkg(os.path.dirname(os.path.abspath(sub_launch_file)))
            if sub_pkg is None:
                print >> sys.stderr, "ERROR: cannot determine package for [%s]" % sub_launch_file

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

            # recurse
            file_deps[sub_launch_file] = RoslaunchDeps()
            try:
                dom = parse(sub_launch_file).getElementsByTagName("launch")
                if not len(dom):
                    print >> sys.stderr, "ERROR: %s is not a valid roslaunch file" % sub_launch_file
                else:
                    launch_tag = dom[0]
                    _parse_launch(launch_tag.childNodes, sub_launch_file, file_deps, verbose)
            except IOError, e:
                raise RoslaunchDepsException(
                    "Cannot load roslaunch include '%s' in '%s'" % (sub_launch_file, launch_file)
                )
    def test_resolve_args(self):
        from roslib.substitution_args import resolve_args, SubstitutionException
        from roslib.packages import get_pkg_dir
        roslib_dir = get_pkg_dir('roslib', required=True)

        anon_context = {'foo': 'bar'}
        arg_context = {'fuga': 'hoge', 'car': 'cdr'}
        context = {'anon': anon_context, 'arg': arg_context }
        
        tests = [
            ('$(find roslib)', roslib_dir),
            ('hello$(find roslib)', 'hello'+roslib_dir),
            ('$(find roslib )', roslib_dir),
            ('$$(find roslib )', '$'+roslib_dir),
            ('$( find roslib )', roslib_dir),
            ('$(find  roslib )', roslib_dir),
            ('$(find roslib)$(find roslib)', roslib_dir+roslib_dir),
            ('$(find roslib)/foo/bar.xml', roslib_dir+os.sep+'foo'+os.sep+'bar.xml'),
            (r'$(find roslib)\foo\bar.xml $(find roslib)\bar.xml', roslib_dir+os.sep+'foo'+os.sep+'bar.xml '+roslib_dir+os.sep+'bar.xml'),
            ('$(find roslib)\\foo\\bar.xml more/stuff\\here', roslib_dir+os.sep+'foo'+os.sep+'bar.xml more/stuff\\here'),
            ('$(env ROS_ROOT)', os.environ['ROS_ROOT']),
            ('$(env ROS_ROOT)', os.environ['ROS_ROOT']),
            ('$(env ROS_ROOT )', os.environ['ROS_ROOT']),
            ('$(optenv ROS_ROOT)', os.environ['ROS_ROOT']),
            ('$(optenv ROS_ROOT)$(optenv ROS_ROOT)', os.environ['ROS_ROOT']+os.environ['ROS_ROOT']),
            ('$(optenv ROS_ROOT alternate text)', os.environ['ROS_ROOT']),
            ('$(optenv NOT_ROS_ROOT)', ''),
            ('$(optenv NOT_ROS_ROOT)more stuff', 'more stuff'),
            ('$(optenv NOT_ROS_ROOT alternate)', 'alternate'),
            ('$(optenv NOT_ROS_ROOT alternate text)', 'alternate text'),

            # #1776
            ('$(anon foo)', 'bar'),
            ('$(anon foo)/baz', 'bar/baz'),
            ('$(anon foo)/baz/$(anon foo)', 'bar/baz/bar'),

            # arg
            ('$(arg fuga)', 'hoge'),
            ('$(arg fuga)$(arg fuga)', 'hogehoge'),
            ('$(arg car)$(arg fuga)', 'cdrhoge'),
            ('$(arg fuga)hoge', 'hogehoge'),
            ]
        for arg, val in tests:
            self.assertEquals(val, resolve_args(arg, context=context))

        # more #1776
        r = resolve_args('$(anon foo)/bar')
        self.assert_('/bar' in r)
        self.failIf('$(anon foo)' in r)        
        
            
        # test against strings that should not match
        noop_tests = [
            '$(find roslib', '$find roslib', '', ' ', 'noop', 'find roslib', 'env ROS_ROOT', '$$', ')', '(', '()',
            None, 
            ]
        for t in noop_tests:
            self.assertEquals(t, resolve_args(t))
        failures = [
            '$((find roslib))',  '$(find $roslib)',
            '$(find)', '$(find roslib roslib)', '$(export roslib)',
            '$(env)', '$(env ROS_ROOT alternate)',
            '$(env NOT_SET)',
            '$(optenv)',
            '$(anon)',
            '$(anon foo bar)',            
            ]
        for f in failures:
            try:
                resolve_args(f)
                self.fail("resolve_args(%s) should have failed"%f)
            except SubstitutionException: pass
    def test_resolve_args(self):
        from roslib.substitution_args import resolve_args, SubstitutionException
        from roslib.packages import get_pkg_dir
        rospy_dir = get_pkg_dir('rospy', required=True)

        anon_context = {'foo': 'bar'}
        arg_context = {'fuga': 'hoge', 'car': 'cdr'}
        context = {'anon': anon_context, 'arg': arg_context }
        
        tests = [
            ('$(find rospy)', rospy_dir),
            ('hello$(find rospy)', 'hello'+rospy_dir),
            ('$(find rospy )', rospy_dir),
            ('$$(find rospy )', '$'+rospy_dir),
            ('$( find rospy )', rospy_dir),
            ('$(find  rospy )', rospy_dir),
            ('$(find rospy)$(find rospy)', rospy_dir+rospy_dir),
            ('$(find rospy)/foo/bar.xml', rospy_dir+os.sep+'foo'+os.sep+'bar.xml'),
            (r'$(find rospy)\foo\bar.xml $(find rospy)\bar.xml', rospy_dir+os.sep+'foo'+os.sep+'bar.xml '+rospy_dir+os.sep+'bar.xml'),
            ('$(find rospy)\\foo\\bar.xml more/stuff\\here', rospy_dir+os.sep+'foo'+os.sep+'bar.xml more/stuff\\here'),
            ('$(env ROS_ROOT)', os.environ['ROS_ROOT']),
            ('$(env ROS_ROOT)', os.environ['ROS_ROOT']),
            ('$(env ROS_ROOT )', os.environ['ROS_ROOT']),
            ('$(optenv ROS_ROOT)', os.environ['ROS_ROOT']),
            ('$(optenv ROS_ROOT)$(optenv ROS_ROOT)', os.environ['ROS_ROOT']+os.environ['ROS_ROOT']),
            ('$(optenv ROS_ROOT alternate text)', os.environ['ROS_ROOT']),
            ('$(optenv NOT_ROS_ROOT)', ''),
            ('$(optenv NOT_ROS_ROOT)more stuff', 'more stuff'),
            ('$(optenv NOT_ROS_ROOT alternate)', 'alternate'),
            ('$(optenv NOT_ROS_ROOT alternate text)', 'alternate text'),

            # #1776
            ('$(anon foo)', 'bar'),
            ('$(anon foo)/baz', 'bar/baz'),
            ('$(anon foo)/baz/$(anon foo)', 'bar/baz/bar'),

            # arg
            ('$(arg fuga)', 'hoge'),
            ('$(arg fuga)$(arg fuga)', 'hogehoge'),
            ('$(arg car)$(arg fuga)', 'cdrhoge'),
            ('$(arg fuga)hoge', 'hogehoge'),
            ]
        for arg, val in tests:
            self.assertEquals(val, resolve_args(arg, context=context))

        # more #1776
        r = resolve_args('$(anon foo)/bar')
        self.assert_('/bar' in r)
        self.failIf('$(anon foo)' in r)        
        
            
        # test against strings that should not match
        noop_tests = [
            '$(find rospy', '$find rospy', '', ' ', 'noop', 'find rospy', 'env ROS_ROOT', '$$', ')', '(', '()',
            None, 
            ]
        for t in noop_tests:
            self.assertEquals(t, resolve_args(t))
        failures = [
            '$((find rospy))',  '$(find $rospy)',
            '$(find)', '$(find rospy roslib)', '$(export rospy)',
            '$(env)', '$(env ROS_ROOT alternate)',
            '$(env NOT_SET)',
            '$(optenv)',
            '$(anon)',
            '$(anon foo bar)',            
            ]
        for f in failures:
            try:
                resolve_args(f)
                self.fail("resolve_args(%s) should have failed"%f)
            except SubstitutionException: pass
Esempio n. 5
0
                dom = parse(sub_launch_file).getElementsByTagName('launch')
                if not len(dom):
                    print >> sys.stderr, "ERROR: %s is not a valid roslaunch file" % sub_launch_file
                else:
                    launch_tag = dom[0]
                    _parse_launch(launch_tag.childNodes, sub_launch_file,
                                  file_deps, verbose)
            except IOError, e:
                raise RoslaunchDepsException(
                    "Cannot load roslaunch include '%s' in '%s'" %
                    (sub_launch_file, launch_file))

        elif tag.tagName in ['node', 'test']:
            try:
                pkg, type = [
                    resolve_args(tag.attributes[a].value)
                    for a in ['pkg', 'type']
                ]
            except KeyError, e:
                raise RoslaunchDepsException(
                    "Cannot load roslaunch <%s> tag: missing required attribute %s.\nXML is %s"
                    % (tag.tagName, str(e), tag.toxml()))
            file_deps[launch_file].nodes.append((pkg, type))
            # we actually want to include the package itself if that's referenced
            #if launch_file_pkg != pkg:
            file_deps[launch_file].pkgs.append(pkg)


def parse_launch(launch_file, file_deps, verbose):
    if verbose:
        print "processing launch %s" % launch_file
Esempio n. 6
0
            file_deps[sub_launch_file] = RoslaunchDeps()
            try:
                dom = parse(sub_launch_file).getElementsByTagName("launch")
                if not len(dom):
                    print >> sys.stderr, "ERROR: %s is not a valid roslaunch file" % sub_launch_file
                else:
                    launch_tag = dom[0]
                    _parse_launch(launch_tag.childNodes, sub_launch_file, file_deps, verbose)
            except IOError, e:
                raise RoslaunchDepsException(
                    "Cannot load roslaunch include '%s' in '%s'" % (sub_launch_file, launch_file)
                )

        elif tag.tagName in ["node", "test"]:
            try:
                pkg, type = [resolve_args(tag.attributes[a].value) for a in ["pkg", "type"]]
            except KeyError, e:
                raise RoslaunchDepsException(
                    "Cannot load roslaunch <%s> tag: missing required attribute %s.\nXML is %s"
                    % (tag.tagName, str(e), tag.toxml())
                )
            file_deps[launch_file].nodes.append((pkg, type))
            # we actually want to include the package itself if that's referenced
            # if launch_file_pkg != pkg:
            file_deps[launch_file].pkgs.append(pkg)


def parse_launch(launch_file, file_deps, verbose):
    if verbose:
        print "processing launch %s" % launch_file