util: Move xml_indent to XMLBuilder

This commit is contained in:
Cole Robinson 2016-08-24 15:55:08 -04:00
parent 5dea1c2d80
commit eb2a56f700
3 changed files with 17 additions and 11 deletions

View File

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

View File

@ -36,15 +36,6 @@ def listify(l):
return l
def xml_indent(xmlstr, level):
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

@ -775,6 +775,20 @@ 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, parsexmlnode=None,
parent_xpath=None, relative_object_xpath=None):
"""
@ -1020,7 +1034,7 @@ class XMLBuilder(object):
if not obj._xmlstate.is_build:
use_xpath = obj.get_root_xpath().rsplit("/", 1)[0]
indent = 2 * obj.get_root_xpath().count("/")
newnode = libxml2.parseDoc(util.xml_indent(xml, indent)).children
newnode = libxml2.parseDoc(self.xml_indent(xml, indent)).children
parentnode = _build_xpath_node(self._xmlstate.xml_ctx, use_xpath)
# Tack newnode on the end
_add_pretty_child(parentnode, newnode)