[1/6] scripts/layer-overview: improve layer detection

Message ID 20220119212050.1886613-1-ross.burton@arm.com
State New
Headers show
Series [1/6] scripts/layer-overview: improve layer detection | expand

Commit Message

Ross Burton Jan. 19, 2022, 9:20 p.m. UTC
Refactor the script somewhat, and detect whether the starting directory
is a single layer, or a collection of layers.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 scripts/layer-overview.py | 60 ++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 19 deletions(-)

Comments

Jon Mason Jan. 20, 2022, 3:50 a.m. UTC | #1
On Wed, 19 Jan 2022 21:20:45 +0000, Ross Burton wrote:
> Refactor the script somewhat, and detect whether the starting directory
> is a single layer, or a collection of layers.

Applied, thanks!

[1/6] scripts/layer-overview: improve layer detection
      commit: 02350369574cdcea2091048a04468ee515c7d711
[2/6] scripts/machine-summary: harvest more patch data
      commit: cb29175ab4c9a68e26b66aceb97463b32b3639c9
[3/6] scripts/machine-summary: refactor output to classes
      commit: 0d2d0fd69102cadb4e699fa41402227f60e56b69
[4/6] scripts/machine-summary: put more version information into the context
      commit: b1b0f37da7f4c670216de4225af024560e97248e
[5/6] scripts/machine-summary: write per-machine reports with more details
      commit: c4b34740cfc78485d22453d9bc284adc12216dcd
[6/6] CI: update for changes to machine-summary
      commit: aaac0541658b6d6e655662d53dcd27e5cd1bf018

Best regards,

Patch

diff --git a/scripts/layer-overview.py b/scripts/layer-overview.py
index 24a9a5b6..326470e6 100755
--- a/scripts/layer-overview.py
+++ b/scripts/layer-overview.py
@@ -6,31 +6,24 @@  Print an overview of the layer to help writing release notes.
 Output includes sublayers, machines, recipes.
 """
 
+import argparse
+import sys
+
 # TODO:
 # - More human-readable output
 # - Diff mode, give two revisions and list the changes
-# - Support finding no sublayers, meaning the path is a single layer
-
-import argparse
-parser = argparse.ArgumentParser()
-parser.add_argument("repository")
-parser.add_argument("revision", nargs="?")
-args = parser.parse_args()
 
-if args.revision:
-    import gitpathlib
-    base = gitpathlib.GitPath(args.repository, args.revision)
-else:
-    import pathlib
-    base = pathlib.Path(args.repository)
+def is_layer(path):
+    """
+    Determine if this path looks like a layer (is a directory and contains conf/layer.conf).
+    """
+    return path.is_dir() and (path / "conf" / "layer.conf").exists()
 
-print("Sub-Layers")
-sublayers = sorted(p for p in base.glob("meta-*") if p.is_dir())
-for l in sublayers:
-    print(f" {l.name}")
-print()
 
-for layer in sublayers:
+def print_layer(layer):
+    """
+    Print a summary of the layer.
+    """
     print(layer.name)
 
     machines = sorted(p for p in layer.glob("conf/machine/*.conf"))
@@ -50,3 +43,32 @@  for layer in sublayers:
             else:
                 print(f"  {r.stem}")
         print()
+
+
+parser = argparse.ArgumentParser()
+parser.add_argument("repository")
+parser.add_argument("revision", nargs="?")
+args = parser.parse_args()
+
+if args.revision:
+    import gitpathlib
+    base = gitpathlib.GitPath(args.repository, args.revision)
+else:
+    import pathlib
+    base = pathlib.Path(args.repository)
+
+if is_layer(base):
+    print_layer(base)
+else:
+    sublayers = sorted(p for p in base.glob("meta-*") if is_layer(p))
+    if sublayers:
+        print("Sub-Layers")
+        for l in sublayers:
+            print(f" {l.name}")
+        print()
+
+        for layer in sublayers:
+            print_layer(layer)
+    else:
+        print(f"No layers found in {base}", file=sys.stderr)
+        sys.exit(1)