def _get_ros_version(distro): distros = get_distros() return 2 if distro not in distros \ else int(distros[distro]['distribution_type'][len('ros'):])
def regenerate_pkg(overlay, pkg, distro, preserve_existing=False): version = get_pkg_version(distro, pkg) ebuild_name =\ '/ros-{0}/{1}/{1}-{2}.ebuild'.format(distro.name, pkg, version) ebuild_name = overlay.repo.repo_dir + ebuild_name patch_path = '/ros-{}/{}/files'.format(distro.name, pkg) patch_path = overlay.repo.repo_dir + patch_path is_ros2 = get_distros()[distro.name]['distribution_type'] == 'ros2' has_patches = os.path.exists(patch_path) pkg_names = get_package_names(distro)[0] patches = None if os.path.exists(patch_path): patches = [f for f in glob.glob('%s/*.patch' % patch_path)] if pkg not in pkg_names: raise RuntimeError("Unknown package '%s'" % (pkg)) # otherwise, remove a (potentially) existing ebuild. prefix = '{0}/ros-{1}/{2}/'.format(overlay.repo.repo_dir, distro.name, pkg) existing = glob.glob('%s*.ebuild' % prefix) previous_version = None if preserve_existing and os.path.isfile(ebuild_name): ok("ebuild for package '%s' up to date, skipping..." % pkg) return None, [] elif existing: overlay.repo.remove_file(existing[0]) previous_version = existing[0].lstrip(prefix).rstrip('.ebuild') manifest_file = '{0}/ros-{1}/{2}/Manifest'.format( overlay.repo.repo_dir, distro.name, pkg) overlay.repo.remove_file(manifest_file) try: current = gentoo_installer(distro, pkg, has_patches) current.ebuild.name = pkg current.ebuild.patches = patches current.ebuild.is_ros2 = is_ros2 except Exception as e: err('Failed to generate installer for package {}!'.format(pkg)) raise e try: ebuild_text = current.ebuild_text() metadata_text = current.metadata_text() except UnresolvedDependency: dep_err = 'Failed to resolve required dependencies for' err("{0} package {1}!".format(dep_err, pkg)) unresolved = current.ebuild.get_unresolved() for dep in unresolved: err(" unresolved: \"{}\"".format(dep)) return None, current.ebuild.get_unresolved() except KeyError as ke: err("Failed to parse data for package {}!".format(pkg)) raise ke make_dir("{}/ros-{}/{}".format(overlay.repo.repo_dir, distro.name, pkg)) success_msg = 'Successfully generated installer for package' ok('{0} \'{1}\'.'.format(success_msg, pkg)) try: ebuild_file = '{0}/ros-{1}/{2}/{2}-{3}.ebuild'.format( overlay.repo.repo_dir, distro.name, pkg, version) ebuild_file = open(ebuild_file, "w") metadata_file = '{0}/ros-{1}/{2}/metadata.xml'.format( overlay.repo.repo_dir, distro.name, pkg) metadata_file = open(metadata_file, "w") ebuild_file.write(ebuild_text) metadata_file.write(metadata_text) except Exception as e: err("Failed to write ebuild/metadata to disk!") raise e return current, previous_version