def test_create_package_template(self):
     template = PackageTemplate._create_package_template("foopackage")
     self.assertEqual("foopackage", template.name)
     self.assertEqual("0.0.0", template.version)
     self.assertEqual("The foopackage package", template.description)
     self.assertEqual([], template.catkin_deps)
     self.assertEqual([], template.authors)
     self.assertEqual(1, len(template.maintainers))
     self.assertIsNotNone(template.maintainers[0].email)
     self.assertEqual([], template.urls)
     # with args
     template = PackageTemplate._create_package_template(
         "foopackage",
         description="foo_desc",
         licenses=["a", "b"],
         maintainer_names=["John Doe", "Jim Daniels"],
         author_names=["Harry Smith"],
         version="1.2.3",
         catkin_deps=["foobar", "baz"],
     )
     self.assertEqual("foopackage", template.name)
     self.assertEqual("1.2.3", template.version)
     self.assertEqual("foo_desc", template.description)
     self.assertEqual(["baz", "foobar"], template.catkin_deps)
     self.assertEqual(1, len(template.authors))
     self.assertEqual("Jim Daniels", template.maintainers[0].name)
     self.assertEqual("John Doe", template.maintainers[1].name)
     self.assertEqual("Harry Smith", template.authors[0].name)
     self.assertEqual(2, len(template.maintainers))
     self.assertEqual([], template.urls)
 def test_create_package_template(self):
     template = PackageTemplate._create_package_template('fooPackage')
     self.assertEqual('fooPackage', template.name)
     self.assertEqual('0.0.0', template.version)
     self.assertEqual('The fooPackage package', template.description)
     self.assertEqual([], template.catkin_deps)
     self.assertEqual([], template.authors)
     self.assertEqual(1, len(template.maintainers))
     self.assertIsNotNone(template.maintainers[0].email)
     self.assertEqual([], template.urls)
     # with args
     template = PackageTemplate._create_package_template(
         'fooPackage',
         description='foo_desc',
         licenses=['a', 'b'],
         maintainer_names=['John Doe', 'Jim Daniels'],
         author_names=['Harry Smith'],
         version='1.2.3',
         catkin_deps=['foobar', 'baz'])
     self.assertEqual('fooPackage', template.name)
     self.assertEqual('1.2.3', template.version)
     self.assertEqual('foo_desc', template.description)
     self.assertEqual(['baz', 'foobar'], template.catkin_deps)
     self.assertEqual(1, len(template.authors))
     self.assertEqual('Jim Daniels', template.maintainers[0].name)
     self.assertEqual('John Doe', template.maintainers[1].name)
     self.assertEqual('Harry Smith', template.authors[0].name)
     self.assertEqual(2, len(template.maintainers))
     self.assertEqual([], template.urls)
 def test_create_package_template(self):
     template = PackageTemplate._create_package_template('foopackage')
     self.assertEqual('foopackage', template.name)
     self.assertEqual('0.0.0', template.version)
     self.assertEqual('The foopackage package', template.description)
     self.assertEqual([], template.catkin_deps)
     self.assertEqual([], template.authors)
     self.assertEqual(1, len(template.maintainers))
     self.assertIsNotNone(template.maintainers[0].email)
     self.assertEqual([], template.urls)
     # with args
     template = PackageTemplate._create_package_template(
         'foopackage',
         description='foo_desc',
         licenses=['a', 'b'],
         maintainer_names=['John Doe', 'Jim Daniels'],
         author_names=['Harry Smith'],
         version='1.2.3',
         catkin_deps=['foobar', 'baz'])
     self.assertEqual('foopackage', template.name)
     self.assertEqual('1.2.3', template.version)
     self.assertEqual('foo_desc', template.description)
     self.assertEqual(['baz', 'foobar'], template.catkin_deps)
     self.assertEqual(1, len(template.authors))
     self.assertEqual('Jim Daniels', template.maintainers[0].name)
     self.assertEqual('John Doe', template.maintainers[1].name)
     self.assertEqual('Harry Smith', template.authors[0].name)
     self.assertEqual(2, len(template.maintainers))
     self.assertEqual([], template.urls)
def create_catkin_package_files(package_name, package_path, args):
    '''
      This is almost a direct copy from catkin_create_pkg.
    '''
    try:
        build_depends = []
        if 'rosjava_build_tools' not in args.dependencies:
            build_depends.append(catkin_pkg.package.Dependency('rosjava_build_tools'))
        for depend_name in args.dependencies:
            build_depends.append(catkin_pkg.package.Dependency(depend_name))
        package_template = PackageTemplate._create_package_template(
            package_name=package_name,
            description=args.description,
            licenses=args.license or [],
            maintainer_names=args.maintainer,
            author_names=args.author,
            version=args.pkg_version,
            catkin_deps=[],
            system_deps=[],
            boost_comps=None)
        package_template.exports = []
        package_template.build_depends = build_depends
        distro_version = utils.distro_version()
        package_xml = create_package_xml(package_template=package_template, rosdistro=distro_version)
        try:
            filename = os.path.join(package_path, 'package.xml')
            f = open(filename, 'w')
            f.write(package_xml)
            console.pretty_print('Created repo file: ', console.cyan)
            console.pretty_println('%s' % filename, console.yellow)
        finally:
            f.close()
    except Exception:
        raise
