From e2f1051f7d0924bf6a2fa7e405fd36bffaeeef1a Mon Sep 17 00:00:00 2001 From: "Ivan A. Melnikov" Date: Fri, 20 Dec 2024 13:06:41 +0400 Subject: [PATCH] repos: Rewrite missing_rating in terms of BuildReporter --- repos_cmp/repos.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/repos_cmp/repos.py b/repos_cmp/repos.py index e083214..f361134 100644 --- a/repos_cmp/repos.py +++ b/repos_cmp/repos.py @@ -576,32 +576,35 @@ class BuildReporter: return to('\n'.join(result)) if to else '\n'.join(result) -def missing_rating(from_repo, to_repo): +def missing_rating(build_reporter, ignore=None): result = collections.defaultdict(set) - reporter = BuildReporter(from_repo, to_repo) - for name in from_repo.sources: - if name in to_repo.sources or b'gost' in name: - continue + ignore = re.compile(ignore).search if ignore else lambda x: False + + sources = (s for s in build_reporter.from_repo.sources + if s not in build_reporter.to_repo.sources + and b'gost' not in s + and not s.startswith(b'kernel-') + and not ignore(s)) + for name in sources: try: - rbr = reporter.recursive_closure([name]) + rbr = build_reporter.recursive_closure([name]) except Exception: LOG.error("Failed to build recursive build report " "for %s", name.decode(), exc_info=True) else: for other_name in rbr: - if other_name != name: + if other_name != name and not ignore(name): result[other_name].add(name) - return sorted(result.items(), key=lambda x: (len(x[1]), x[0])) + return dict(result) -def missing_rating_report(from_repo, to_repo): - rr = list(reversed(missing_rating(from_repo, to_repo))) +def format_missing_rating(rating, to=None): + rr = sorted(rating.items(), key=lambda x: (-len(x[1]), x[0])) result = [] for name, where in rr: - present = '+' if name in to_repo.sources else '' - result.append(f"{name.decode()} {present}: {len(where)}") - result.append(" " + b' '.join(where).decode()) - return '\n'.join(result) + result.append(f"{name.decode()}: {len(where)}") + result.append(" " + b' '.join(sorted(where)).decode()) + return to('\n'.join(result)) if to else '\n'.join(result) def recursive_build_report(from_repo, to_repo, *source_names,