Skip to contentSkip to conversation

scripts/machine-summary: remove obsolete is_old test

PATCH New Ross Burton 1 participant 4 messages Jan 25, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 scripts/machine-summary: remove obsolete is_old test

This test isn't used any more, so remove it.

---
 scripts/machine-summary.py | 6 ------
 1 file changed, 6 deletions(-)
scripts/machine-summary.py +0 -6
index 1f98f247..5e66cc1b 100755
@@ -154,12 +154,6 @@ class Format:
             trim_blocks=True,
             lstrip_blocks=True
         )
-        def is_old(version, upstream):
-            if "+git" in version:
-                # strip +git and see if this is a post-release snapshot
-                version = version.replace("+git", "")
-            return version != upstream
-        env.tests["old"] = is_old
 
         return env.get_template(name)
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/4 scripts/machine-summary: don't mark denied patches as good

A patch in denied state isn't good, it's bad.

---
 scripts/report-details.html.jinja | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/report-details.html.jinja +2 -2
index ba66fcf0..19ede510 100644
@@ -6,9 +6,9 @@
   {% set status = status.split()[0] %}
   {% if status in ("Unknown", "Pending") %}
     {% set class = "is-danger" %}
-  {% elif status in ("Backport", "Accepted", "Inappropriate") %}
+  {% elif status in ("Backport", "Accepted", "Inappropriate", "Denied") %}
     {% set class = "is-success" %}
-  {% elif status in ("Submitted", "Denied") %}
+  {% elif status in ("Submitted",) %}
     {% set class = "is-info" %}
   {% else %}
     {% set class = "is-info" %}
Signature · 1 line
2.25.1
#2 lore raw

PATCH 3/4 scripts/machine-summary: remove default Format.render()

In reply to Ross Burton

There's no shared code anymore, so move the code to TextOverview.

---
 scripts/machine-summary.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
scripts/machine-summary.py +5 -3
index 5e66cc1b..0849c579 100755
@@ -142,9 +142,7 @@ class Format:
         return cls.registry[name]()
 
     def render(self, context, output: pathlib.Path):
-        # Default implementation for convenience
-        with open(output, "wt") as f:
-            f.write(self.get_template(f"machine-summary-{self.name}.jinja").render(context))
+        pass
 
     def get_template(self, name):
         template_dir = os.path.dirname(os.path.abspath(__file__))
@@ -160,6 +158,10 @@ class Format:
 class TextOverview(Format):
     name = "overview.txt"
 
+    def render(self, context, output: pathlib.Path):
+        with open(output, "wt") as f:
+            f.write(self.get_template(f"machine-summary-overview.txt.jinja").render(context))
+
 class HtmlUpdates(Format):
     name = "report"
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH 4/4 scripts/machine-summary: show patch count in the overview

In reply to Ross Burton

Instead of simply adding a tag saying "Patched", include the patch count and make a judgement call on whether the patches are "safe" or not. For example, patches which are entirely backports or inappropriate are "safe", pending and denied patches are not.

---
 scripts/machine-summary.py      | 11 +++++++++++
 scripts/report-index.html.jinja |  8 +++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
scripts/machine-summary.py +11 -0
index 0849c579..4888a007 100755
@@ -24,6 +24,12 @@ def needs_update(version, upstream):
         version = version.replace("+git", "")
     return version != upstream
 
+def safe_patches(patches):
+    for info in patches:
+        if info["status"] in ("Denied", "Pending", "Unknown"):
+            return False
+    return True
+
 def layer_path(layername, d):
     """
     Return the path to the specified layer, or None if the layer isn't present.
@@ -100,6 +106,7 @@ def harvest_data(machines, recipes):
                 details["fullversion"] = d.getVar("PV")
                 details["patches"] = [extract_patch_info(p, d) for p in oe.patch.src_patches(d)]
                 details["patched"] = bool(details["patches"])
+                details["patches_safe"] = safe_patches(details["patches"])
 
     # Now backfill the upstream versions
     for machine in versions:
@@ -148,11 +155,15 @@ class Format:
         template_dir = os.path.dirname(os.path.abspath(__file__))
         env = jinja2.Environment(
             loader=jinja2.FileSystemLoader(template_dir),
+            extensions=['jinja2.ext.i18n'],
             autoescape=jinja2.select_autoescape(),
             trim_blocks=True,
             lstrip_blocks=True
         )
 
+        # We only need i18n for plurals
+        env.install_null_translations()
+
         return env.get_template(name)
 
 class TextOverview(Format):
scripts/report-index.html.jinja +7 -1
index 3e39174f..44537581 100644
@@ -26,7 +26,13 @@
             {% if details.patches or details.needs_update %}
             <br>
             {% if details.patches %}
-              <span class="tag is-info">Patched</span>
+              <span class="tag {{ "is-info" if details.patches_safe else "is-danger" }}">
+                {% trans count=details.patches|length %}
+                  {{ count }} Patch
+                {% pluralize %}
+                  {{ count }} Patches
+                {% endtrans %}
+              </span>
             {% endif %}
             {% if details.needs_update %}
               <span class="tag is-danger">Upgrade</span>
Signature · 1 line
2.25.1