def main(self, *, args): maintainer = Person(args.maintainer_name) if args.maintainer_email: maintainer.email = args.maintainer_email else: # try getting the email from the global git config git = shutil.which('git') if git is not None: p = subprocess.Popen([git, 'config', '--global', 'user.email'], stdout=subprocess.PIPE) resp = p.communicate() email = resp[0].decode().rstrip() if email: maintainer.email = email if not maintainer.email: maintainer.email = maintainer.name + '@todo.todo' cpp_node_name = None if args.cpp_node_name: cpp_node_name = args.cpp_node_name if args.cpp_node_name == args.cpp_library_name: cpp_node_name = args.cpp_node_name + '_node' print( '[WARNING] node name can not be equal to the library name', file=sys.stderr) print('[WARNING] renaming node to %s' % cpp_node_name, file=sys.stderr) buildtool_depends = args.build_type if args.build_type == 'ament_cmake' and args.cpp_library_name: buildtool_depends = 'ament_cmake_ros' test_dependencies = [] if args.build_type == 'ament_cmake': test_dependencies = ['ament_lint_auto', 'ament_lint_common'] package = Package( package_format=args.package_format, name=args.package_name, version='0.0.0', description=args.description, maintainers=[maintainer], licenses=[args.license], buildtool_depends=[Dependency(buildtool_depends)], build_depends=[Dependency(dep) for dep in args.dependencies], test_depends=[Dependency(dep) for dep in test_dependencies], exports=[Export('build_type', content=args.build_type)]) package_path = os.path.join(args.destination_directory, package.name) if os.path.exists(package_path): return '\nAborted!\nThe directory already exists: ' + package_path + '\nEither ' + \ 'remove the directory or choose a different destination directory or package name' print('going to create a new package') print('package name:', package.name) print('destination directory:', os.path.abspath(args.destination_directory)) print('package format:', package.package_format) print('version:', package.version) print('description:', package.description) print('maintainer:', [str(maintainer) for maintainer in package.maintainers]) print('licenses:', [license_ for license_ in package.licenses]) print('build type:', package.get_build_type()) print('dependencies:', [str(dependency) for dependency in package.build_depends]) if args.cpp_node_name: print('cpp_node_name:', cpp_node_name) if args.cpp_library_name: print('cpp_library_name:', args.cpp_library_name) package_directory, source_directory, include_directory = \ create_package_environment(package, args.destination_directory) if not package_directory: return 'unable to create folder: ' + args.destination_directory if args.build_type == 'cmake': populate_cmake(package, package_directory, cpp_node_name, args.cpp_library_name) if args.build_type == 'ament_cmake': populate_ament_cmake(package, package_directory, cpp_node_name, args.cpp_library_name) if cpp_node_name: if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_cpp_node(package, source_directory, cpp_node_name) if args.cpp_library_name: if not source_directory or not include_directory: return 'unable to create source or include folder in ' + args.destination_directory populate_cpp_library(package, source_directory, include_directory, args.cpp_library_name)
def main(self, *, args): available_licenses = {} for shortname, entry in ament_copyright.get_licenses().items(): available_licenses[entry.spdx] = entry.license_files if args.license == '?': print('Supported licenses:\n%s' % ('\n'.join(available_licenses))) sys.exit(0) maintainer = Person(args.maintainer_name) if args.maintainer_email: maintainer.email = args.maintainer_email else: # try getting the email from the global git config git = shutil.which('git') if git is not None: p = subprocess.Popen([git, 'config', 'user.email'], stdout=subprocess.PIPE) resp = p.communicate() email = resp[0].decode().rstrip() if email: maintainer.email = email if not maintainer.email: maintainer.email = maintainer.name + '@todo.todo' node_name = None library_name = None if args.library_name: library_name = args.library_name if args.node_name: node_name = args.node_name if args.node_name == args.library_name: node_name = args.node_name + '_node' print( '[WARNING] node name can not be equal to the library name', file=sys.stderr) print('[WARNING] renaming node to %s' % node_name, file=sys.stderr) buildtool_depends = [] if args.build_type == 'ament_cmake': if args.library_name: buildtool_depends = ['ament_cmake_ros'] else: buildtool_depends = ['ament_cmake'] test_dependencies = [] if args.build_type == 'ament_cmake': test_dependencies = ['ament_lint_auto', 'ament_lint_common'] if args.build_type == 'ament_python': test_dependencies = [ 'ament_copyright', 'ament_flake8', 'ament_pep257', 'python3-pytest' ] if args.build_type == 'ament_python' and args.package_name == 'test': # If the package name is 'test', there will be a conflict between # the directory the source code for the package goes in and the # directory the tests for the package go in. return "Aborted since 'ament_python' packages can't be named 'test'. Please " + \ 'choose a different package name.' package = Package( package_format=args.package_format, name=args.package_name, version='0.0.0', description=args.description, maintainers=[maintainer], licenses=[args.license], buildtool_depends=[Dependency(dep) for dep in buildtool_depends], build_depends=[Dependency(dep) for dep in args.dependencies], test_depends=[Dependency(dep) for dep in test_dependencies], exports=[Export('build_type', content=args.build_type)]) package_path = os.path.join(args.destination_directory, package.name) if os.path.exists(package_path): return '\nAborted!\nThe directory already exists: ' + package_path + '\nEither ' + \ 'remove the directory or choose a different destination directory or package name' print('going to create a new package') print('package name:', package.name) print('destination directory:', os.path.abspath(args.destination_directory)) print('package format:', package.package_format) print('version:', package.version) print('description:', package.description) print('maintainer:', [str(maintainer) for maintainer in package.maintainers]) print('licenses:', package.licenses) print('build type:', package.get_build_type()) print('dependencies:', [str(dependency) for dependency in package.build_depends]) if node_name: print('node_name:', node_name) if library_name: print('library_name:', library_name) package_directory, source_directory, include_directory = \ create_package_environment(package, args.destination_directory) if not package_directory: return 'unable to create folder: ' + args.destination_directory if args.build_type == 'cmake': populate_cmake(package, package_directory, node_name, library_name) if args.build_type == 'ament_cmake': populate_ament_cmake(package, package_directory, node_name, library_name) if args.build_type == 'ament_python': if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_ament_python(package, package_directory, source_directory, node_name) if node_name: populate_python_node(package, source_directory, node_name) if library_name: populate_python_libary(package, source_directory, library_name) if args.build_type == 'ament_cmake' or args.build_type == 'cmake': if node_name: if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_cpp_node(package, source_directory, node_name) if library_name: if not source_directory or not include_directory: return 'unable to create source or include folder in ' + \ args.destination_directory populate_cpp_library(package, source_directory, include_directory, library_name) if args.license in available_licenses: with open(os.path.join(package_directory, 'LICENSE'), 'w') as outfp: for lic in available_licenses[args.license]: outfp.write(lic) else: print( "\n[WARNING]: Unknown license '%s'. This has been set in the package.xml, but " 'no LICENSE file has been created.\nIt is recommended to use one of the ament ' 'license identitifers:\n%s' % (args.license, '\n'.join(available_licenses)))
def main(self, *, args): # when a package-type extension exists, delegate package creation to it. extension = get_package_type_extension(args.build_type) if extension: return extension.create_package(args) maintainer = Person(args.maintainer_name) if args.maintainer_email: maintainer.email = args.maintainer_email else: # try getting the email from the global git config git = shutil.which('git') if git is not None: p = subprocess.Popen([git, 'config', '--global', 'user.email'], stdout=subprocess.PIPE) resp = p.communicate() email = resp[0].decode().rstrip() if email: maintainer.email = email if not maintainer.email: maintainer.email = maintainer.name + '@todo.todo' node_name = None library_name = None if args.library_name: library_name = args.library_name if args.node_name: node_name = args.node_name if args.node_name == args.library_name: node_name = args.node_name + '_node' print( '[WARNING] node name can not be equal to the library name', file=sys.stderr) print('[WARNING] renaming node to %s' % node_name, file=sys.stderr) buildtool_depends = [] if args.build_type == 'ament_cmake': if args.library_name: buildtool_depends = ['ament_cmake_ros'] else: buildtool_depends = ['ament_cmake'] test_dependencies = [] if args.build_type == 'ament_cmake': test_dependencies = ['ament_lint_auto', 'ament_lint_common'] if args.build_type == 'ament_python': test_dependencies = [ 'ament_copyright', 'ament_flake8', 'ament_pep257', 'python3-pytest' ] if args.build_type == 'ament_python' and args.package_name == 'test': # If the package name is 'test', there will be a conflict between # the directory the source code for the package goes in and the # directory the tests for the package go in. return "Aborted since 'ament_python' packages can't be named 'test'. Please " + \ 'choose a different package name.' package = Package( package_format=args.package_format, name=args.package_name, version='0.0.0', description=args.description, maintainers=[maintainer], licenses=[args.license], buildtool_depends=[Dependency(dep) for dep in buildtool_depends], build_depends=[Dependency(dep) for dep in args.dependencies], test_depends=[Dependency(dep) for dep in test_dependencies], exports=[Export('build_type', content=args.build_type)]) package_path = os.path.join(args.destination_directory, package.name) if os.path.exists(package_path): return '\nAborted!\nThe directory already exists: ' + package_path + '\nEither ' + \ 'remove the directory or choose a different destination directory or package name' print('going to create a new package') print('package name:', package.name) print('destination directory:', os.path.abspath(args.destination_directory)) print('package format:', package.package_format) print('version:', package.version) print('description:', package.description) print('maintainer:', [str(maintainer) for maintainer in package.maintainers]) print('licenses:', package.licenses) print('build type:', package.get_build_type()) print('dependencies:', [str(dependency) for dependency in package.build_depends]) if node_name: print('node_name:', node_name) if library_name: print('library_name:', library_name) package_directory, source_directory, include_directory = \ create_package_environment(package, args.destination_directory) if not package_directory: return 'unable to create folder: ' + args.destination_directory if args.build_type == 'cmake': populate_cmake(package, package_directory, node_name, library_name) if args.build_type == 'ament_cmake': populate_ament_cmake(package, package_directory, node_name, library_name) if args.build_type == 'ament_python': if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_ament_python(package, package_directory, source_directory, node_name) if node_name: populate_python_node(package, source_directory, node_name) if library_name: populate_python_libary(package, source_directory, library_name) if args.build_type == 'ament_cmake' or args.build_type == 'cmake': if node_name: if not source_directory: return 'unable to create source folder in ' + args.destination_directory populate_cpp_node(package, source_directory, node_name) if library_name: if not source_directory or not include_directory: return 'unable to create source or include folder in ' + \ args.destination_directory populate_cpp_library(package, source_directory, include_directory, library_name)