xmlbuilder: Kill make_xpath_cb

There's no users left, and it's better to come up with a solution at
the caller anyways
This commit is contained in:
Cole Robinson 2015-09-05 17:20:43 -04:00
parent 9e23843961
commit d449fb6fd5
3 changed files with 22 additions and 35 deletions

View File

@ -191,12 +191,11 @@ class _VirtualCharDevice(VirtualDevice):
"_source_path", "source_channel", "_source_path", "source_channel",
"target_type", "target_name"] "target_type", "target_name"]
type = XMLProperty( type = XMLProperty("./@type",
doc=_("Method used to expose character device in the host."), doc=_("Method used to expose character device in the host."))
xpath="./@type")
_tty = XMLProperty("./@tty") _tty = XMLProperty("./@tty")
_source_path = XMLProperty(xpath="./source/@path", _source_path = XMLProperty("./source/@path",
doc=_("Host input path to attach to the guest.")) doc=_("Host input path to attach to the guest."))
def _get_source_path(self): def _get_source_path(self):
@ -208,7 +207,7 @@ class _VirtualCharDevice(VirtualDevice):
self._source_path = val self._source_path = val
source_path = property(_get_source_path, _set_source_path) source_path = property(_get_source_path, _set_source_path)
source_channel = XMLProperty(xpath="./source/@channel", source_channel = XMLProperty("./source/@channel",
doc=_("Source channel name.")) doc=_("Source channel name."))

View File

@ -98,25 +98,24 @@ class VirtualRNGDevice(VirtualDevice):
self._has_mode_bind = VirtualRNGDevice.BACKEND_MODE_BIND self._has_mode_bind = VirtualRNGDevice.BACKEND_MODE_BIND
return val return val
type = XMLProperty(xpath="./backend/@model") type = XMLProperty("./backend/@model")
model = XMLProperty(xpath="./@model", model = XMLProperty("./@model", default_cb=lambda s: "virtio")
default_cb=lambda s: "virtio")
backend_type = XMLProperty(xpath="./backend/@type") backend_type = XMLProperty("./backend/@type")
bind_host = XMLProperty(xpath="./backend/source[@mode='bind']/@host", bind_host = XMLProperty("./backend/source[@mode='bind']/@host",
set_converter=_set_bind_validate) set_converter=_set_bind_validate)
bind_service = XMLProperty(xpath="./backend/source[@mode='bind']/@service", bind_service = XMLProperty("./backend/source[@mode='bind']/@service",
set_converter=_set_bind_validate) set_converter=_set_bind_validate)
connect_host = XMLProperty(xpath="./backend/source[@mode='connect']/@host", connect_host = XMLProperty("./backend/source[@mode='connect']/@host",
set_converter=_set_connect_validate) set_converter=_set_connect_validate)
connect_service = XMLProperty(set_converter=_set_connect_validate, connect_service = XMLProperty("./backend/source[@mode='connect']/@service",
xpath="./backend/source[@mode='connect']/@service") set_converter=_set_connect_validate)
rate_bytes = XMLProperty(xpath="./rate/@bytes") rate_bytes = XMLProperty("./rate/@bytes")
rate_period = XMLProperty(xpath="./rate/@period") rate_period = XMLProperty("./rate/@period")
device = XMLProperty(xpath="./backend") device = XMLProperty("./backend")
VirtualRNGDevice.register_type() VirtualRNGDevice.register_type()

View File

@ -332,8 +332,8 @@ class XMLChildProperty(property):
class XMLProperty(property): class XMLProperty(property):
def __init__(self, xpath=None, name=None, doc=None, def __init__(self, xpath, doc=None,
set_converter=None, validate_cb=None, make_xpath_cb=None, set_converter=None, validate_cb=None,
is_bool=False, is_int=False, is_yesno=False, is_onoff=False, is_bool=False, is_int=False, is_yesno=False, is_onoff=False,
default_cb=None, default_name=None, do_abspath=False): default_cb=None, default_name=None, do_abspath=False):
""" """
@ -359,9 +359,6 @@ class XMLProperty(property):
operation we convert the XML value with int(val) / 1024. operation we convert the XML value with int(val) / 1024.
@param validate_cb: Called once when value is set, should @param validate_cb: Called once when value is set, should
raise a RuntimeError if the value is not proper. raise a RuntimeError if the value is not proper.
@param make_xpath_cb: Not all props map cleanly to a
static xpath. This allows passing functions which generate
an xpath.
@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_int: Whether this is an integer property in the XML @param is_int: Whether this is an integer property in the XML
@param is_yesno: Whether this is a yes/no property in the XML @param is_yesno: Whether this is a yes/no property in the XML
@ -374,11 +371,9 @@ class XMLProperty(property):
value, instead use the value of default_cb() value, instead use the value of default_cb()
@param do_abspath: If True, run os.path.abspath on the passed value @param do_abspath: If True, run os.path.abspath on the passed value
""" """
self._xpath = xpath self._xpath = xpath
self._name = name or xpath if not self._xpath:
if not self._name: raise RuntimeError("XMLProperty: xpath must be passed.")
raise RuntimeError("XMLProperty: name or xpath must be passed.")
self._propname = None self._propname = None
self._is_bool = is_bool self._is_bool = is_bool
@ -387,7 +382,6 @@ class XMLProperty(property):
self._is_onoff = is_onoff self._is_onoff = is_onoff
self._do_abspath = do_abspath self._do_abspath = do_abspath
self._make_xpath_cb = make_xpath_cb
self._validate_cb = validate_cb self._validate_cb = validate_cb
self._convert_value_for_setter_cb = set_converter self._convert_value_for_setter_cb = set_converter
self._default_cb = default_cb self._default_cb = default_cb
@ -410,7 +404,7 @@ class XMLProperty(property):
def __repr__(self): def __repr__(self):
return "<XMLProperty %s %s>" % (str(self._name), id(self)) return "<XMLProperty %s %s>" % (str(self._xpath), id(self))
#################### ####################
@ -432,12 +426,7 @@ class XMLProperty(property):
return self._propname return self._propname
def _make_xpath(self, xmlbuilder): def _make_xpath(self, xmlbuilder):
ret = self._xpath return xmlbuilder.fix_relative_xpath(self._xpath)
if self._make_xpath_cb:
ret = self._make_xpath_cb(xmlbuilder)
if ret is None:
raise RuntimeError("%s: didn't generate any xpath." % self)
return xmlbuilder.fix_relative_xpath(ret)
def _build_node_list(self, xmlbuilder, xpath): def _build_node_list(self, xmlbuilder, xpath):