Beispiel #1
0
def test_is_legal_resource_base_name():
    from genmsg import is_legal_resource_base_name
    failures = [
        None, '', 'hello\n', '\t', 'foo++', 'foo-bar', '#foo', 'f/', 'foo/bar',
        '/', '/a', 'f//b', '~f', '~a/b/c', '~/f', ' name', 'name ', '1name',
        'foo\\'
    ]
    for f in failures:
        assert not is_legal_resource_base_name(f), f
    tests = ['f', 'f1', 'f_', 'foo', 'foo_bar']
    for t in tests:
        assert is_legal_resource_base_name(t), "[%s]" % t
def test_is_legal_resource_base_name():
    from genmsg import is_legal_resource_base_name
    failures = [None, '', 'hello\n', '\t', 'foo++', 'foo-bar', '#foo',
                'f/', 'foo/bar', '/', '/a',
                'f//b',
                '~f', '~a/b/c',
                '~/f',
                ' name', 'name ',
                '1name', 'foo\\']
    for f in failures:
        assert not is_legal_resource_base_name(f), f
    tests = ['f', 'f1', 'f_', 'foo', 'foo_bar']
    for t in tests:
        assert is_legal_resource_base_name(t), "[%s]"%t
Beispiel #3
0
    def generate_messages(self, package, package_files, outdir, search_path):
        """
        :returns: return code, ``int``
        """
        if not genmsg.is_legal_resource_base_name(package):
            raise MsgGenerationException(
                "\nERROR: package name '%s' is illegal and cannot be used in message generation.\nPlease see http://ros.org/wiki/Names"
                % (package)
            )

        # package/src/package/msg for messages, packages/src/package/srv for services
        msg_context = MsgContext.create_default()
        retcode = 0
        for f in package_files:
            try:
                f = os.path.abspath(f)
                infile_name = os.path.basename(f)
                full_type = genmsg.gentools.compute_full_type_name(package, infile_name)
                outfile = self.generate(msg_context, full_type, f, outdir, search_path)  # actual generation
            except Exception as e:
                if not isinstance(e, MsgGenerationException) and not isinstance(e, genmsg.msgs.InvalidMsgSpec):
                    traceback.print_exc()
                print(
                    "\nERROR: Unable to generate %s for package '%s': while processing '%s': %s\n"
                    % (self.what, package, f, e),
                    file=sys.stderr,
                )
                retcode = 1  # flag error
        return retcode
Beispiel #4
0
    def generate_messages(self, package, package_files, outdir, search_path):
        """
        :returns: return code, ``int``
        """
        if not genmsg.is_legal_resource_base_name(package):
            raise MsgGenerationException(
                "\nERROR: package name '%s' is illegal and cannot be used in message generation.\nPlease see http://ros.org/wiki/Names"
                % (package))

        # package/src/package/msg for messages, packages/src/package/srv for services
        msg_context = MsgContext.create_default()
        retcode = 0
        for f in package_files:
            try:
                f = os.path.abspath(f)
                infile_name = os.path.basename(f)
                full_type = genmsg.gentools.compute_full_type_name(
                    package, infile_name)
                outfile = self.generate(msg_context, full_type, f, outdir,
                                        search_path)  #actual generation
            except Exception as e:
                if not isinstance(e,
                                  MsgGenerationException) and not isinstance(
                                      e, genmsg.msgs.InvalidMsgSpec):
                    traceback.print_exc()
                print(
                    "\nERROR: Unable to generate %s for package '%s': while processing '%s': %s\n"
                    % (self.what, package, f, e),
                    file=sys.stderr)
                retcode = 1  #flag error
        return retcode
Beispiel #5
0
    def generate_firos_messages(self, package, data, outdir, OUTPUT, search_path):
        """
        :returns: return code, ``int``
        """
        if not genmsg.is_legal_resource_base_name(package):
            raise MsgGenerationException("\nERROR: package name '%s' is illegal and cannot be used in message generation.\nPlease see http://ros.org/wiki/Names"%(package))

        # package/src/package/msg for messages, packages/src/package/srv for services
        msg_context = MsgContext.create_default()
        retcode = 0
        try:
            # you can't just check first... race condition
            outdir = outdir + OUTPUT
            os.makedirs(outdir)
            f = open(os.path.join(outdir, "__init__.py"), 'w')
            f.close()
        except OSError as e:
            if e.errno != 17: # file exists
                raise

        for robotName in data:
            try:
                robot = data[robotName]
                for topic_name in robot['topics']:
                    topic = robot['topics'][topic_name]
                    full_type = str(robotName) + '/' + str(topic_name)
                    if type(topic['msg']) is dict:
                        self.firos_generate(msg_context, full_type, topic, outdir, search_path) #actual generation
            except Exception as e:
                if not isinstance(e, MsgGenerationException) and not isinstance(e, genmsg.msgs.InvalidMsgSpec):
                    traceback.print_exc()
                print("\nERROR: Unable to generate %s for package '%s': %s\n"%(self.what, package, e), file=sys.stderr)
                retcode = 1 #flag error
        return retcode