def _get_route_dvers_pairs(routenames, valid_routes, extra_dvers, no_dvers, only_dver): route_dvers_pairs = [] for routename in routenames: route = valid_routes[routename] if only_dver: if only_dver in route.dvers or only_dver in route.extra_dvers: route_dvers_pairs.append((route, set([only_dver]))) else: printf("The dver %s is not available for route %s.", only_dver, routename) _print_route_dvers(routename, route) sys.exit(2) continue wanted_dvers_for_route = set(route.dvers) for extra_dver in extra_dvers: if extra_dver in route.extra_dvers: wanted_dvers_for_route.add(extra_dver) for no_dver in no_dvers: wanted_dvers_for_route.discard(no_dver) if not wanted_dvers_for_route: printf("All dvers for route %s have been disabled.") _print_route_dvers(routename, route) sys.exit(2) route_dvers_pairs.append((route, wanted_dvers_for_route)) return route_dvers_pairs
def watch_builds(self, tasks): """Helper for do_promotions(). Watch builds being promoted and return successful ones. 'tasks' is a dict of koji tasks keyed by the koji task ID Promoted builds are returned as a dict keyed by 'build_no_dver' (i.e. the NVR with the dver chopped off), containing dicts keyed by dver, containing the build (i.e. NVR as string). """ self.kojihelper.watch_tasks(list(tasks.keys())) promoted_builds = {} for task_id, (tag, build) in tasks.items(): if self.kojihelper.get_task_state(task_id) == 'CLOSED': promoted_builds.setdefault(tag, []) promoted_builds[tag].append(build) else: printf("* Error promoting build %s", build.nvr) return promoted_builds
def do_promotions(self, dry_run=False, regen=False): """Tag all builds selected to be tagged in self.tag_pkg_args. self.tag_pkg_args is a list of (tag, [builds]) pairs. If dry_run is True, no actual tagging happens. If regen is True, then each repository that gets modified will be regenerated after all tagging is done. Will not attempt to tag builds already in the destination tag. Return builds successfully promoted. """ printf("--- Tagging builds") tasks = dict() for tag, builds in self.tag_pkg_args.items(): for build in builds: try: # Make sure the build isn't already in tag if build.nvr in self.kojihelper.get_tagged_builds(tag): printf("Skipping %s, already in %s", build.nvr, tag) continue except KeyError: pass # Launch the builds if not dry_run: task_id = self.kojihelper.tag_build(tag, build.nvr) tasks[task_id] = (tag, build) else: printf("tagBuild('%s', '%s')", tag, build.nvr) promoted_builds = dict(self.tag_pkg_args) if not dry_run: promoted_builds = self.watch_builds(tasks) if regen: print "--- Regenerating repos" self.kojihelper.regen_repos( tags_to_regen=self.tag_pkg_args.keys()) return promoted_builds
def main(argv=None): if argv is None: argv = sys.argv kojihelper = KojiHelper(False) valid_routes = load_routes(INIFILE) options, pkgs_or_builds = parse_cmdline_args(kojihelper.get_all_dvers(), valid_routes, argv) routenames = options.routes route_dvers_pairs = _get_route_dvers_pairs(routenames, valid_routes, options.extra_dvers, options.no_dvers, options.only_dver) if not options.dry_run: kojihelper.login_to_koji() for route, dvers in route_dvers_pairs: printf("Promoting from %s to %s for dvers: %s", route.from_tag_hint % 'el*', route.to_tag_hint % 'el*', ", ".join(sorted(dvers))) printf("Examining the following packages/builds:\n%s", "\n".join(["'" + x + "'" for x in pkgs_or_builds])) dvers = set() for _, x in route_dvers_pairs: dvers.update(x) promoter = Promoter(kojihelper, route_dvers_pairs) for pkgb in pkgs_or_builds: promoter.add_promotion(pkgb, options.ignore_rejects) if promoter.rejects: print "Rejected package or builds:\n" + "\n".join( [str(x) for x in promoter.rejects]) print "Rejects will not be promoted! Rerun with --ignore-rejects to promote them anyway." print "Promotion plan:" if any(promoter.tag_pkg_args.values()): text_args = {} for tag, builds in promoter.tag_pkg_args.items(): text_args[tag] = [x.nvr for x in builds] print_table(text_args) else: printf("Nothing will be promoted!") return 1 question = "Proceed with promoting the builds?" try: proceed = (options.assume_yes or not sys.stdin.isatty() or utils.ask_yn(question)) except KeyboardInterrupt: printf("Canceled.") return 3 if proceed: promoted_builds = promoter.do_promotions(options.dry_run, options.regen) if not options.dry_run: printf("\nJIRA code for this set of promotions:\n") write_jira(kojihelper, promoted_builds, [x[0] for x in route_dvers_pairs]) else: printf("Not proceeding.") return 1 return 0
def _print_route_dvers(routename, route): printf("The default dver(s) for %s are: %s", routename, ", ".join(route.dvers)) if route.extra_dvers: printf("The route optionally supports these dver(s): %s", ", ".join(route.extra_dvers))