From abe47cb981a63e4f04852298443255861409c97f Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Thu, 12 Aug 2021 10:49:50 +0100 Subject: [PATCH] ci/listmachines: add helper to list machines in a layer Instead of duplicating this logic, put it in a little helper module. Change-Id: I2ca881c8de7e6ec6d4a940255d9ba97226e78d87 Signed-off-by: Ross Burton Signed-off-by: Jon Mason --- ci/listmachines.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 ci/listmachines.py diff --git a/ci/listmachines.py b/ci/listmachines.py new file mode 100755 index 00000000..04d207e4 --- /dev/null +++ b/ci/listmachines.py @@ -0,0 +1,29 @@ +#! /usr/bin/env python3 + +import pathlib +import typing +import sys + +""" +List all of the machines available under the listed sub-layers of meta-arm. +""" +def list_machines(layers: typing.Sequence[str]) -> typing.Set[str]: + machines = set() + + # We know we're in meta-arm/scripts, so find the top-level directory + metaarm = pathlib.Path(__file__).resolve().parent.parent + if metaarm.name != "meta-arm": + raise Exception("Not running inside meta-arm") + + for layer in layers: + machines |= set(p.stem for p in (metaarm / layer / "conf" / "machine").glob("*.conf")) + return machines + +if __name__ == "__main__": + if len(sys.argv) > 1: + machines = list_machines(sys.argv[1:]) + print(" ".join(sorted(machines))) + sys.exit(0) + else: + print("Usage:\n$ %s [layer name ...] " % sys.argv[0]) + sys.exit(1)