mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-23 17:34:21 +03:00
xmlbuilder: Drop is_tri property
It's a minor variation of is_bool which is better understood by using defaults.
This commit is contained in:
parent
7a369a9802
commit
170595698e
@ -27,9 +27,15 @@ class DomainFeatures(XMLBuilder):
|
|||||||
_XML_ROOT_XPATH = "/domain/features"
|
_XML_ROOT_XPATH = "/domain/features"
|
||||||
_XML_PROP_ORDER = ["acpi", "apic", "pae"]
|
_XML_PROP_ORDER = ["acpi", "apic", "pae"]
|
||||||
|
|
||||||
acpi = XMLProperty(xpath="./features/acpi", is_tri=True)
|
acpi = XMLProperty(xpath="./features/acpi", is_bool=True,
|
||||||
apic = XMLProperty(xpath="./features/apic", is_tri=True)
|
default_name="default",
|
||||||
pae = XMLProperty(xpath="./features/pae", is_tri=True)
|
default_cb=lambda s: False)
|
||||||
|
apic = XMLProperty(xpath="./features/apic", is_bool=True,
|
||||||
|
default_name="default",
|
||||||
|
default_cb=lambda s: False)
|
||||||
|
pae = XMLProperty(xpath="./features/pae", is_bool=True,
|
||||||
|
default_name="default",
|
||||||
|
default_cb=lambda s: False)
|
||||||
|
|
||||||
def __setitem__(self, attr, val):
|
def __setitem__(self, attr, val):
|
||||||
return setattr(self, attr, bool(val))
|
return setattr(self, attr, bool(val))
|
||||||
|
@ -942,11 +942,11 @@ class Guest(XMLBuilder):
|
|||||||
if not self.os.is_hvm():
|
if not self.os.is_hvm():
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.features["acpi"] is None:
|
if self.features["acpi"] == "default":
|
||||||
self.features["acpi"] = self._lookup_osdict_key("acpi")
|
self.features["acpi"] = self._lookup_osdict_key("acpi")
|
||||||
if self.features["apic"] is None:
|
if self.features["apic"] == "default":
|
||||||
self.features["apic"] = self._lookup_osdict_key("apic")
|
self.features["apic"] = self._lookup_osdict_key("apic")
|
||||||
if self.features["pae"] is None:
|
if self.features["pae"] == "default":
|
||||||
self.features["pae"] = self.conn.caps.support_pae()
|
self.features["pae"] = self.conn.caps.support_pae()
|
||||||
|
|
||||||
def _set_device_defaults(self):
|
def _set_device_defaults(self):
|
||||||
|
@ -242,7 +242,7 @@ class XMLProperty(property):
|
|||||||
def __init__(self, doc=None, xpath=None, name=None,
|
def __init__(self, doc=None, xpath=None, name=None,
|
||||||
set_converter=None, validate_cb=None,
|
set_converter=None, validate_cb=None,
|
||||||
make_getter_xpath_cb=None, make_setter_xpath_cb=None,
|
make_getter_xpath_cb=None, make_setter_xpath_cb=None,
|
||||||
is_bool=False, is_tri=False, is_int=False, is_yesno=False,
|
is_bool=False, is_int=False, is_yesno=False,
|
||||||
clear_first=None, default_cb=None, default_name=None):
|
clear_first=None, default_cb=None, default_name=None):
|
||||||
"""
|
"""
|
||||||
Set a XMLBuilder class property that represents a value in the
|
Set a XMLBuilder class property that represents a value in the
|
||||||
@ -272,8 +272,6 @@ class XMLProperty(property):
|
|||||||
static xpath. This allows passing functions which generate
|
static xpath. This allows passing functions which generate
|
||||||
an xpath for getting or setting.
|
an xpath for getting or setting.
|
||||||
@param is_bool: Whether this is a boolean property in the XML
|
@param is_bool: Whether this is a boolean property in the XML
|
||||||
@param is_tri: Boolean XML property, but return None if there's
|
|
||||||
no value set.
|
|
||||||
@param is_int: Whethere this is an integer property in the XML
|
@param is_int: Whethere this is an integer property in the XML
|
||||||
@param is_yesno: Whethere this is a yes/no property in the XML
|
@param is_yesno: Whethere this is a yes/no property in the XML
|
||||||
@param clear_first: List of xpaths to unset before any 'set' operation.
|
@param clear_first: List of xpaths to unset before any 'set' operation.
|
||||||
@ -292,8 +290,7 @@ class XMLProperty(property):
|
|||||||
if not self._name:
|
if not self._name:
|
||||||
raise RuntimeError("XMLProperty: name or xpath must be passed.")
|
raise RuntimeError("XMLProperty: name or xpath must be passed.")
|
||||||
|
|
||||||
self._is_tri = is_tri
|
self._is_bool = is_bool
|
||||||
self._is_bool = is_bool or is_tri
|
|
||||||
self._is_int = is_int
|
self._is_int = is_int
|
||||||
self._is_yesno = is_yesno
|
self._is_yesno = is_yesno
|
||||||
|
|
||||||
@ -395,12 +392,11 @@ class XMLProperty(property):
|
|||||||
return clear_nodes
|
return clear_nodes
|
||||||
|
|
||||||
|
|
||||||
def _convert_get_value(self, val, initial=False):
|
def _convert_get_value(self, val):
|
||||||
if self._is_bool:
|
if self._default_name and val == self._default_name:
|
||||||
if initial and self._is_tri and val is None:
|
ret = val
|
||||||
ret = None
|
elif self._is_bool:
|
||||||
else:
|
ret = bool(val)
|
||||||
ret = bool(val)
|
|
||||||
elif self._is_int and val is not None:
|
elif self._is_int and val is not None:
|
||||||
intkwargs = {}
|
intkwargs = {}
|
||||||
if "0x" in str(val):
|
if "0x" in str(val):
|
||||||
@ -477,7 +473,7 @@ class XMLProperty(property):
|
|||||||
def getter(self, xmlbuilder):
|
def getter(self, xmlbuilder):
|
||||||
if xmlbuilder._xml_ctx is None:
|
if xmlbuilder._xml_ctx is None:
|
||||||
fgetval = self._nonxml_fget(xmlbuilder)
|
fgetval = self._nonxml_fget(xmlbuilder)
|
||||||
return self._convert_get_value(fgetval, initial=True)
|
return self._convert_get_value(fgetval)
|
||||||
|
|
||||||
xpath = self._xpath_for_getter(xmlbuilder)
|
xpath = self._xpath_for_getter(xmlbuilder)
|
||||||
node = _get_xpath_node(xmlbuilder._xml_ctx, xpath)
|
node = _get_xpath_node(xmlbuilder._xml_ctx, xpath)
|
||||||
|
Loading…
Reference in New Issue
Block a user