From 2c19cccd4bf0c5ef72aa0b1bd3f1c9c626fc8bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Mon, 19 Oct 2020 21:42:53 -0700 Subject: [PATCH] scripts: edtlib: bindings_from_paths() helper function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a convenience function for creating a bunch of Binding objects from files in a directory. Signed-off-by: Martí Bolívar --- scripts/dts/edtlib.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/dts/edtlib.py b/scripts/dts/edtlib.py index 6d532cde092..ce461bef28e 100644 --- a/scripts/dts/edtlib.py +++ b/scripts/dts/edtlib.py @@ -21,7 +21,8 @@ Each devicetree node (dtlib.Node) gets a corresponding edtlib.Node instance, which has all the information related to the node. The top-level entry points for the library are the EDT and Binding classes. -See their constructor docstrings for details. +See their constructor docstrings for details. There is also a +bindings_from_paths() helper function. """ # NOTE: testedtlib.py is the test suite for this library. @@ -1702,6 +1703,26 @@ class Binding: raise _err("can't _warn() outside of Binding.__init__") +def bindings_from_paths(yaml_paths, ignore_errors=False): + """ + Get a list of Binding objects from the yaml files 'yaml_paths'. + + If 'ignore_errors' is True, YAML files that cause an EDTError when + loaded are ignored. (No other exception types are silenced.) + """ + + ret = [] + fname2path = {os.path.basename(path): path for path in yaml_paths} + for path in yaml_paths: + try: + ret.append(Binding(path, fname2path)) + except EDTError: + if ignore_errors: + continue + raise + + return ret + class PropertySpec: """ Represents a "property specification", i.e. the description of a