summaryrefslogtreecommitdiff
path: root/meta-arm/scripts/layer-overview.py
blob: 326470e64b01c56e3fd501fb1556ffdcdbd1219c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python3

"""
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

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()


def print_layer(layer):
    """
    Print a summary of the layer.
    """
    print(layer.name)

    machines = sorted(p for p in layer.glob("conf/machine/*.conf"))
    if machines:
        print(" Machines")
        for m in machines:
            print(f"  {m.stem}")
        print()

    recipes = sorted((p for p in layer.glob("recipes-*/*/*.bb")), key=lambda p:p.name)
    if recipes:
        print(" Recipes")
        for r in recipes:
            if "_" in r.stem:
                pn, pv = r.stem.rsplit("_", 1)
                print(f"  {pn} {pv}")
            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)