repos: Add RecursiveBuildReport missing_rating
The plan is to split the recursive_build_report into more structured and easy-to-operate pieces. The first part of those pieces is introduction of a separate class that walks the dependency trees to build a closure of build requirements for a given package. To show what's already possible with it, we add new report, missing_rating_report, that shows the most wanted of packages that are missing from a given repository.
This commit is contained in:
parent
ad19973427
commit
bbf24803fa
@ -363,8 +363,8 @@ class TripletReport:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __bool__(self):
|
def sources_set(self):
|
||||||
return len(self.triplets) > 0
|
return set(p.source_name for k, d, p in self.triplets)
|
||||||
|
|
||||||
def basic_format(self, title=None, to=None):
|
def basic_format(self, title=None, to=None):
|
||||||
"""Format a report
|
"""Format a report
|
||||||
@ -517,6 +517,75 @@ def _src_name(source):
|
|||||||
return source
|
return source
|
||||||
|
|
||||||
|
|
||||||
|
class RecursiveBuildReport:
|
||||||
|
def __init__(self, from_repo, to_repo, source_names,
|
||||||
|
stop_names=(), prefer=()):
|
||||||
|
self.from_repo = from_repo
|
||||||
|
self.to_repo = to_repo
|
||||||
|
self.stop_names = frozenset(stop_names)
|
||||||
|
self.prefer = prefer
|
||||||
|
self.requested_names = [_src_name(s) for s in source_names]
|
||||||
|
self.reported_names = self._closure()
|
||||||
|
|
||||||
|
def _build_report(self, name):
|
||||||
|
return build_report(self.from_repo, self.to_repo, name,
|
||||||
|
prefer=self.prefer)
|
||||||
|
|
||||||
|
def _closure(self):
|
||||||
|
seen = list(self.requested_names)
|
||||||
|
queue = list(self.requested_names)
|
||||||
|
while queue:
|
||||||
|
cur = queue.pop()
|
||||||
|
missing = self._build_report(cur).sources_set()
|
||||||
|
unseen = missing.difference(seen)
|
||||||
|
seen.extend(unseen)
|
||||||
|
# don't recur into packages from stop_names
|
||||||
|
queue.extend(unseen - self.stop_names)
|
||||||
|
return seen
|
||||||
|
|
||||||
|
def format_build_reports(self, to=None):
|
||||||
|
result = []
|
||||||
|
for name in self.reported_names:
|
||||||
|
result.append(f"\n== {name.decode()} ==")
|
||||||
|
|
||||||
|
in_to = self.to_repo.sources.get(name)
|
||||||
|
srpm = in_to.source_rpm.decode() if in_to else 'NONE'
|
||||||
|
result.append(f"{self.to_repo.name} has {srpm}\n")
|
||||||
|
|
||||||
|
if name in self.stop_names:
|
||||||
|
result.append('not going deeper (stop_names)')
|
||||||
|
else:
|
||||||
|
result.append(self._build_report(name).basic_format().strip())
|
||||||
|
return to('\n'.join(result)) if to else '\n'.join(result)
|
||||||
|
|
||||||
|
|
||||||
|
def missing_rating(from_repo, to_repo):
|
||||||
|
result = collections.defaultdict(set)
|
||||||
|
for name in from_repo.sources:
|
||||||
|
if name in to_repo.sources or b'gost' in name:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
rbr = RecursiveBuildReport(from_repo, to_repo, [name])
|
||||||
|
except Exception:
|
||||||
|
LOG.error("Failed to build recursive build report"
|
||||||
|
"for %s", name.decode(), exc_info=True)
|
||||||
|
else:
|
||||||
|
for other_name in rbr.reported_names:
|
||||||
|
if other_name != name:
|
||||||
|
result[other_name].add(name)
|
||||||
|
return sorted(result.items(), key=lambda x: (len(x[1]), x[0]))
|
||||||
|
|
||||||
|
|
||||||
|
def missing_rating_report(from_repo, to_repo):
|
||||||
|
rr = list(reversed(missing_rating(from_repo, to_repo)))
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
def recursive_build_report(from_repo, to_repo, *source_names,
|
def recursive_build_report(from_repo, to_repo, *source_names,
|
||||||
ignore=(), ignore_sort=(), summary=True):
|
ignore=(), ignore_sort=(), summary=True):
|
||||||
reports = []
|
reports = []
|
||||||
|
Loading…
Reference in New Issue
Block a user