summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-09-22 12:12:48 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-01 18:49:53 +0900
commit83b8128e66e1ddb9f26aa6155dd5903bb3eb29b1 (patch)
tree3655708605db6c91defa48ffeccfc1d7c6377ddb
parent84688b81d650ff803fac88a0af65b473746bd128 (diff)
downloadbuildstream-83b8128e66e1ddb9f26aa6155dd5903bb3eb29b1.tar.gz
_yaml.py: Added node_items() convenience generator
-rw-r--r--buildstream/_yaml.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index aead2ed84..9823f7ca3 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -385,6 +385,25 @@ def node_get(node, expected_type, key, indices=[], default_value=None):
return value
+# node_items()
+#
+# A convenience generator for iterating over loaded key/value
+# tuples in a dictionary loaded from project YAML.
+#
+# Args:
+# node (dict): The dictionary node
+#
+# Yields:
+# (str): The key name
+# (anything): The value for the key
+#
+def node_items(node):
+ for key, value in node.items():
+ if key == PROVENANCE_KEY:
+ continue
+ yield (key, value)
+
+
# Gives a node a dummy provenance, in case of compositing dictionaries
# where the target is an empty {}
def ensure_provenance(node):