def create_catkin_package_files(package_name, package_path, args):
    '''
      This is almost a direct copy from catkin_create_pkg.
    '''
    try:
        build_depends = []
        if 'rosjava_build_tools' not in args.dependencies:
            build_depends.append(catkin_pkg.package.Dependency('rosjava_build_tools'))
        for depend_name in args.dependencies:
            build_depends.append(catkin_pkg.package.Dependency(depend_name))
        package_template = PackageTemplate._create_package_template(
            package_name=package_name,
            description=args.description,
            licenses=args.license or [],
            maintainer_names=args.maintainer,
            author_names=args.author,
            version=args.pkg_version,
            catkin_deps=[],
            system_deps=[],
            boost_comps=None)
        package_template.exports = []
        package_template.build_depends = build_depends
        distro_version = utils.distro_version()
        package_xml = create_package_xml(package_template=package_template, rosdistro=distro_version)
        try:
            filename = os.path.join(package_path, 'package.xml')
            f = open(filename, 'w')
            f.write(package_xml)
            console.pretty_print('Created repo file: ', console.cyan)
            console.pretty_println('%s' % filename, console.yellow)
        finally:
            f.close()
    except Exception:
        raise
Example #6
0
def main(argv=sys.argv[1:], parent_path=os.getcwd()):
    parser = argparse.ArgumentParser(
        description='Creates a new catkin package')
    parser.add_argument('name',
                        nargs=1,
                        help='The name for the package')
    parser.add_argument('--meta',
                        action='store_true',
                        help='Creates meta-package files')
    parser.add_argument('dependencies',
                        nargs='*',
                        help='Catkin package Dependencies')
    parser.add_argument('-s', '--sys-deps',
                        nargs='*',
                        help='System Dependencies')
    parser.add_argument('-b', '--boost-comps',
                        nargs='*',
                        help='Boost Components')
    parser.add_argument('-V', '--pkg_version',
                        action='store',
                        help='Initial Package version')
    parser.add_argument('-D', '--description',
                        action='store',
                        help='Description')
    parser.add_argument('-l', '--license',
                        action='append',
                        help='Name for License, (e.g. BSD, MIT, GPLv3...)')
    parser.add_argument('-a', '--author',
                        action='append',
                        help='A single author, may be used multiple times')
    parser.add_argument('-m', '--maintainer',
                        action='append',
                        help='A single maintainer, may be used multiple times')
    rosdistro_name = os.environ['ROS_DISTRO'] if 'ROS_DISTRO' in os.environ else None
    parser.add_argument('--rosdistro', required=rosdistro_name is None, default=rosdistro_name, help='The ROS distro (default: environment variable ROS_DISTRO if defined)')

    args = parser.parse_args(argv)

    try:
        package_name = args.name[0]
        target_path = os.path.join(parent_path, package_name)
        package_template = PackageTemplate._create_package_template(
            package_name=package_name,
            description=args.description,
            licenses=args.license or [],
            maintainer_names=args.maintainer,
            author_names=args.author,
            version=args.pkg_version,
            catkin_deps=args.dependencies,
            system_deps=args.sys_deps,
            boost_comps=args.boost_comps)
        create_package_files(target_path=target_path,
                             package_template=package_template,
                             rosdistro=args.rosdistro,
                             newfiles={},
                             meta=args.meta)
        print('Successfully created files in %s. Please adjust the values in package.xml.' % target_path)
    except ValueError as vae:
        parser.error(str(vae))
