summaryrefslogtreecommitdiff
path: root/buildstream/_yaml.py
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-05 22:17:32 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-05 22:17:32 +0900
commit4f3a71f898ad550e98c1e74f96ffa1fd145c9980 (patch)
tree99e29180de06914cb713e9af9dfd723c584a7fc7 /buildstream/_yaml.py
parentc8c5516c7f426b17cfc5c7ba4f29c09a0ba13d73 (diff)
downloadbuildstream-4f3a71f898ad550e98c1e74f96ffa1fd145c9980.tar.gz
Diffstat (limited to 'buildstream/_yaml.py')
-rw-r--r--buildstream/_yaml.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 93fae4903..c8151d501 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -602,3 +602,33 @@ def list_chain_copy(source):
copy.append(item)
return copy
+
+
+def node_copy(source):
+ copy = {}
+ for key, value in source.items():
+ if isinstance(value, collections.Mapping):
+ copy[key] = node_copy(value)
+ elif isinstance(value, list):
+ copy[key] = list_copy(value)
+ elif isinstance(value, Provenance):
+ copy[key] = value.clone()
+
+ ensure_provenance(copy)
+
+ return copy
+
+
+def list_copy(source):
+ copy = []
+ for item in source:
+ if isinstance(item, collections.Mapping):
+ copy.append(node_copy(item))
+ elif isinstance(item, list):
+ copy.append(list_copy(item))
+ elif isinstance(item, Provenance):
+ copy.append(item.clone())
+ else:
+ copy.append(item)
+
+ return copy