def main(): overlay = None preserve_existing = True parser = get_parser('Deploy ROS packages into Gentoo Linux') args = parser.parse_args(sys.argv[1:]) pr_comment = args.pr_comment selected_targets = None if args.all: warn('"All" mode detected... This may take a while!') preserve_existing = False elif args.ros_distro: selected_targets = [args.ros_distro] set_index_for_distro(args.ros_distro) preserve_existing = False elif args.dry_run and args.pr_only: parser.error('Invalid args! cannot dry-run and file PR') elif args.pr_only and not args.output_repository_path: parser.error('Invalid args! no repository specified') elif args.pr_only: try: prev_overlay = RepoInstance(args.output_repository_path, False) msg, title = load_pr() prev_overlay.pull_request(msg, title) clean_up() sys.exit(0) except Exception as e: err('Failed to file PR!') err('reason: {0}'.format(e)) sys.exit(1) if not selected_targets: selected_targets = active_distros + ros2_distros repo_org = 'ros' repo_name = 'ros-overlay' if args.upstream_repo: repo_org, repo_name = url_to_repo_org(args.upstream_repo) with TempfileManager(args.output_repository_path) as _repo: if not args.output_repository_path: # give our group write permissions to the temp dir os.chmod(_repo, 17407) # clone if args.output_repository_path is None overlay = RosOverlay( _repo, not args.output_repository_path, org=repo_org, repo=repo_name ) if not preserve_existing and not args.only: pr_comment = pr_comment or ( 'Superflore ebuild generator began regeneration of all' ' packages from ROS distro %s from ROS-Overlay commit %s.' % ( selected_targets, overlay.repo.get_last_hash() ) ) elif not args.only: pr_comment = pr_comment or ( 'Superflore ebuild generator ran update from ROS-Overlay ' + 'commit %s.' % (overlay.repo.get_last_hash()) ) # generate installers total_installers = dict() total_broken = set() total_changes = dict() if args.only: pr_comment = pr_comment or ( 'Superflore ebuild generator began regeneration of ' + 'package(s) %s from commit %s.' % ( args.only, overlay.repo.get_last_hash() ) ) for pkg in args.only: info("Regenerating package '%s'..." % pkg) try: regenerate_pkg( overlay, pkg, get_distro(args.ros_distro), preserve_existing ) except KeyError: err("No package to satisfy key '%s'" % pkg) sys.exit(1) # Commit changes and file pull request regen_dict = dict() regen_dict[args.ros_distro] = args.only overlay.regenerate_manifests(regen_dict) overlay.commit_changes(args.ros_distro) if args.dry_run: save_pr( overlay, args.only, missing_deps=None, comment=pr_comment ) sys.exit(0) delta = "Regenerated: '%s'\n" % args.only file_pr(overlay, delta, '', pr_comment) ok('Successfully synchronized repositories!') sys.exit(0) for distro in selected_targets: set_index_for_distro(distro) distro_installers, distro_broken, distro_changes =\ generate_installers( distro_name=distro, overlay=overlay, gen_pkg_func=regenerate_pkg, preserve_existing=preserve_existing ) for key in distro_broken.keys(): for pkg in distro_broken[key]: total_broken.add(pkg) total_changes[distro] = distro_changes total_installers[distro] = distro_installers num_changes = 0 for distro_name in total_changes: num_changes += len(total_changes[distro_name]) if num_changes == 0: info('ROS distro is up to date.') info('Exiting...') clean_up() sys.exit(0) # remove duplicates delta = gen_delta_msg(total_changes) missing_deps = gen_missing_deps_msg(total_broken) # Commit changes and file pull request overlay.regenerate_manifests(total_installers) overlay.commit_changes(args.ros_distro) if args.dry_run: info('Running in dry mode, not filing PR') save_pr( overlay, delta, missing_deps=missing_deps, comment=pr_comment ) sys.exit(0) file_pr(overlay, delta, missing_deps, comment=pr_comment) clean_up() ok('Successfully synchronized repositories!')
def main(): overlay = None preserve_existing = True parser = get_parser('Deploy ROS packages into Gentoo Linux') args = parser.parse_args(sys.argv[1:]) pr_comment = args.pr_comment skip_keys = args.skip_keys or [] selected_targets = None if not args.dry_run: if 'SUPERFLORE_GITHUB_TOKEN' not in os.environ: raise NoGitHubAuthToken() if args.pr_only: if args.dry_run: parser.error('Invalid args! cannot dry-run and file PR') if not args.output_repository_path: parser.error('Invalid args! no repository specified') try: prev_overlay = RepoInstance(args.output_repository_path, False) msg, title = load_pr() prev_overlay.pull_request(msg, title=title) clean_up() sys.exit(0) except Exception as e: err('Failed to file PR!') err('reason: {0}'.format(e)) sys.exit(1) elif args.all: warn('"All" mode detected... This may take a while!') preserve_existing = False elif args.ros_distro: warn('"{0}" distro detected...'.format(args.ros_distro)) selected_targets = [args.ros_distro] preserve_existing = False elif args.only: parser.error('Invalid args! --only requires specifying --ros-distro') if not selected_targets: selected_targets = get_distros_by_status('active') repo_org = 'ros' repo_name = 'ros-overlay' if args.upstream_repo: repo_org, repo_name = url_to_repo_org(args.upstream_repo) with TempfileManager(args.output_repository_path) as _repo: if not args.output_repository_path: # give our group write permissions to the temp dir os.chmod(_repo, 17407) # clone if args.output_repository_path is None overlay = RosOverlay( _repo, not args.output_repository_path, org=repo_org, repo=repo_name, from_branch=args.upstream_branch, new_branch=(not args.no_branch), ) if not preserve_existing and not args.only: pr_comment = pr_comment or ( 'Superflore ebuild generator began regeneration of all' ' packages from ROS distro %s from ROS-Overlay commit %s.' % (selected_targets, overlay.repo.get_last_hash())) elif not args.only: pr_comment = pr_comment or ( 'Superflore ebuild generator ran update from ROS-Overlay ' + 'commit %s.' % (overlay.repo.get_last_hash())) # generate installers total_installers = dict() total_broken = set() total_changes = dict() if args.only: pr_comment = pr_comment or ( 'Superflore ebuild generator began regeneration of ' + 'package(s) %s from commit %s.' % (args.only, overlay.repo.get_last_hash())) missing_depends = set() to_commit = set() will_file_pr = False for pkg in args.only: if pkg in skip_keys: warn("Package '%s' is in skip-keys list, skipping..." % pkg) continue info("Regenerating package '%s'..." % pkg) try: ebuild, deps, version = regenerate_pkg( overlay, pkg, get_distro(args.ros_distro), preserve_existing) if not ebuild: for dep in deps: missing_depends.add(dep) except KeyError: err("No package to satisfy key '%s'" % pkg) continue if ebuild: to_commit.add(pkg) will_file_pr = True # if no packages succeeded, exit with error if not will_file_pr: err("No packages generated successfully, exiting.") sys.exit(1) # Commit changes and file pull request regen_dict = dict() regen_dict[args.ros_distro] = to_commit overlay.regenerate_manifests(regen_dict) overlay.commit_changes(args.ros_distro) if args.dry_run: save_pr(overlay, args.only, missing_deps=gen_missing_deps_msg(missing_depends), comment=pr_comment) sys.exit(0) delta = "Regenerated: '%s'\n" % args.only file_pr(overlay, delta, gen_missing_deps_msg(missing_depends), pr_comment) ok('Successfully synchronized repositories!') sys.exit(0) for distro in selected_targets: distro_installers, distro_broken, distro_changes =\ generate_installers( get_distro(distro), overlay=overlay, gen_pkg_func=regenerate_pkg, preserve_existing=preserve_existing, skip_keys=skip_keys, ) for key in distro_broken.keys(): for pkg in distro_broken[key]: total_broken.add(pkg) total_changes[distro] = distro_changes total_installers[distro] = distro_installers num_changes = 0 for distro_name in total_changes: num_changes += len(total_changes[distro_name]) if num_changes == 0: info('ROS distro is up to date.') info('Exiting...') clean_up() sys.exit(0) # remove duplicates delta = gen_delta_msg(total_changes) missing_deps = gen_missing_deps_msg(total_broken) # Commit changes and file pull request overlay.regenerate_manifests(total_installers) overlay.commit_changes('all' if args.all else args.ros_distro) if args.dry_run: info('Running in dry mode, not filing PR') save_pr(overlay, delta, missing_deps=missing_deps, comment=pr_comment) sys.exit(0) file_pr(overlay, delta, missing_deps, comment=pr_comment) clean_up() ok('Successfully synchronized repositories!')
def main(): global overlay global preserve_existing parser = argparse.ArgumentParser('Deploy ROS packages into Gentoo Linux') parser.add_argument('--ros-distro', help='regenerate packages for the specified distro', type=str) parser.add_argument('--all', help='regenerate all packages in all distros', action="store_true") parser.add_argument('--dry-run', help='run without filing a PR to remote', action="store_true") parser.add_argument('--pr-only', help='ONLY file a PR to remote', action='store_true') parser.add_argument('--output-repository-path', help='location of the Git repo', type=str) parser.add_argument('--only', nargs='+', help='generate only the specified packages') args = parser.parse_args(sys.argv[1:]) selected_targets = None if args.all: warn('"All" mode detected... This may take a while!') preserve_existing = False elif args.ros_distro: selected_targets = [args.ros_distro] preserve_existing = False elif args.dry_run and args.pr_only: parser.error('Invalid args! cannot dry-run and file PR') elif args.pr_only and not args.output_repository_path: parser.error('Invalid args! no repository specified') elif args.pr_only: try: with open('.pr-message.tmp', 'r') as msg_file: msg = msg_file.read().rstrip('\n') with open('.pr-title.tmp', 'r') as title_file: title = title_file.read().rstrip('\n') except OSError: err('Failed to open PR title/message file!') err('Please supply the %s and %s files' % ('.pr_message.tmp', '.pr_title.tmp')) raise try: prev_overlay = RepoInstance(args.output_repository_path, False) info('PR message:\n"%s"\n' % msg) info('PR title:\n"%s"\n' % title) prev_overlay.pull_request(msg, title) clean_up() sys.exit(0) except Exception as e: err('Failed to file PR!') err('reason: {0}'.format(e)) sys.exit(1) if not selected_targets: selected_targets = active_distros with TempfileManager(args.output_repository_path) as _repo: if not args.output_repository_path: # give our group write permissions to the temp dir os.chmod(_repo, 17407) # clone if args.output_repository_path is None overlay = RosOverlay(_repo, not args.output_repository_path) # generate installers total_installers = dict() total_broken = set() total_changes = dict() if args.only: for pkg in args.only: info("Regenerating package '%s'..." % pkg) regenerate_pkg(overlay, pkg, get_distro(args.ros_distro), preserve_existing) # Commit changes and file pull request regen_dict = dict() regen_dict[args.ros_distro] = args.only overlay.regenerate_manifests(regen_dict) overlay.commit_changes(args.ros_distro) delta = "Regenerated: '%s'\n" % args.only if args.dry_run: info('Running in dry mode, not filing PR') title_file = open('.pr-title.tmp', 'w') title_file.write('rosdistro sync, {0}\n'.format(time.ctime())) pr_message_file = open('.pr-message.tmp', 'w') pr_message_file.write('%s\n%s\n' % (delta, '')) sys.exit(0) file_pr(overlay, delta, '') clean_up() ok('Successfully synchronized repositories!') sys.exit(0) for distro in selected_targets: distro_installers, distro_broken, distro_changes =\ generate_installers( distro_name=distro, overlay=overlay, gen_pkg_func=regenerate_pkg, preserve_existing=preserve_existing ) for key in distro_broken.keys(): for pkg in distro_broken[key]: total_broken.add(pkg) total_changes[distro] = distro_changes total_installers[distro] = distro_installers num_changes = 0 for distro_name in total_changes: num_changes += len(total_changes[distro_name]) if num_changes == 0: info('ROS distro is up to date.') info('Exiting...') clean_up() sys.exit(0) # remove duplicates inst_list = total_broken delta = "Changes:\n" delta += "========\n" if 'indigo' in total_changes and len(total_changes['indigo']) > 0: delta += "Indigo Changes:\n" delta += "---------------\n" for d in sorted(total_changes['indigo']): delta += '* {0}\n'.format(d) delta += "\n" if 'kinetic' in total_changes and len(total_changes['kinetic']) > 0: delta += "Kinetic Changes:\n" delta += "----------------\n" for d in sorted(total_changes['kinetic']): delta += '* {0}\n'.format(d) delta += "\n" if 'lunar' in total_changes and len(total_changes['lunar']) > 0: delta += "Lunar Changes:\n" delta += "--------------\n" for d in sorted(total_changes['lunar']): delta += '* {0}\n'.format(d) delta += "\n" missing_deps = '' if len(inst_list) > 0: missing_deps = "Missing Dependencies:\n" missing_deps += "=====================\n" for pkg in sorted(inst_list): missing_deps += " * [ ] {0}\n".format(pkg) # Commit changes and file pull request overlay.regenerate_manifests(total_installers) overlay.commit_changes(args.ros_distro) if args.dry_run: info('Running in dry mode, not filing PR') title_file = open('.pr-title.tmp', 'w') title_file.write('rosdistro sync, {0}\n'.format(time.ctime())) pr_message_file = open('.pr-message.tmp', 'w') pr_message_file.write('%s\n%s\n' % (delta, missing_deps)) sys.exit(0) file_pr(overlay, delta, missing_deps) clean_up() ok('Successfully synchronized repositories!')