Example #7
0
def main(opts):

    try:
        # Get absolute path to directory containing package
        package_dest_path = os.path.abspath(opts.path)

        # Sort list of maintainers and authors (it will also be sorted inside
        # PackageTemplate so by sorting it here, we ensure that the same order
        # is used.  This is important later when email addresses are assigned.
        if opts.maintainers:
            opts.maintainers.sort(key=lambda x: x[0])
        if opts.authors:
            opts.authors.sort(key=lambda x: x[0])

        for package_name in opts.name:
            print('Creating package "%s" in "%s"...' %
                  (package_name, package_dest_path))
            target_path = os.path.join(package_dest_path, package_name)
            package_template = PackageTemplate._create_package_template(
                package_name=package_name,
                description=opts.description,
                licenses=opts.license or [],
                maintainer_names=[m[0] for m in opts.maintainers]
                if opts.maintainers else [],
                author_names=[a[0]
                              for a in opts.authors] if opts.authors else [],
                version=opts.version,
                catkin_deps=opts.catkin_deps,
                system_deps=opts.system_deps,
                boost_comps=opts.boost_components)

            # Add maintainer and author e-mails
            if opts.maintainers:
                for (pm, om) in zip(package_template.maintainers,
                                    opts.maintainers):
                    pm.email = om[1]
            if opts.authors:
                for (pa, oa) in zip(package_template.authors, opts.authors):
                    pa.email = oa[1]

            # Add build type export
            # if opts.build_type and opts.build_type != 'catkin':
            #     build_type = Export('build_type', content=opts.build_type)
            #     package_template.exports.append(build_type)

            create_package_files(target_path=target_path,
                                 package_template=package_template,
                                 rosdistro=opts.rosdistro,
                                 newfiles={})
            print('Successfully created package files in %s.' % target_path)
    except ValueError as vae:
        print(str(vae))
        return 1

    return 0
Example #8
0
def main(options):

    parent_path = os.getcwd()
    print("parent path: %s" % parent_path)
    package_name = options.name[0]
    print("package name: %s" % package_name)
    package_path = os.path.join(parent_path, package_name)
    print("package path: %s" % package_path)
    print_color("@!@{green}==>@|@! Creating %s package..." % package_name)
    try:
        package_template = PackageTemplate._create_package_template(
            package_name=package_name,
            description=options.description,
            licenses=options.license or [],
            maintainer_names=options.maintainer,
            author_names=options.author,
            version=options.pkg_version,
            catkin_deps=options.dependencies,
            system_deps=options.sys_deps,
            boost_comps=options.boost_comps)
        create_package_files(target_path=package_path,
                             package_template=package_template,
                             rosdistro=options.rosdistro,
                             newfiles={},
                             meta=options.meta)
        print(
            'Successfully created files in %s. Please adjust the values in package.xml.'
            % package_path)
    except ValueError as vae:
        print_color("@{red}[ERROR] %s" % vae)

    if not package_exists_at(package_path):
        print_color("@{red}[ERROR] The %s package was not created." %
                    package_name)
        return 1
    print_color("[INFO] The %s package was created." % package_name)

    folders = [
        'include',
        'include/%s' % package_name, 'src',
        'src/%s' % package_name, 'action', 'config', 'launch', 'msg', 'mmsg',
        'srv'
    ]
    print_color("@!@{green}==>@|@! Organizing package...")
    for folder_name in folders:
        folder_path = os.path.join(package_path, folder_name)
        if not os.path.exists(folder_path):
            os.makedirs(folder_path)
            print_color("[INFO] The %s folder was created in the %s package." %
                        (folder_name, package_name))

    return 0
Example #9
0
def main(opts):

    try:
        # Get absolute path to directory containing package
        package_dest_path = os.path.abspath(opts.path)

        # Sort list of maintainers and authors (it will also be sorted inside
        # PackageTemplate so by sorting it here, we ensure that the same order
        # is used.  This is important later when email addresses are assigned.
        if opts.maintainers:
            opts.maintainers.sort(key=lambda x: x[0])
        if opts.authors:
            opts.authors.sort(key=lambda x: x[0])

        for package_name in opts.name:
            print('Creating package "%s" in "%s"...' % (package_name, package_dest_path))
            target_path = os.path.join(package_dest_path, package_name)
            package_template = PackageTemplate._create_package_template(
                package_name=package_name,
                description=opts.description,
                licenses=opts.license or [],
                maintainer_names=[m[0] for m in opts.maintainers] if opts.maintainers else [],
                author_names=[a[0] for a in opts.authors] if opts.authors else [],
                version=opts.version,
                catkin_deps=opts.catkin_deps,
                system_deps=opts.system_deps,
                boost_comps=opts.boost_components)

            # Add maintainer and author e-mails
            if opts.maintainers:
                for (pm, om) in zip(package_template.maintainers, opts.maintainers):
                    pm.email = om[1]
            if opts.authors:
                for (pa, oa) in zip(package_template.authors, opts.authors):
                    pa.email = oa[1]

            # Add build type export
            # if opts.build_type and opts.build_type != 'catkin':
            #     build_type = Export('build_type', content=opts.build_type)
            #     package_template.exports.append(build_type)

            create_package_files(target_path=target_path,
                                 package_template=package_template,
                                 rosdistro=opts.rosdistro,
                                 newfiles={})
            print('Successfully created package files in %s.' % target_path)
    except ValueError as vae:
        print(str(vae))
        return 1

    return 0
