layer-overview.py 1.8 KB

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