Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame^] | 1 | #! /usr/bin/env python3 |
| 2 | |
| 3 | """ |
| 4 | Print an overview of the layer to help writing release notes. |
| 5 | |
| 6 | Output includes sublayers, machines, recipes. |
| 7 | """ |
| 8 | |
| 9 | import argparse |
| 10 | import sys |
| 11 | |
| 12 | # TODO: |
| 13 | # - More human-readable output |
| 14 | # - Diff mode, give two revisions and list the changes |
| 15 | |
| 16 | def 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 | |
| 23 | def 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 | |
| 48 | parser = argparse.ArgumentParser() |
| 49 | parser.add_argument("repository") |
| 50 | parser.add_argument("revision", nargs="?") |
| 51 | args = parser.parse_args() |
| 52 | |
| 53 | if args.revision: |
| 54 | import gitpathlib |
| 55 | base = gitpathlib.GitPath(args.repository, args.revision) |
| 56 | else: |
| 57 | import pathlib |
| 58 | base = pathlib.Path(args.repository) |
| 59 | |
| 60 | if is_layer(base): |
| 61 | print_layer(base) |
| 62 | else: |
| 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) |