mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
cli: refactor get_prop
Refactor get_prop since it will be used in the next patches at other places as well. Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
This commit is contained in:
parent
1856c1fa65
commit
adf30349c3
@ -22,7 +22,7 @@ import libvirt
|
||||
|
||||
from virtcli import CLIConfig
|
||||
|
||||
from . import util
|
||||
from . import util, xmlapi
|
||||
from .devices import (Device, DeviceController, DeviceDisk, DeviceGraphics,
|
||||
DeviceInterface, DevicePanic)
|
||||
from .domain import DomainClock, DomainOs
|
||||
@ -1225,12 +1225,7 @@ class VirtCLIParser(metaclass=InitClass):
|
||||
"""
|
||||
if not cls.propname:
|
||||
return None
|
||||
parent = obj
|
||||
pieces = cls.propname.split(".")
|
||||
for piece in pieces[:-1]:
|
||||
parent = getattr(parent, piece)
|
||||
|
||||
return getattr(parent, pieces[-1])
|
||||
return xmlapi.get_prop(obj, cls.propname)
|
||||
|
||||
@classmethod
|
||||
def prop_is_list(cls, obj):
|
||||
|
@ -11,6 +11,22 @@ from . import util
|
||||
# pylint: disable=protected-access
|
||||
|
||||
|
||||
def get_prop(obj, prop_path):
|
||||
"""Return value of attribute identified by `prop_path`
|
||||
|
||||
Look up the attribute of `obj` identified by `prop_path`
|
||||
(separated by "."). 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 getattr(parent, pieces[-1])
|
||||
|
||||
|
||||
class _XPathSegment(object):
|
||||
"""
|
||||
Class representing a single 'segment' of an xpath string. For example,
|
||||
|
Loading…
Reference in New Issue
Block a user