Example #10
0
def main(opts):

    try:
        # Get absolute path to directory containing package
        package_dest_path = os.path.abspath(opts.path)
        for package_name in opts.name:
            print('Creating package "%s" in "%s"...' %
                  (package_name, package_dest_path))
            target_path = os.path.join(package_dest_path, package_name)
            package_template = PackageTemplate._create_package_template(
                package_name=package_name,
                description=opts.description,
                licenses=opts.license or [],
                maintainer_names=[m[0] for m in opts.maintainers]
                if opts.maintainers else [],
                author_names=[a[0]
                              for a in opts.authors] if opts.authors else [],
                version=opts.version,
                catkin_deps=opts.catkin_deps,
                system_deps=opts.system_deps,
                boost_comps=opts.boost_components)

            # Add maintainer and author e-mails
            if opts.maintainers:
                for (pm, om) in zip(package_template.maintainers,
                                    opts.maintainers):
                    pm.email = om[1]
            if opts.authors:
                for (pa, oa) in zip(package_template.authors, opts.authors):
                    pa.email = oa[1]

            # Add build type export
            # if opts.build_type and opts.build_type != 'catkin':
            #     build_type = Export('build_type', content=opts.build_type)
            #     package_template.exports.append(build_type)

            create_package_files(target_path=target_path,
                                 package_template=package_template,
                                 rosdistro=opts.rosdistro,
                                 newfiles={})
            print('Successfully created package files in %s.' % target_path)
    except ValueError as vae:
        print(str(vae))
        return 1

    return 0
Example #11
0
def main(opts):

    try:
        package_dest_path = opts.path
        print('path: ' + str(opts.path))
        for package_name in opts.name:
            print('Creating package "%s" in "%s"...' % (package_name, package_dest_path))
            target_path = os.path.join(package_dest_path, package_name)
            package_template = PackageTemplate._create_package_template(
                package_name=package_name,
                description=opts.description,
                licenses=opts.license or [],
                maintainer_names=[m[0] for m in opts.maintainers] if opts.maintainers else [],
                author_names=[a[0] for a in opts.authors] if opts.authors else [],
                version=opts.version,
                catkin_deps=opts.catkin_deps,
                system_deps=opts.system_deps,
                boost_comps=opts.boost_components)

            # Add maintainer and author e-mails
            if opts.maintainers:
                for (pm, om) in zip(package_template.maintainers, opts.maintainers):
                    pm.email = om[1]
            if opts.authors:
                for (pa, oa) in zip(package_template.authors, opts.authors):
                    pa.email = oa[1]

            # Add build type export
            # if opts.build_type and opts.build_type != 'catkin':
            #     build_type = Export('build_type', content=opts.build_type)
            #     package_template.exports.append(build_type)

            create_package_files(target_path=target_path,
                                 package_template=package_template,
                                 rosdistro=opts.rosdistro,
                                 newfiles={})
            print('Successfully created package files in %s.' % target_path)
    except ValueError as vae:
        print(str(vae))
        return 1

    return 0
Example #12
0
def init_package(path: str, package: str) -> None:
    """Create a package at the given path.

    This is equivalent to calling `catkin_create_pkg` on the given path.

    Internal use only.

    Args:
        path (str): Path to create package.
        package (str): Package name.
    """

    package_name = package
    description = "Simulation package created by Fido. DO NOT EDIT."
    maintainer = "Fido maintainers"
    author = "Fido authors"
    version = "0.0.1"
    distro = "melodic"
    target_path = os.path.join(path, "src", package)

    package_template = PackageTemplate._create_package_template(
        package_name=package_name,
        description=description,
        licenses=[],
        maintainer_names=[maintainer],
        author_names=[author],
        version=version,
        catkin_deps=None,
        system_deps=None,
        boost_comps=None,
    )

    if not os.path.exists(target_path):
        os.makedirs(target_path)

    create_package_files(os.path.abspath(target_path), package_template,
                         distro)

    os.makedirs(os.path.join(path, "src", package, "launch"))
    os.makedirs(os.path.join(path, "src", package, "scripts"))
Example #13
0
 def test_create_package_template(self):
     template = PackageTemplate._create_package_template(
         package_name='bar2', catkin_deps=['dep1', 'dep2'])
     self.assertEqual('dep1', template.build_depends[0].name)
     self.assertEqual('dep2', template.build_depends[1].name)
Example #14
0
 def test_create_package_template(self):
     template = PackageTemplate._create_package_template(
         package_name='bar2',
         catkin_deps=['dep1', 'dep2'])
     self.assertEqual('dep1', template.build_depends[0].name)
     self.assertEqual('dep2', template.build_depends[1].name)