def get_version(self): ros_pkg = generator.generate_rosinstall(self.rosdistro, [self.name], deps=False, wet_only=True, tar=True) return re.match('[\w-]*-([0-9-_.]*)(-[0-9-]*)', ros_pkg[0]['tar']['version']).group(1)
def get_sources(self): sources = self.get_sources_from_cfg() ros_pkg = generator.generate_rosinstall(self.rosdistro, [self.name], deps=False, wet_only=True, tar=True) sources.append(ros_pkg[0]['tar']['uri']) return sources
def scrape_for_release_message_packages(track): try: # Should use ROS_DISTRO here, or some passed in value. rosinstall_data = generate_rosinstall(track, [ARG_ALL_PACKAGES], wet_only=True, dry_only=False ) except RuntimeError as unused_e: raise RuntimeError("error occured while scraping rosdistro for msg package naems and versions.") rosinstall_data = sort_rosinstall(rosinstall_data) #print("%s" % rosinstall_data) packages = [] for element in rosinstall_data: for unused_key, value in element.items(): if "_msgs" in value['local-name'] or "_srvs" in value['local-name']: name = value['local-name'] # bloom version is usually of the form: 'release/hydro/zeroconf_msgs/0.2.1-0' version = value['version'].split('/')[-1].split('-')[0] pkg = {'name': name, 'version': version} packages.append(pkg) return packages
def scrape_for_release_message_packages(track): try: # Should use ROS_DISTRO here, or some passed in value. rosinstall_data = generate_rosinstall(track, [ARG_ALL_PACKAGES], wet_only=True, dry_only=False) except RuntimeError as unused_e: raise RuntimeError( "error occured while scraping rosdistro for msg package naems and versions." ) rosinstall_data = sort_rosinstall(rosinstall_data) #print("%s" % rosinstall_data) packages = [] for element in rosinstall_data: for unused_key, value in element.items(): if "_msgs" in value['local-name'] or "_srvs" in value['local-name']: name = value['local-name'] # bloom version is usually of the form: 'release/hydro/zeroconf_msgs/0.2.1-0' version = value['version'].split('/')[-1].split('-')[0] pkg = {'name': name, 'version': version} packages.append(pkg) return packages
def main(argv=sys.argv[1:]): distro_name = os.environ[ 'ROS_DISTRO'] if 'ROS_DISTRO' in os.environ else None parser = argparse.ArgumentParser( description='Generate a .rosinstall file for a set of packages.') parser.add_argument( '--debug', action='store_true', default=False, help= 'Print debug information about fetching the ROS distribution files to stderr' ) parser.add_argument('--verbose', action='store_true', default=False, help='Print verbose information to stderr') parser.add_argument( '--rosdistro', required=distro_name is None, default=distro_name, help= 'The ROS distro (default: environment variable ROS_DISTRO if defined)') parser.add_argument( 'package_names', nargs='*', metavar='pkgname', help= "catkin package names, rosbuild stack names or variant names. Use '%s' to specify all packages available in the current environment. Use '%s' to specify all release packages (only usable as a single argument)." % (ARG_CURRENT_ENVIRONMENT, ARG_ALL_PACKAGES)) parser.add_argument( '--from-path', type=_existing_directory, nargs='*', help= "Add a set of catkin packages found recursively under the given path as if they would have been passed as 'package_names'." ) parser.add_argument( '--repos', nargs='*', metavar='reponame', help= "Repository names containing catkin packages. Use '%s' to specify all release packages (only usable as a single argument)." % ARG_ALL_PACKAGES) group = parser.add_mutually_exclusive_group() group.add_argument( '--upstream', action='store_true', default=False, help= 'Fetch the release tag of catkin packages from the upstream repo instead of the gbp. Note that this implies always fetching the whole repository which might contain additional (unreleased) packages.' ) group.add_argument( '--upstream-development', action='store_true', default=False, help= 'Fetch the development version of catkin packages from the upstream repo instead of the gbp. Be aware that the development version might not even be intended to build between releases. Note that this implies always fetching the whole repository which might contain additional (unreleased) packages.' ) group = parser.add_mutually_exclusive_group() group.add_argument('--deps', action='store_true', default=False, help='Include recursive dependencies') group.add_argument( '--deps-up-to', nargs='*', help= "A set of packages which will limit the recursive dependencies to packages which (in-)directly depend on a package in this set. Use '%s' to specify all packages available in the current environment." % ARG_CURRENT_ENVIRONMENT) # implies either --deps or --deps-up-to parser.add_argument( '--deps-depth', type=int, metavar='N', help= 'Limit recursive dependencies to a specific level (not supported on Groovy).' ) parser.add_argument( '--deps-only', action='store_true', default=False, help= 'Include only the recursive dependencies but not the specified packages' ) group = parser.add_mutually_exclusive_group() group.add_argument('--wet-only', action='store_true', default=False, help='Only include catkin packages') group.add_argument('--dry-only', action='store_true', default=False, help='Only include rosbuild stacks') group.add_argument('--catkin-only', action='store_true', default=False, help="Only wet packages with build type 'catkin'") group.add_argument( '--non-catkin-only', action='store_true', default=False, help="Only wet packages with build type other than 'catkin'") parser.add_argument( '--exclude', nargs='*', help= "Exclude a set of packages (also skips further recursive dependencies). Use '%s' to specify all packages available in the current environment." % ARG_CURRENT_ENVIRONMENT) parser.add_argument( '--exclude-path', type=_existing_directory, nargs='*', help= 'Exclude a set of catkin packages found recursively under the given path (also skips further recursive dependencies).' ) parser.add_argument( '--flat', action='store_true', default=False, help= 'Use a flat folder structure without a parent folder names after the repository containing the catkin packages' ) parser.add_argument( '--tar', action='store_true', default=False, help= 'Use tarballs instead of repositories for catkin packages (rosbuild stacks are always tarballs)' ) parser.add_argument( '--format', choices=('rosinstall', 'repos'), default='rosinstall', help='Output the repository information in .rosinstall or .repos format' ) args = parser.parse_args(argv) # check for invalid combinations if args.rosdistro == 'groovy' and args.deps_depth: parser.error( "Option '--deps-depth N' is not available for the ROS distro 'groovy'" ) if args.rosdistro != 'groovy': if args.dry_only: parser.error( "For the ROS distro '%s' there are no rosbuild released packages so '--dry-only' is not a valid option" % args.rosdistro) args.wet_only = True if not args.package_names and not args.from_path and not args.repos: parser.error( 'Either some package names must be specified, some --from-path or some repository names using --repos' ) if ARG_ALL_PACKAGES in args.package_names and (len(args.package_names) > 1 or args.repos): parser.error( "When using '%s' as a package name no other names can be specified" % ARG_ALL_PACKAGES) if not args.deps and not args.deps_up_to: if args.deps_depth: parser.error( "Option '--deps-depth N' can only be used together with either '--deps' or '--deps-up-to'" ) if args.deps_only: parser.error( "Option '--deps-only' can only be used together with either '--deps' or '--deps-up-to'" ) if args.deps_depth is not None and args.deps_depth < 1: parser.error( "The argument 'N' to the option '--deps-depth ' must be a positive integer" ) if args.catkin_only or args.non_catkin_only: args.wet_only = True # pass all logging output to stderr logger = logging.getLogger('rosinstall_generator') logger.addHandler(logging.StreamHandler(sys.stderr)) verbose_level = logging.DEBUG if args.verbose else logging.INFO logger.setLevel(verbose_level) debug_level = logging.DEBUG if args.debug else logging.INFO logger = logging.getLogger('rosinstall_generator.dry') logger.setLevel(debug_level) logger = logging.getLogger('rosinstall_generator.wet') logger.setLevel(debug_level) if '--rosdistro' not in argv: print('Using ROS_DISTRO: %s' % args.rosdistro, file=sys.stderr) try: rosinstall_data = generate_rosinstall( args.rosdistro, args.package_names, from_paths=args.from_path, repo_names=args.repos, deps=args.deps, deps_up_to=args.deps_up_to, deps_depth=args.deps_depth, deps_only=args.deps_only, wet_only=args.wet_only, dry_only=args.dry_only, catkin_only=args.catkin_only, non_catkin_only=args.non_catkin_only, excludes=args.exclude, exclude_paths=args.exclude_path, flat=args.flat, tar=args.tar, upstream_version_tag=args.upstream, upstream_source_version=args.upstream_development) except RuntimeError as e: if args.debug: raise print(str(e), file=sys.stderr) return 1 if args.format == 'rosinstall': rosinstall_data = sort_rosinstall(rosinstall_data) elif args.format == 'repos': # convert data into .repos format repos_data = {} for data in rosinstall_data: assert len(data) == 1 type_ = list(data.keys())[0] repo_data = data[type_] assert repo_data[ 'local-name'] not in repos_data, 'Multiple entries with the local-name: ' + repo_data[ 'local-name'] repos_data[repo_data['local-name']] = { 'type': type_, 'url': repo_data['uri'], } if 'version' in repo_data and type_ != 'tar': repos_data[ repo_data['local-name']]['version'] = repo_data['version'] rosinstall_data = {'repositories': repos_data} else: assert False, 'Unhandled format: ' + args.format print(yaml.safe_dump(rosinstall_data, default_flow_style=False)) return 0
def get_rosinstall(distro_name, names, wet_only=False, dry_only=False): rosinstall_data = generate_rosinstall(distro_name, names, wet_only=wet_only, dry_only=dry_only, deps=True, tar=True) rosinstall_data = sort_rosinstall(rosinstall_data) return yaml.safe_dump(rosinstall_data, default_flow_style=False)
def package_to_apkbuild(ros_distro, package_name, check=True, upstream=False, src=False, revfn=static_revfn(0), ver_suffix=None, commit_hash=None): pkg_xml = '' todo_upstream_clone = dict() ros_python_version = os.environ["ROS_PYTHON_VERSION"] if package_name.startswith('http://') or package_name.startswith( 'https://'): import requests res = requests.get(package_name) pkg_xml = res.text elif package_name.endswith('.xml'): with open(package_name, 'r') as f: pkg_xml = f.read() else: distro = get_wet_distro(ros_distro) pkg_xml = distro.get_release_package_xml(package_name) if upstream: todo_upstream_clone['read_manifest'] = True pkg = parse_package_string(pkg_xml) # generate rosinstall rosinstall = None if not src: rosinstall = generate_rosinstall( ros_distro, [pkg.name], flat=True, tar=False, upstream_source_version=(True if upstream else False)) rosinstall[0]['git']['local-name'] = pkg.name if upstream: if commit_hash is not None: rosinstall[0]['git']['version'] = commit_hash if ver_suffix is None: todo_upstream_clone['obtain_ver_suffix'] = True elif ver_suffix is None: date = git_date() if date is not None: ver_suffix = '_git' + date # temporary close upstream if needed if len(todo_upstream_clone) > 0: import tempfile with tempfile.TemporaryDirectory() as tmpd: pkglist = '/'.join([tmpd, 'pkg.rosinstall']) f = open(pkglist, 'w') f.write(yaml.dump(rosinstall)) f.close() subprocess.check_output( ['vcs', 'import', '--input', pkglist, tmpd]) basepath = '/'.join([tmpd, rosinstall[0]['git']['local-name']]) if 'read_manifest' in todo_upstream_clone and todo_upstream_clone[ 'read_manifest']: target_name = pkg.name pkg = None for root, _, names in os.walk(basepath): if pkg is not None: break for name in names: if name == 'package.xml': with open('/'.join([root, name]), 'r') as f: pkg_tmp = parse_package_string(f.read()) if pkg_tmp.name == target_name: pkg = pkg_tmp break if 'obtain_ver_suffix' in todo_upstream_clone and todo_upstream_clone[ 'obtain_ver_suffix']: date = git_date('/'.join( [tmpd, rosinstall[0]['git']['local-name']])) if date is not None: ver_suffix = '_git' + date pkg.evaluate_conditions(os.environ) depends = [] for dep in pkg.exec_depends: depends.append(ros_dependency_to_name_ver(dep)) depends_keys = resolve(ros_distro, depends) depends_export = [] for dep in pkg.buildtool_export_depends: depends_export.append(ros_dependency_to_name_ver(dep)) for dep in pkg.build_export_depends: depends_export.append(ros_dependency_to_name_ver(dep)) depends_export_keys = resolve(ros_distro, depends_export) makedepends = [] catkin = False cmake = False for dep in pkg.buildtool_depends: makedepends.append(ros_dependency_to_name_ver(dep)) if dep.name == 'catkin': catkin = True elif dep.name == 'cmake': cmake = True if (catkin and cmake) or ((not catkin) and (not cmake)): print('Un-supported buildtool ' + ' '.join(makedepends), file=sys.stderr) sys.exit(1) for dep in pkg.build_depends: makedepends.append(ros_dependency_to_name_ver(dep)) for dep in pkg.test_depends: makedepends.append(ros_dependency_to_name_ver(dep)) makedepends_keys = resolve(ros_distro, makedepends) if depends_keys is None or depends_export_keys is None or makedepends_keys is None: sys.exit(1) # Remove duplicated dependency keys depends_keys = sorted(list(set(depends_keys))) depends_export_keys = sorted(list(set(depends_export_keys))) makedepends_keys = sorted(list(set(makedepends_keys))) makedepends_implicit = [ 'py-setuptools', 'py-rosdep', 'py-rosinstall', 'py-rosinstall-generator', 'py-vcstool', 'chrpath' ] # Force using py3- packages for Python 3 build if ros_python_version == '3': depends_keys = force_py3_keys(depends_keys) depends_export_keys = force_py3_keys(depends_export_keys) makedepends_keys = force_py3_keys(makedepends_keys) makedepends_implicit = force_py3_keys(makedepends_implicit) if ver_suffix is None: ver_suffix = '' g = { 'pkgname': ros_pkgname_to_pkgname(ros_distro, pkg.name), '_pkgname': pkg.name, 'pkgver': pkg.version + ver_suffix, 'pkgrel': revfn(pkg.version + ver_suffix), 'ros_distro': ros_distro, 'url': pkg.urls[0].url if len(pkg.urls) > 0 else 'http://wiki.ros.org/$_pkgname', 'license': pkg.licenses[0], 'check': check, 'depends': depends_keys + depends_export_keys, 'makedepends': makedepends_implicit + makedepends_keys, 'ros_python_version': os.environ["ROS_PYTHON_VERSION"], 'rosinstall': None if src else yaml.dump(rosinstall), 'vcstool_opt': '' if upstream and commit_hash is not None else '--shallow', 'use_upstream': upstream, 'use_catkin': catkin, 'use_cmake': cmake, } template_path = os.path.join(os.path.dirname(__file__), 'APKBUILD.em.sh') apkbuild = StringIO() interpreter = em.Interpreter(output=apkbuild, globals=g) interpreter.file(open(template_path)) interpreter.flush() apkbuild_str = apkbuild.getvalue() interpreter.shutdown() return apkbuild_str
# Sometimes a name can be shared by both a meta and regular package # Generate list of packages if pkg_name == None and not args.update_existing: # Get a list of all packages # This currently includes Meta and Regular packages pkg_list = generate_package_list() elif pkg_name == None and args.update_existing: # If no package name is given and update_existing is TRUE then # use the list of packages within the given OBS Project pkg_list = osc.core.meta_get_packagelist(apiurl, project) else: # If "-gen_deps" option is set, then add all dependencies to pkg_list if args.gen_deps: rosinstall_data = generate_rosinstall(rdistro, pkg_name, deps=True, flat=True) dep_list = [item['git']['local-name'] for item in rosinstall_data] pkg_list = dep_list else: pkg_list = pkg_name ptot = len(pkg_list) pcounter = 0 scounter = 0 fcounter = 0 for p in sorted(pkg_list): pcounter += 1 print("{}/{} Looking for package data for {}".format( pcounter, ptot, p))