xmlbuilder: Move xml_indent to util

This commit is contained in:
Cole Robinson 2018-03-20 10:35:22 -04:00
parent 3d34f6a231
commit 93c22eff79
3 changed files with 14 additions and 16 deletions

View File

@ -176,7 +176,7 @@ class StoragePool(_StorageObject):
source_xml = source.get_xml_config()
pool_xml = "<pool>\n%s\n</pool>" % (
XMLBuilder.xml_indent(source_xml, 2))
util.xml_indent(source_xml, 2))
parseobj = StoragePool(conn, parsexml=pool_xml)
parseobj.type = pool_type

View File

@ -36,6 +36,18 @@ def listify(l):
return l
def xml_indent(xmlstr, level):
"""
Indent the passed str the specified number of spaces
"""
xml = ""
if not xmlstr:
return xml
if not level:
return xmlstr
return "\n".join((" " * level + l) for l in xmlstr.splitlines())
def vm_uuid_collision(conn, uuid):
"""
Check if passed UUID string is in use by another guest of the connection

View File

@ -511,20 +511,6 @@ class XMLBuilder(object):
# https://bugzilla.redhat.com/show_bug.cgi?id=1184131
_XML_SANITIZE = False
@staticmethod
def xml_indent(xmlstr, level):
"""
Indent the passed str the specified number of spaces
"""
xml = ""
if not xmlstr:
return xml
if not level:
return xmlstr
return "\n".join((" " * level + l) for l in xmlstr.splitlines())
def __init__(self, conn, parsexml=None,
parentxmlstate=None, relative_object_xpath=None):
"""
@ -745,7 +731,7 @@ class XMLBuilder(object):
use_xpath = obj._xmlstate.abs_xpath().rsplit("/", 1)[0]
indent = 2 * obj._xmlstate.abs_xpath().count("/")
self._xmlstate.xmlapi.node_add_xml(
self.xml_indent(xml, indent), use_xpath)
util.xml_indent(xml, indent), use_xpath)
obj._parse_with_children(None, self._xmlstate)
def remove_child(self, obj):