Introduce set_prop helper function. It will be used in the next patch.

Signed-off-by: Marc Hartmayer <[email protected]>
Reviewed-by: Boris Fiuczynski <[email protected]>
---
 virtinst/xmlapi.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/virtinst/xmlapi.py b/virtinst/xmlapi.py
index 569e47f7498d..49ca0fa395cb 100644
--- a/virtinst/xmlapi.py
+++ b/virtinst/xmlapi.py
@@ -27,6 +27,22 @@ def get_prop(obj, prop_path):
     return getattr(parent, pieces[-1])
 
 
+def set_prop(obj, prop_path, value):
+    """Set value of attribute identified by `prop_path`
+
+    Set the attribute of `obj` identified by `prop_path` (separated by
+    ".") to `value`. If any component along the path is missing an
+    `AttributeError` is raised.
+
+    """
+    parent = obj
+    pieces = prop_path.split(".")
+    for piece in pieces[:-1]:
+        parent = getattr(parent, piece)
+
+    return setattr(parent, pieces[-1], value)
+
+
 class _XPathSegment(object):
     """
     Class representing a single 'segment' of an xpath string. For example,
-- 
2.17.0

_______________________________________________
virt-tools-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-tools-list

Reply via email to