blob: 326470e64b01c56e3fd501fb1556ffdcdbd1219c [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001#! /usr/bin/env python3
2
3"""
4Print an overview of the layer to help writing release notes.
5
6Output includes sublayers, machines, recipes.
7"""
8
9import argparse
10import sys
11
12# TODO:
13# - More human-readable output
14# - Diff mode, give two revisions and list the changes
15
16def is_layer(path):
17 """
18 Determine if this path looks like a layer (is a directory and contains conf/layer.conf).
19 """
20 return path.is_dir() and (path / "conf" / "layer.conf").exists()
21
22
23def print_layer(layer):
24 """
25 Print a summary of the layer.
26 """
27 print(layer.name)
28
29 machines = sorted(p for p in layer.glob("conf/machine/*.conf"))
30 if machines:
31 print(" Machines")
32 for m in machines:
33 print(f" {m.stem}")
34 print()
35
36 recipes = sorted((p for p in layer.glob("recipes-*/*/*.bb")), key=lambda p:p.name)
37 if recipes:
38 print(" Recipes")
39 for r in recipes:
40 if "_" in r.stem:
41 pn, pv = r.stem.rsplit("_", 1)
42 print(f" {pn} {pv}")
43 else:
44 print(f" {r.stem}")
45 print()
46
47
48parser = argparse.ArgumentParser()
49parser.add_argument("repository")
50parser.add_argument("revision", nargs="?")
51args = parser.parse_args()
52
53if args.revision:
54 import gitpathlib
55 base = gitpathlib.GitPath(args.repository, args.revision)
56else:
57 import pathlib
58 base = pathlib.Path(args.repository)
59
60if is_layer(base):
61 print_layer(base)
62else:
63 sublayers = sorted(p for p in base.glob("meta-*") if is_layer(p))
64 if sublayers:
65 print("Sub-Layers")
66 for l in sublayers:
67 print(f" {l.name}")
68 print()
69
70 for layer in sublayers:
71 print_layer(layer)
72 else:
73 print(f"No layers found in {base}", file=sys.stderr)
74 sys.exit(1)