From 41f4b43f2c6f2c864b2d15b879e446a41331e7c7 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 30 Sep 2018 09:47:44 +0000 Subject: [PATCH] excuse.p: Refactor some duplicated code Signed-off-by: Niels Thykier --- britney2/excuse.py | 47 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/britney2/excuse.py b/britney2/excuse.py index 36dd32d..5e36c6e 100644 --- a/britney2/excuse.py +++ b/britney2/excuse.py @@ -208,6 +208,21 @@ class Excuse(object): return VERDICT2DESC[verdict] return "UNKNOWN: Missing description for {0} - Please file a bug against Britney".format(verdict.name) + def _render_dep_issue(self, dep_issues, invalid_deps, field): + lastdep = "" + res = [] + for x in sorted(dep_issues, key=lambda x: x.split('/')[0]): + dep = x.split('/')[0] + if dep == lastdep: + continue + lastdep = dep + if x in invalid_deps: + res.append("
  • %s: %s %s (not considered)\n" % (field, self.name, dep, dep)) + else: + res.append("
  • %s: %s %s\n" % (field, self.name, dep, dep)) + + return "".join(res) + def html(self): """Render the excuse in HTML""" res = "%s (%s to %s)\n
      \n" % \ @@ -228,38 +243,14 @@ class Excuse(object): (self.daysold, self.mindays)) for x in self.htmlline: res = res + "
    • " + x + "\n" - lastdep = "" - for x in sorted(self.deps, key=lambda x: x.split('/')[0]): - dep = x.split('/')[0] - if dep == lastdep: continue - lastdep = dep - if x in self.invalid_deps: - res = res + "
    • Depends: %s %s (not considered)\n" % (self.name, dep, dep) - else: - res = res + "
    • Depends: %s %s\n" % (self.name, dep, dep) + res += self._render_dep_issue(self.deps, self.invalid_deps, 'Depends') + for (n,a) in self.break_deps: if n not in self.deps: res += "
    • Ignoring %s depends: %s\n" % (a, n, n) - lastdep = "" - for x in sorted(self.arch_build_deps, key=lambda x: x.split('/')[0]): - dep = x.split('/')[0] - if dep == lastdep: - continue - lastdep = dep - if x in self.invalid_build_deps: - res = res + "
    • Build-Depends(-Arch): %s %s (not ready)\n" % (self.name, dep, dep) - else: - res = res + "
    • Build-Depends(-Arch): %s %s\n" % (self.name, dep, dep) - for x in sorted(self.indep_build_deps, key=lambda x: x.split('/')[0]): - dep = x.split('/')[0] - if dep == lastdep: - continue - lastdep = dep - if x in self.invalid_build_deps: - res = res + "
    • Build-Depends-Indep: %s %s (not ready)\n" % (self.name, dep, dep) - else: - res = res + "
    • Build-Depends-Indep: %s %s\n" % (self.name, dep, dep) + res += self._render_dep_issue(self.arch_build_deps, self.invalid_build_deps, 'Build-Depends(-Arch)') + res += self._render_dep_issue(self.indep_build_deps, self.invalid_build_deps, 'Build-Depends-Indep') res = res + "
    \n" return res