mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
xmlapi: add set_prop
Introduce set_prop helper function. It will be used in the next patch. Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
This commit is contained in:
parent
adf30349c3
commit
60c7e778e3
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user